Yash
Yash

Reputation: 699

Can the compiled opencl program be stored as a seperate binary file?

I have 2 two python script on separate files. The first one has opencl program that performs some image processing on the image passed to it and returns the results. The second script reads the image on from a file and calls the first script passing the read image as a parameter and obtains the results returned by it which is used for further processing.

Now, I have like a 100 images in the folder. So the second scripts calls the first script 100 times and each time the first script is called, the opencl kernel is compiled which is absolutely unnecessary as all the images are of same format and dimension. Is there a way to first compile the opencl kernel once, store it in a binary format and call it whenever required? Of-course, i can put all the code in one large file, compile the kernel once and call it in a loop for 100 times but I want separate files for the purpose of convenience.

Hardware:

CPU: AMD A8 APU, AMD Phenom 2 X4

GPU: AMD Radeon HD 7640G + 7670M Dual Graphics, ATI Radeon HD5770

Upvotes: 2

Views: 1250

Answers (2)

Chanakya.sun
Chanakya.sun

Reputation: 587

on NVIDIA the binary will be in the ptx format. obtain the Binary sizes clGetProgramInfo() using the flag CL_PROGRAM_BINARY_SIZES

store the binaries in ptx file. clGetProgramInfo() using the flag CL_PROGRAM_BINARIES

clCreateProgramWithBinary() with the ptx file as input.

Upvotes: 1

matthias
matthias

Reputation: 2181

Yes, you can get the compiled "binary" of a program via clGetProgramInfo() and store it. You would then load the program with clCreateProgramWithBinary() instead of clCreateProgramWithSource().

But then you are using PyOpenCL which automatically caches program binaries.

Upvotes: 2

Related Questions