I was studying opencl until I see the clCreateProgramWithSource(). This function uses, as a parameter, a string which is the kernel source code to be built. But, is there any specific reason why not get a file path and read it? Any security reason?
Every time that I want to use a kernel program I need to read the kernel file, then pass its content to a buffer. So, it could be better if opencl has support to read files.
It shouldnt be that hard for you to load a file from disk on your pc. But every opencl vendor (from a like amd to z like zfx) has to write a fileload into ther opencl implementation.
If the opencl specification said that the parameter of clCreateProgramWithSource should be a file instead of string, all vendors should implement it. I think that use a file as a parameter will be better and simple than put a string…I know that it is simple to load a file and pass its string, but pass the file is
more intuitive than the first option.
This is because not everyone loads kernel sources from files.
If clCreateProgramWithSource() only took a file name it would prevent applications from programmatically creating and using kernel source strings at run-time. The only option in that case would be to create the string, write it to a temporary file, then reload the file again (quite inefficent).
In most programming languages it only takes a couple lines of code to open a file and read its contents into a string.