Jcuda cuModuleLoad() cannot load file using getClass().getResource().getPath()

I am trying to use cuModuleLoad() in JCuda to load a vectorAdd.ptx file from /src/main/resources. The code is as follows:

cuModuleLoad(module, getClass.getResource(“vectorAdd.ptx”).getPath())

But the cuModuleLoad() doesn’t pick up this file. It only works when I pass in the absolute path of the ptx file. But I would like to have the ptx file shipped with compile jar files. Is there any way to accomplish this?

A short/quick response: You’ll likely have to open the file with getResourceAsStream, then read the contents of the stream into a byte[] array, and then load it using [%29"]cuModuleLoadData](http://www.jcuda.org/jcuda/doc/jcuda/driver/JCudaDriver.html#cuModuleLoadData(jcuda.driver.CUmodule,%20byte[). The cuModuleLoad is a CUDA function, and it expects a real file name - it can’t extract the PTX from the JAR. If it doesn’t work, or you encounter problems, I can test it an extend this answer later today.

A short note: The question was also asked on stackoverflow, and I added an answer there: jcuda cuModuleLoad() cannot load file using the path of getClass().getResource().getPath() - Stack Overflow