Skip to content

Commit 986d37b

Browse files
convert tabs to 4 spaces (#29)
1 parent 3bcbf88 commit 986d37b

File tree

10 files changed

+112
-112
lines changed

10 files changed

+112
-112
lines changed

dub.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
{
2-
"name": "dcompute",
3-
"description": "Native Heterogeneous Computing for D",
4-
"copyright": "Copyright © 2017, Nicholas Wilson",
5-
"authors": ["Nicholas Wilson"],
2+
"name": "dcompute",
3+
"description": "Native Heterogeneous Computing for D",
4+
"copyright": "Copyright © 2017, Nicholas Wilson",
5+
"authors": ["Nicholas Wilson"],
66
"license": "BSL-1.0",
7-
"dependencies": {
7+
"dependencies": {
88
"derelict-cl" : "~>2.0.0",
99
"derelict-cuda": "~>2.0.1",
1010
"taggedalgebraic": "~>0.10.7"
11-
},
11+
},
1212
"dflags" : ["-mdcompute-targets=cuda-210" ,"-oq", "-betterC"],
13-
"configurations": [
14-
{
15-
"name": "library",
16-
"targetType": "library",
17-
"excludedSourceFiles": ["./source/tests/*"],
18-
},
19-
{
20-
"name": "unittest",
21-
"targetType": "executable",
22-
"versions": ["DComputeTesting"],
13+
"configurations": [
14+
{
15+
"name": "library",
16+
"targetType": "library",
17+
"excludedSourceFiles": ["./source/tests/*"],
18+
},
19+
{
20+
"name": "unittest",
21+
"targetType": "executable",
22+
"versions": ["DComputeTesting"],
2323

24-
},
25-
]
24+
},
25+
]
2626
}

source/dcompute/driver/cuda/buffer.d

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@ struct Buffer(T)
66
{
77
size_t raw;
88

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

1212
this(size_t elems)
1313
{
1414
status = cast(Status)cuMemAlloc(&raw,elems * T.sizeof);
1515
checkErrors();
16-
hostMemory = null;
16+
hostMemory = null;
1717
}
1818

19-
this(T[] arr)
20-
{
21-
status = cast(Status)cuMemAlloc(&raw,arr.length * T.sizeof);
22-
checkErrors();
23-
hostMemory = arr;
24-
}
25-
void copy(Copy c)()
26-
{
27-
static if (c == Copy.hostToDevice)
28-
{
29-
cuMemcpyHtoD(raw, hostMemory.ptr,hostMemory.length * T.sizeof);
30-
}
31-
else static if (c == Copy.deviceToHost)
32-
{
33-
cuMemcpyDtoH(hostMemory.ptr,raw,hostMemory.length * T.sizeof);
34-
}
35-
}
36-
alias hostArgOf(U : GlobalPointer!T) = raw;
37-
void release()
38-
{
39-
cuMemFree(raw);
40-
raw = 0;
41-
hostMemory = null;
42-
}
19+
this(T[] arr)
20+
{
21+
status = cast(Status)cuMemAlloc(&raw,arr.length * T.sizeof);
22+
checkErrors();
23+
hostMemory = arr;
24+
}
25+
void copy(Copy c)()
26+
{
27+
static if (c == Copy.hostToDevice)
28+
{
29+
cuMemcpyHtoD(raw, hostMemory.ptr,hostMemory.length * T.sizeof);
30+
}
31+
else static if (c == Copy.deviceToHost)
32+
{
33+
cuMemcpyDtoH(hostMemory.ptr,raw,hostMemory.length * T.sizeof);
34+
}
35+
}
36+
alias hostArgOf(U : GlobalPointer!T) = raw;
37+
void release()
38+
{
39+
cuMemFree(raw);
40+
raw = 0;
41+
hostMemory = null;
42+
}
4343
}
4444

4545
alias bf = Buffer!float;

source/dcompute/driver/cuda/context.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ struct Context
2222
Context ret;
2323
status = cast(Status)cuCtxPopCurrent(&ret.raw);
2424
checkErrors();
25-
return ret;
25+
return ret;
2626
}
2727
static @property Context current()
2828
{
2929
Context ret;
3030
status = cast(Status)cuCtxGetCurrent(&ret.raw);
3131
checkErrors();
32-
return ret;
32+
return ret;
3333
}
3434

3535
static @property void current(Context ctx)

source/dcompute/driver/cuda/memory.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct MemoryPointer
2121
Memory ret;
2222
status = cast(Status)cuMemGetAddressRange(&ret.ptr.raw,&ret.length,raw);
2323
checkErrors();
24-
return ret;
24+
return ret;
2525
}
2626

2727
}
@@ -41,7 +41,7 @@ struct Memory
4141

4242
// cuMemcpy and friends
4343
// TODO: implement this properly
44-
/*
44+
/*
4545
template copy(T, CopySource from, CopySource to, int dimentions = 1,
4646
Flag!"peer" _peer = No.peer)
4747
{

source/dcompute/driver/cuda/platform.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Platform
2222

2323
//TODO:
2424
//Device[] ret = allocator.makeArray!(Device)(len);
25-
Device[] ret = new Device[len];
25+
Device[] ret = new Device[len];
2626
foreach(int i; 0 .. len)
2727
{
2828
status = cast(Status)cuDeviceGet(&ret[i].raw,i);

source/dcompute/driver/cuda/program.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct Program
3939
return ret;
4040
}
4141

42-
__gshared static Program globalProgram;
42+
__gshared static Program globalProgram;
4343
//cuModuleLoadDataEx
4444
//cuModuleLoadFatBinary
4545

source/dcompute/driver/cuda/queue.d

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ struct Queue
6565
uint[3] grid, block;
6666
uint sharedMem;
6767

68-
this(Queue _q,uint[3] _grid, uint[3] _block, uint _sharedMem)
69-
{
70-
q= _q;
71-
grid = _grid;
72-
block = _block;
73-
sharedMem = _sharedMem;
74-
}
68+
this(Queue _q,uint[3] _grid, uint[3] _block, uint _sharedMem)
69+
{
70+
q= _q;
71+
grid = _grid;
72+
block = _block;
73+
sharedMem = _sharedMem;
74+
}
7575
//TODO integrate evnts into this.
7676
void opCall(HostArgsOf!(typeof(k)) args)
7777
{

source/dcompute/driver/error.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ version (D_BetterC)
141141
import std.conv : to;
142142
fprintf(stderr,"*** DCompute driver error:%s\n",
143143
_status.to!(string).toStringz);
144-
};
145-
}
144+
};
145+
}
146146
}
147147
else
148148
{
@@ -162,7 +162,7 @@ else
162162
void delegate(Status) onDriverError;
163163
immutable void delegate(Status) defaultOnDriverError;
164164
static this()
165-
{
165+
{
166166
defaultOnDriverError = (Status _status)
167167
{
168168
throw new DComputeDriverException(_status);

source/dcompute/tests/dummykernels.d

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import ldc.dcompute;
66
import dcompute.std.index;
77

88
@kernel void saxpy(GlobalPointer!(float) res,
9-
float alpha,GlobalPointer!(float) x,
10-
GlobalPointer!(float) y,
11-
size_t N)
9+
float alpha,GlobalPointer!(float) x,
10+
GlobalPointer!(float) y,
11+
size_t N)
1212
{
1313
auto i = GlobalIndex.x;
14-
if (i >= N) return;
14+
if (i >= N) return;
1515
res[i] = alpha*x[i] + y[i];
1616
}
1717

source/dcompute/tests/main.d

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import std.array;
1212
import dcompute.tests.dummykernels : saxpy;
1313

1414
version(DComputeTestOpenCL)
15-
import dcompute.driver.ocl120;
15+
import dcompute.driver.ocl120;
1616
version(DComputeTestCUDA)
17-
import dcompute.driver.cuda;
17+
import dcompute.driver.cuda;
1818

1919
ubyte[] readBinaryFromDisk()
2020
{
@@ -24,55 +24,55 @@ ubyte[] readBinaryFromDisk()
2424
float[] somedata() { return [1,2,3,4,5]; }
2525
int main(string[] args)
2626
{
27-
version(DComputeTestOpenCL)
28-
{
29-
auto platform = Platform.getPlatforms(theAllocator)[0];
30-
auto devices = platform.getDevices(theAllocator);
31-
auto plist = propertyList!(Context.Properties)(Context.Properties.platform);
32-
auto ctx = Context(devices,plist);
33-
Program.globalProgram = context.createProgramFromSPIR(theAllocator,devices,readBinaryFromDisk());
34-
auto queue = context.createQueue(devices[0],Queue.Properties.outOfOrderExecution);
35-
auto data = somedata();
36-
auto buf = context.createBuffer!(float)(Memory.Flags.none,data);
37-
Event e = queue.enqueue!(saxpy)([5])(buf,buf,42.0);
38-
e.wait();
39-
}
40-
version(DComputeTestCUDA)
41-
{
42-
Platform.initialise();
43-
44-
auto devs = Platform.getDevices(theAllocator);
45-
auto dev = devs[0];
46-
auto ctx = Context(dev); scope(exit) ctx.detach();
27+
version(DComputeTestOpenCL)
28+
{
29+
auto platform = Platform.getPlatforms(theAllocator)[0];
30+
auto devices = platform.getDevices(theAllocator);
31+
auto plist = propertyList!(Context.Properties)(Context.Properties.platform);
32+
auto ctx = Context(devices,plist);
33+
Program.globalProgram = context.createProgramFromSPIR(theAllocator,devices,readBinaryFromDisk());
34+
auto queue = context.createQueue(devices[0],Queue.Properties.outOfOrderExecution);
35+
auto data = somedata();
36+
auto buf = context.createBuffer!(float)(Memory.Flags.none,data);
37+
Event e = queue.enqueue!(saxpy)([5])(buf,buf,42.0);
38+
e.wait();
39+
}
40+
version(DComputeTestCUDA)
41+
{
42+
Platform.initialise();
43+
44+
auto devs = Platform.getDevices(theAllocator);
45+
auto dev = devs[0];
46+
auto ctx = Context(dev); scope(exit) ctx.detach();
4747

48-
// Change the file to match your GPU.
49-
Program.globalProgram = Program.fromFile("./.dub/obj/kernels_cuda210_64.ptx");
50-
auto q = Queue(false);
48+
// Change the file to match your GPU.
49+
Program.globalProgram = Program.fromFile("./.dub/obj/kernels_cuda210_64.ptx");
50+
auto q = Queue(false);
5151

52-
enum size_t N = 128;
53-
float alpha = 5.0;
54-
float[N] res, x,y;
55-
foreach (i; 0 .. N)
56-
{
57-
x[i] = N - i;
58-
y[i] = i * i;
59-
}
60-
Buffer!(float) b_res, b_x, b_y;
61-
b_res = Buffer!(float)(res[]); scope(exit) b_res.release();
62-
b_x = Buffer!(float)(x[]); scope(exit) b_x.release();
63-
b_y = Buffer!(float)(y[]); scope(exit) b_y.release();
52+
enum size_t N = 128;
53+
float alpha = 5.0;
54+
float[N] res, x,y;
55+
foreach (i; 0 .. N)
56+
{
57+
x[i] = N - i;
58+
y[i] = i * i;
59+
}
60+
Buffer!(float) b_res, b_x, b_y;
61+
b_res = Buffer!(float)(res[]); scope(exit) b_res.release();
62+
b_x = Buffer!(float)(x[]); scope(exit) b_x.release();
63+
b_y = Buffer!(float)(y[]); scope(exit) b_y.release();
6464

65-
b_x.copy!(Copy.hostToDevice);
66-
b_y.copy!(Copy.hostToDevice);
65+
b_x.copy!(Copy.hostToDevice);
66+
b_y.copy!(Copy.hostToDevice);
6767

68-
q.enqueue!(saxpy)
69-
([N,1,1],[1,1,1])
70-
(b_res,alpha,b_x,b_y, N);
71-
b_res.copy!(Copy.deviceToHost);
72-
foreach(i; 0 .. N)
73-
enforce(res[i] == alpha * x[i] + y[i]);
74-
writeln(res[]);
75-
}
68+
q.enqueue!(saxpy)
69+
([N,1,1],[1,1,1])
70+
(b_res,alpha,b_x,b_y, N);
71+
b_res.copy!(Copy.deviceToHost);
72+
foreach(i; 0 .. N)
73+
enforce(res[i] == alpha * x[i] + y[i]);
74+
writeln(res[]);
75+
}
7676

7777
return 0;
7878
}

0 commit comments

Comments
 (0)