1 module dcompute.driver.ocl.program; 2 3 import dcompute.driver.ocl; 4 import std..string : toStringz; 5 6 struct Program 7 { 8 static struct Info 9 { 10 @(0x1160) uint referneceCount; 11 @(0x1161) Context context; 12 13 @(0x1162) uint _numDevices; 14 @(0x1163) Device* _devices; 15 ArrayAccesssor!(_devices,_numDevices) devices; 16 17 @(0x1164) char* _source; 18 StringzAccessor!(_source) source; 19 20 @(0x1165) size_t* _binarySizes; 21 @(0x1166) ubyte** _binaries; 22 @(0x1167) size_t _numKernels; 23 ArrayAccesssor2D!(_binaries,_binarySizes,_numKernels) binaries; 24 25 @(0x1168) char* _kernelNames; 26 StringzAccessor!(_kernelNames) kernelNames; 27 } 28 static Program globalProgram; 29 cl_program raw; 30 mixin(generateGetInfo!(Info,clGetProgramInfo)); 31 void retain() 32 { 33 status = cast(Status)clRetainProgram(raw); 34 checkErrors(); 35 } 36 37 void release() 38 { 39 status = cast(Status)clReleaseProgram(raw); 40 checkErrors(); 41 } 42 void build(Device[] devices, string options) 43 { 44 status = cast(Status)clBuildProgram(raw, 45 cast(uint)devices.length,cast(cl_device_id*)devices.ptr, 46 options.toStringz, 47 null,null); 48 checkErrors(); 49 } 50 51 Kernel!(typeof(sym)) getKernel(alias sym)() 52 { 53 Kernel!void ret = getKernel(sym.mangleof); 54 return cast(typeof(return))ret; 55 } 56 Kernel!void getKernel(string name) 57 { 58 Kernel!void ret; 59 ret.raw = clCreateKernel(this.raw,name.toStringz,cast(int*)&status); 60 checkErrors(); 61 return ret; 62 } 63 64 } 65 66 67 68 struct Build 69 { 70 Program program; 71 Device device; 72 enum BinaryType 73 { 74 none = 0x0, 75 object = 0x1, 76 library = 0x2, 77 executable = 0x4, 78 } 79 80 enum Status 81 { 82 success = 0, 83 none = -1, 84 error = -2, 85 inProgress = -3, 86 } 87 88 static struct Info 89 { 90 @(0x1181) Status status; 91 @(0x1182) char* _options; 92 StringzAccessor!(_options) options; 93 @(0x1183) char* _log; 94 StringzAccessor!(_log) log; 95 @(0x1184) BinaryType binaryType; 96 } 97 mixin(generateGetInfo!(Info,clGetProgramBuildInfo,"program.raw,device.raw")); 98 }