0

In renderscript kernels has to be defined in separate .rs files as follows:

float __attribute__((kernel)) foo_1(uint32_t x) {
}

float __attribute__((kernel)) foo_2(uint32_t x) {
}

Then it has to be used in the main java file as follows:

ScriptC_fileName tmp = new ScriptC_fileName(rs);

I was wondering which of the following is the best programming practice for performance and why.

  1. Defining all kernels in the same .rs file.
  2. Using separate .rs files for different kernels.
mmotamedi144
  • 115
  • 1
  • 10

1 Answers1

2

It's really a matter of preference and architecture. Separation of concerns: if the RS functionality is not related then you likely don't want to keep it all in one .rs file.

When you create the ScriptC instance it is creating the Java side object as well as loading the native / platform specific code for the component. So if you have everything in a single .rs file you could be loading content which is not used/required at that time. So larger memory consumption and possible native/platform resource consumption.

Processing performance it (generally) should have no major impact, other than the larger resource usage I already described. Of course, that will be hardware and implementation dependent. If the hardware specifics take a processing performance impact because of more low level code being loaded (on a DSP or GPU) then that is a platform specific issue.

Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • That's interesting. I use in my app one rs instance and several (10) ScriptC instances. All of them are created in the onCreate method of mainActivity and are later used more or less sequentially. That clearly has some benefits, since creation of these objects (particularly the rs itself) is time consuming. Now, since I have added more and more kernels, I noted that on some lower-resource devices (as e.g. LG Fino) this starts to create (memory) problems. Thus, while I will keep one rs instance, I will create some of the ScriptC instances on an as-needed basis and then destroy them again. – Settembrini Jul 15 '16 at 08:06