According to the documentation of CUDAFunctionLoad it should be easy to specify a compiled file (cubin, ptx, dll should all work) as the source for loading a CUDAFunction. Unfortunately it does not for me. Compiling from source works fine, but as soon as I try to load the CUDAFunction from the compiled file (I tried cubin, ptx and a dll) things fail.
Here is a very simple example that does not work for me, no matter what combination I try (you can just copy and paste the code into mathematica and run it as long as you have a proper CUDA setup):
Let's create a cubin file first from a very simple CUDA kernel:
Needs["CUDALink`"];
code = "
__global__ void addTwo(int * in, int * out, int length) {
int index = threadIdx.x + blockIdx.x*blockDim.x;
if (index < length)
out[index] = in[index] + 2;
}";
cubinFile = CreateExecutable[code, "test", "Compiler" -> NVCCCompiler,
"CreateCUBIN" -> True];
This successfully creates test.cubin.
Unfortunately loading the function addTwo fails:
cudaFun = CUDAFunctionLoad[File[cubinFile],
"addTwo", {{"Integer32", _, "Input"}, {"Integer32", _,
"Output"}, "Integer32"}, 256, "ShellCommandFunction" :> Print,
"ShellOutputFunction" -> Print];
CUDAFunctionLoad::invsrc: CUDALink encountered invalid source input. The source input must be either a string containing the program, or a list of one element indicating the file containing the program.
The input file should be valid, but maybe I am missing something obvious here. Interestingly enough going the same route creating a .ptx file yields a different error:
ptxFile =
CreateExecutable[code, "test", "Compiler" -> NVCCCompiler,
"CreatePTX" -> True];
cudaFun =
CUDAFunctionLoad[File[ptxFile],
"addTwo", {{"Integer32", _, "Input"}, {"Integer32", _,
"Output"}, "Integer32"}, 256, "ShellCommandFunction" :> Print,
"ShellOutputFunction" -> Print];
CUDAFunctionLoad::notfnd: CUDALink resource not found.
Any ideas on what is going wrong here and how I can actually load a CUDAFunction from a compiled file?
You can just copy and paste the code above into mathematica and run it as long as you have CUDA setup properly. Can you reproduce the behavior?
Additional Information:
I am running Mathematica 11.2 on Windows 10.
Latest CUDA Paclet installed. CUDA setup working fine (can load CUDAFunctions from source, compile files, etc.).
{})? The first error message ask for a list containing a single element, namely the filename. Admittedly, that's rather unconventional in Mathematica but this can shield a string containing the filename from interpretation as a code string... – Henrik Schumacher Feb 15 '18 at 23:55Throw[$Failed]which is then caught by the part that creates the misleading error. The real error in the first case can be examined by evaluating theCUDAFunctionLoadline, then calling<<LibraryLink`, and then evaluating$LibraryError. For me this gives ".../libCUDALink_Double.so: undefined symbol: WolframCompileLibrary_wrapper". I spend a good 2 h debugging the CUDALink package and when I hear back from support@wri, I give a more detailed answer. – halirutan Feb 25 '18 at 01:32