Skip to content

Commit 28e7aac

Browse files
committed
Use TS for tests
1 parent 0921e84 commit 28e7aac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1073
-1976
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ npm i -s opencl-raub
1313

1414
> This addon is ABI-compatible across Node.js versions. **There is no compilation** during `npm i`.
1515
16-
**Node.js** addon with **OpenCL** bindings. This is not WebCL.
16+
**Node.js** addon with **OpenCL 1.2** bindings. This is not WebCL.
1717

1818
The API directly reflects the low-level **OpenCL** interface. There are minor changes
1919
similar to how WebGL is different from OpenGL.
@@ -33,7 +33,7 @@ See [TypeScript declarations](/index.d.ts) for more details.
3333

3434
1. Import the module:
3535
```ts
36-
const cl = require('opencl-raub');
36+
import cl from 'opencl-raub';
3737
```
3838
2. Fetch the CL control objects:
3939
```ts
@@ -109,7 +109,6 @@ See [TypeScript declarations](/index.d.ts) for more details.
109109
cl.releaseMemObject(bufferA);
110110
cl.releaseMemObject(bufferB);
111111
cl.releaseMemObject(bufferC);
112-
cl.releaseContext(context);
113112
```
114113

115114

examples/package-lock.json

Lines changed: 0 additions & 84 deletions
This file was deleted.

examples/package.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"saxpy": "node --experimental-strip-types saxpy.ts",
8-
"simple": "node --experimental-strip-types simple.ts",
9-
"square": "node --experimental-strip-types square.ts",
10-
"square-events": "node --experimental-strip-types square-events.ts",
11-
"vector-add": "node --experimental-strip-types vector-add.ts",
12-
"vector-add-mapped": "node --experimental-strip-types vector-add-mapped.ts"
13-
},
14-
"dependencies": {
15-
"opencl-raub": "file:..",
16-
"tsconfig-paths": "^4.2.0"
7+
"saxpy": "node --no-warnings=ExperimentalWarning --experimental-strip-types saxpy.ts",
8+
"simple": "node --no-warnings=ExperimentalWarning --experimental-strip-types simple.ts",
9+
"square": "node --no-warnings=ExperimentalWarning --experimental-strip-types square.ts",
10+
"square-events": "node --no-warnings=ExperimentalWarning --experimental-strip-types square-events.ts",
11+
"vector-add": "node --no-warnings=ExperimentalWarning --experimental-strip-types vector-add.ts",
12+
"vector-add-mapped": "node --no-warnings=ExperimentalWarning --experimental-strip-types vector-add-mapped.ts"
1713
}
1814
}

examples/saxpy.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import cl from 'opencl-raub';
2-
1+
import cl from '../index.js';
32

43
const getEventExecTime = (event: cl.TClEvent): number => {
54
// times are 64-bit values in nanoseconds. They are returned as [hi, lo] a 2-integer array
@@ -87,7 +86,7 @@ const readEvent = cl.enqueueReadBuffer(
8786
) as cl.TClEvent;
8887

8988
cl.waitForEvents([readEvent]);
90-
// cl.finish(queue);
89+
9190
console.log(
9291
`C[${VECTOR_SIZE - 1}] =`,
9392
C[VECTOR_SIZE - 1],

examples/simple.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cl from 'opencl-raub';
1+
import cl from '../index.js';
22

33
const { context, device } = cl.quickStart(true);
44
const queue = cl.createCommandQueue(context, device, null);
@@ -61,4 +61,3 @@ cl.releaseProgram(program);
6161
cl.releaseMemObject(bufferA);
6262
cl.releaseMemObject(bufferB);
6363
cl.releaseMemObject(bufferC);
64-
cl.releaseContext(context);

examples/square-events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'node:fs';
2-
import cl from 'opencl-raub';
2+
import cl from '../index.js';
33

44
const { context, device } = cl.quickStart(true);
55

examples/square.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'node:fs';
2-
import cl from 'opencl-raub';
2+
import cl from '../index.js';
33

44
const { context, device } = cl.quickStart(true);
55
const cq = cl.createCommandQueue(context, device);
@@ -9,41 +9,44 @@ const source = fs.readFileSync('square.cl').toString();
99
const NVALUES = 100;
1010
const BYTES_PER_ELEMENT = Uint32Array.BYTES_PER_ELEMENT;
1111

12-
const inputs2 = new Uint32Array(NVALUES);
13-
const outputs2 = new Uint32Array(NVALUES);
12+
const inputs = new Uint32Array(NVALUES);
13+
const outputs = new Uint32Array(NVALUES);
1414

1515
for (let i = 0; i < NVALUES; ++i) {
16-
inputs2[i] = i;
16+
inputs[i] = i;
1717
}
18-
outputs2.fill(0);
18+
outputs.fill(0);
1919

2020
const prog2 = cl.createProgramWithSource(context, source);
2121
cl.buildProgram(prog2);
2222
const kern2 = cl.createKernel(prog2, 'square');
2323

24-
const inputsMem2 = cl.createBuffer(
24+
const inputsMem = cl.createBuffer(
2525
context,
2626
cl.MEM_READ_ONLY | cl.MEM_COPY_HOST_PTR, NVALUES * BYTES_PER_ELEMENT,
27-
inputs2
27+
inputs
2828
);
29-
const outputsMem2 = cl.createBuffer(
29+
const outputsMem = cl.createBuffer(
3030
context,
3131
cl.MEM_WRITE_ONLY | cl.MEM_COPY_HOST_PTR, NVALUES * BYTES_PER_ELEMENT,
32-
outputs2
32+
outputs
3333
);
3434

35-
cl.setKernelArg(kern2, 0, 'uint*', inputsMem2);
36-
cl.setKernelArg(kern2, 1, 'uint*', outputsMem2);
35+
cl.setKernelArg(kern2, 0, 'uint*', inputsMem);
36+
cl.setKernelArg(kern2, 1, 'uint*', outputsMem);
3737
cl.setKernelArg(kern2, 2, 'uint', NVALUES);
3838

3939
cl.enqueueNDRangeKernel(cq, kern2, 1, null, [NVALUES], null);
40-
cl.enqueueReadBuffer(cq, outputsMem2, true, 0, NVALUES * BYTES_PER_ELEMENT, outputs2);
40+
cl.enqueueReadBuffer(cq, outputsMem, true, 0, NVALUES * BYTES_PER_ELEMENT, outputs);
4141
cl.finish(cq);
4242

4343
// contains i^2 for i=0,..., 10000-1
44-
const lastValue2 = outputs2[NVALUES - 1];
44+
const lastValue = outputs[NVALUES - 1];
4545
const correctValue = (NVALUES - 1) * (NVALUES - 1);
46-
console.log('Last value is:', lastValue2);
47-
console.log('Correct value is:', correctValue);
46+
console.log(
47+
'Last value is:',
48+
lastValue,
49+
lastValue === correctValue ? '(correct!)' : `(must be ${correctValue})`,
50+
);
4851

4952
console.log('DONE');

examples/vector-add-mapped.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cl from 'opencl-raub';
1+
import cl from '../index.js';
22

33
const { context, device } = cl.quickStart(true);
44

@@ -97,7 +97,4 @@ console.log(`A = [${A.join(', ')}]`);
9797
console.log(`B = [${B.join(', ')}]`);
9898
console.log(`C = [${C.join(', ')}]`);
9999

100-
// cleanup
101-
// cl.releaseAll();
102-
103100
console.log('DONE');

examples/vector-add.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cl from 'opencl-raub';
1+
import cl from '../index.js';
22

33
const { context, device } = cl.quickStart(true);
44

@@ -78,6 +78,5 @@ cl.releaseProgram(program);
7878
cl.releaseMemObject(aBuffer);
7979
cl.releaseMemObject(bBuffer);
8080
cl.releaseMemObject(cBuffer);
81-
cl.releaseContext(context);
8281

8382
console.log('DONE');

0 commit comments

Comments
 (0)