Skip to content

Commit cf7d6aa

Browse files
OpenCL testing (#36)
1 parent 09401a8 commit cf7d6aa

File tree

25 files changed

+334
-230
lines changed

25 files changed

+334
-230
lines changed

source/dcompute/driver/cuda/buffer.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct Buffer(T)
66
{
77
size_t raw;
88

9-
// Host memory associated with this buffer
9+
// Host memory associated with this buffer
1010
T[] hostMemory;
1111

1212
this(size_t elems)

source/dcompute/driver/error.d

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ enum Status : int {
8080
invalidSampler = -41,
8181
invalidBinary = -42,
8282
invalidBuildOptions = -43,
83-
invalinProgram = -44,
83+
invalidProgram = -44,
8484
invalidExecutable = -45,
8585
invalidKernelName = -46,
8686
invalidKernelDefinition = -47,
@@ -129,6 +129,7 @@ enum Status : int {
129129
EGLResourceNotAcquired = -1092,
130130
}
131131

132+
//@BUG@ The static this does not appear to work!
132133
version (D_BetterC)
133134
{
134135
void delegate (Status) nothrow @nogc onDriverError;
@@ -169,7 +170,9 @@ else
169170
};
170171
}
171172
}
172-
static this() { onDriverError = (Status _status) { defaultOnDriverError(_status);};}
173+
static this() {
174+
onDriverError = (Status _status) { defaultOnDriverError(_status);};
175+
}
173176
// Thread local status
174177
Status status;
175178

source/dcompute/driver/ocl/buffer.d

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module dcompute.driver.ocl.buffer;
2+
3+
import dcompute.driver.ocl;
4+
5+
struct Buffer(T)
6+
{
7+
cl_mem raw;
8+
9+
// Host memory associated with this buffer
10+
T[] hostMemory;
11+
enum CreateType
12+
{
13+
region =0x1220,
14+
}
15+
// opSlice clCreateSubBuffer
16+
}

source/dcompute/driver/ocl120/context.d renamed to source/dcompute/driver/ocl/context.d

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module dcompute.driver.ocl120.context;
1+
module dcompute.driver.ocl.context;
22

3-
import dcompute.driver.ocl120;
3+
import dcompute.driver.ocl;
44
import std.typecons;
55

66
import std.experimental.allocator.typed;
@@ -19,10 +19,9 @@ struct Context
1919
{
2020
@(0x1080) uint referenceCount;
2121
@(0x1081) Device* _devices;
22-
@(0x1082) Properties* _properties;
23-
ZeroTerminatedArrayAccessor!_properties properties;
24-
@(0x1083) uint _numDevices;
25-
ArrayAccesssor!(_devices,_numDevices) devices;
22+
@(0x1082) Context.Properties* properties;
23+
@(0x1083) uint numDevices;
24+
ArrayAccesssor!(_devices,numDevices) devices;
2625
// Extensions
2726
//@(0x2010) khrTerminate;
2827
//@(0x200E) khrMemoryInitialise;
@@ -40,8 +39,7 @@ struct Context
4039
//@(0x200C) CGL_SHAREGROUP_KHR
4140

4241
}
43-
44-
mixin generateGetInfo!clGetContextInfo;
42+
//mixin(generateGetInfo!(Info,clGetContextInfo));
4543

4644
this(Device[] devs,const Properties[] props)
4745
{
@@ -83,11 +81,13 @@ struct Context
8381
return ret;
8482
}
8583

86-
Buffer!T createBuffer(T)(Memory.Flags flags,T[] arr)
84+
Buffer!T createBuffer(T)(T[] arr,Memory.Flags flags = (Memory.Flags.useHostPointer | Memory.Flags.readWrite))
8785
{
86+
import std.stdio;
8887
Buffer!T ret;
8988
auto len = memSize(arr);
9089
ret.raw = clCreateBuffer(raw,flags,len,arr.ptr,cast(int*)&status);
90+
ret.hostMemory = arr;
9191
checkErrors();
9292
return ret;
9393
}
@@ -137,6 +137,16 @@ struct Context
137137
allocator.dispose(ptrs);
138138
return ret;
139139
}
140+
Program createProgram(void[] spirv)
141+
{
142+
Program ret;
143+
144+
ret.raw = clCreateProgramWithIL(this.raw,
145+
spirv.ptr,
146+
spirv.length,
147+
cast(int*)&status);
148+
return ret;
149+
}
140150

141151
/*Program createProgramFromBuiltinKernels(Device[] devices, string kernelNames)
142152
{

source/dcompute/driver/ocl120/device.d renamed to source/dcompute/driver/ocl/device.d

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module dcompute.driver.ocl120.device;
1+
module dcompute.driver.ocl.device;
22

33
import derelict.opencl.cl;
4-
import dcompute.driver.ocl120;
4+
import dcompute.driver.ocl;
55

66
struct Device
77
{
@@ -145,11 +145,11 @@ struct Device
145145
@(0x1041) size_t imageMaxArraySize;
146146
@(0x1042) Device parentDevice;
147147
@(0x1043) uint partitionMaxSubDevices;
148-
@(0x1044) PartitionProperty* _partitionProperties;
149-
ZeroTerminatedArrayAccessor!(_partitionProperties) partitionProperties;
148+
//@(0x1044) PartitionProperty* _partitionProperties;
149+
//ZeroTerminatedArrayAccessor!(_partitionProperties) partitionProperties;
150150
@(0x1045) AffinityDomain partitionAffinityDomain;
151-
@(0x1046) PartitionProperty* _partitionType;
152-
ZeroTerminatedArrayAccessor!(_partitionType) partitionType;
151+
//@(0x1046) PartitionProperty* _partitionType;
152+
//ZeroTerminatedArrayAccessor!(_partitionType) partitionType;
153153
@(0x1047) uint peferenceCount;
154154
@(0x1048) bool prefferedInteropUserSync;
155155
@(0x1049) size_t printfBufferSize;
@@ -168,8 +168,8 @@ struct Device
168168
}
169169

170170
cl_device_id raw;
171-
/*getInfo*/
172-
mixin generateGetInfo!clGetDeviceInfo;
171+
172+
mixin(generateGetInfo!(Info,clGetDeviceInfo));
173173

174174
//Is this a double call function? Also what to do about properties
175175
//its zero terminated an can contain numbers

source/dcompute/driver/ocl120/event.d renamed to source/dcompute/driver/ocl/event.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module dcompute.driver.ocl120.event;
1+
module dcompute.driver.ocl.event;
22

3-
import dcompute.driver.ocl120;
3+
import dcompute.driver.ocl;
44

55
struct Event
66
{
@@ -63,7 +63,7 @@ struct Event
6363
@(0x11D3) EcexutionStatus status;
6464
@(0x11D4) Context context;
6565
}
66-
mixin generateGetInfo!(clGetEventInfo);
66+
//mixin(generateGetInfo!(Info,clGetEventInfo));
6767

6868
void retain()
6969
{

source/dcompute/driver/ocl120/image.d renamed to source/dcompute/driver/ocl/image.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module dcompute.driver.ocl120.image;
1+
module dcompute.driver.ocl.image;
22

3-
import dcompute.driver.ocl120;
3+
import dcompute.driver.ocl;
44
struct Image
55
{
66
cl_mem raw;
@@ -67,5 +67,5 @@ struct Image
6767
//@(0x401F) D3D11_SUBRESOURCE_KHR
6868
//@(0x202A) DX9_MEDIA_PLANE_KHR
6969
}
70-
mixin generateGetInfo!(clGetImageInfo);
70+
//mixin(generateGetInfo!(Info,clGetImageInfo));
7171
}

source/dcompute/driver/ocl120/kernel.d renamed to source/dcompute/driver/ocl/kernel.d

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
module dcompute.driver.ocl120.kernel;
1+
module dcompute.driver.ocl.kernel;
22

3-
import dcompute.driver.ocl120;
3+
import dcompute.driver.ocl;
44

55
struct Kernel(F) if (is(F == function) || is(F==void))
66
{
77
cl_kernel raw;
88

99
static struct Info
1010
{
11-
@(0x1190) char* _name;
11+
@(0x1190) immutable char* _name;
1212
StringzAccessor!(_name) name;
1313
@(0x1191) uint numArgs;
1414
@(0x1192) uint referenceCount;
1515
@(0x1193) Context context;
1616
@(0x1194) Program program;
17-
@(0x1195) char* _attributes;
17+
@(0x1195) immutable char* _attributes;
1818
StringzAccessor!(_attributes) attributes;
1919
}
20-
mixin generateGetInfo!(clGetKernelInfo);
20+
//mixin(generateGetInfo!(Info,clGetKernelInfo));
2121
void retain()
2222
{
2323
status = cast(Status)clRetainKernel(raw);
@@ -69,14 +69,14 @@ struct Arg
6969
{
7070
@(0x1196) AddressQualifier addressQualifier;
7171
@(0x1197) AccessQualifier accessQualifier;
72-
@(0x1198) char* _typeName;
72+
@(0x1198) immutable char* _typeName;
7373
StringzAccessor!(_typeName) typeName;
7474
@(0x1199) TypeQualifier typeQualifier;
75-
@(0x119A) char* _name;
75+
@(0x119A) immutable char* _name;
7676
StringzAccessor!(_name) name;
7777
}
7878

79-
mixin generateGetInfo!(clGetKernelArgInfo);
79+
//mixin(generateGetInfo!(Info,clGetKernelArgInfo,"kernel.raw,argIndex"));
8080
}
8181

8282
struct WorkGroup
@@ -93,5 +93,5 @@ struct WorkGroup
9393
@(0x11B5) size_t[3] globalWorkSize;
9494
}
9595

96-
mixin generateGetInfo!(clGetKernelWorkGroupInfo);
96+
//mixin(generateGetInfo!(Info,clGetKernelWorkGroupInfo,"kernel.raw,device.raw"));
9797
}

source/dcompute/driver/ocl120/memory.d renamed to source/dcompute/driver/ocl/memory.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module dcompute.driver.ocl120.memory;
1+
module dcompute.driver.ocl.memory;
22

3-
import dcompute.driver.ocl120;
3+
import dcompute.driver.ocl;
44

55
struct Memory
66
{
@@ -50,7 +50,7 @@ struct Memory
5050
}
5151
cl_mem raw;
5252

53-
mixin generateGetInfo!(clGetMemObjectInfo);
53+
//mixin(generateGetInfo!(Info,clGetMemObjectInfo));
5454
void retain()
5555
{
5656
status = cast(Status)clRetainMemObject(raw);

source/dcompute/driver/ocl/package.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module dcompute.driver.ocl;
2+
3+
public import dcompute.driver.error;
4+
5+
public import dcompute.driver.ocl.buffer;
6+
public import dcompute.driver.ocl.context;
7+
public import dcompute.driver.ocl.device;
8+
public import dcompute.driver.ocl.event;
9+
public import dcompute.driver.ocl.image;
10+
public import dcompute.driver.ocl.kernel;
11+
public import dcompute.driver.ocl.memory;
12+
public import dcompute.driver.ocl.platform;
13+
public import dcompute.driver.ocl.program;
14+
public import dcompute.driver.ocl.queue;
15+
public import dcompute.driver.ocl.raw;
16+
public import dcompute.driver.ocl.sampler;
17+
public import dcompute.driver.ocl.util;

0 commit comments

Comments
 (0)