1 module dcompute.driver.cuda.program;
2 
3 import dcompute.driver.cuda;
4 
5 import std..string;
6 struct Program
7 {
8     void* raw;
9     
10     Kernel!void getKernelByName(immutable(char)* name)
11     {
12         Kernel!void ret;
13         status = cast(Status)cuModuleGetFunction(&ret.raw,this.raw,name);
14         checkErrors();
15         return ret;
16     }
17     Kernel!(typeof(k)) getKernel(alias k)()
18     {
19         return cast(typeof(return)) getKernelByName(k.mangleof.ptr);
20     }
21     // TODO: Support globals & images. Requires competent compiler. 
22     //cuModuleGetGlobal
23     //cuModuleGetTexRef
24     //cuModuleGetSurfRef
25     
26     static Program fromFile(string name)
27     {
28         Program ret;
29         status = cast(Status)cuModuleLoad(&ret.raw,name.toStringz);
30         checkErrors();
31         return ret;
32     }
33 
34     static Program fromString(string name)
35     {
36         Program ret;
37         status = cast(Status)cuModuleLoadData(&ret.raw,name.toStringz);
38         checkErrors();
39         return ret;
40     }
41     
42     __gshared static Program globalProgram;
43     //cuModuleLoadDataEx
44     //cuModuleLoadFatBinary
45     
46     void unload()
47     {
48         status = cast(Status)cuModuleUnload(raw);
49         checkErrors();
50     }
51     
52     //TODO: linkstate
53 }
54 
55 
56