Skip to content

Commit 33f26f9

Browse files
committed
TypeScript support, initial commit
1 parent 39c4486 commit 33f26f9

Some content is hidden

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

47 files changed

+4371
-1532
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
CMakeLists.txt
22
node_modules
33
build
4+
dist
45
.idea/
56
docker/amd-app-sdk.tar.bz2
67
docker/nodejs-0.10/amd-app-sdk.tar.bz2
78
*~
89
*.swp
9-
!.vscode/launch.json
10+
.idea
1011
.vscode
12+
!.vscode/launch.json

.npmignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.idea
2+
.vscode
3+
build
4+
dist
5+
docker
6+
node_modules

.vscode/launch.json

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,32 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"type": "lldb",
9+
"request": "launch",
10+
"name": "Debug C++ (Wait for JavaScript)",
11+
"program": "node",
12+
"args": [
13+
// Allow current instance to use up to 10 gigs of RAM, because why not? :)
14+
"--max_old_space_size=10240",
15+
"--inspect-brk=7777",
16+
"--require",
17+
"ts-node/register",
18+
"${file}"
19+
],
20+
"cwd": "${workspaceFolder}"
21+
},
722
{
823
"type": "lldb",
924
"request": "launch",
1025
"name": "Debug C++",
11-
"program": "/home/ptaylor/.nvm/versions/node/v12.0.0/bin/node",
12-
"preLaunchTask": "npm: build:dev",
26+
"program": "node",
1327
"args": [
14-
"/home/ptaylor/dev/node-opencl/node_modules/mocha/bin/_mocha"
28+
// Allow current instance to use up to 10 gigs of RAM, because why not? :)
29+
"--max_old_space_size=10240",
30+
"--require",
31+
"ts-node/register",
32+
"${file}"
1533
],
1634
"cwd": "${workspaceFolder}"
1735
},

README.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
# Node OpenCL (TypeScript)
2+
3+
This is a fork of mikeseven's node-opencl project from:
4+
https://github.com/mikeseven/node-opencl (by https://github.com/mikeseven)
5+
6+
I've taken the initiative to renovate the existing code for my own purposes and now I'm sharing the result in hope that it will be useful for anyone else who is lacking typescript support with `node-opencl`.
7+
8+
This project contains full typings coverage of OpenCL 1.0-2.0 (and OpenCL 2.1, 2.2 ready to be implemented) specification (based on Khronos specification) with node-opencl specifics taken into account. The package also contains couple of minor bugfixes suggested by community PRs in original repo and couple of mine aesthetic interface changes / additions and changes related to management of deprecated OpenCL apis (basically I enabled the use of deprecated APIs if they were still supported by OpenCL implementation). Which I think may block mikeseven from merging current changes into `node-opencl`. Nevertheless in order to not partition the community with redundant library versions I'm open to kill this repo in event of merge with `node-opencl`.
9+
10+
One more thing, the typings are handcrafted, I've attempted to make the typings as verbose and type-safe as possible, this means that there is still room for improvement for both typings and the OpenCL bindings implementation itself (I'm open for both issues and PRs).
11+
12+
Currently there are just couple of v1.0-v2.0 functions that are not implemented (most of them are deprecated in OpenCL 1.2 - 2.0 or not needed at all due to the way `node-opencl` was implemented). OpenCL v2.1 and v2.2 are not implemented at all so again issues and PRs are welcome.
13+
14+
And the last thing I wanted to mention. Due to hardware nature of OpenCL segfaults, BSODs, freezes and computer restarts are a normal thing in OpenCL world. So in order to compensate the risk I've implemented extra measures for type-safety. Basically I've used nominal types everywhere where possible (search for type discrimination). I.e. types which basically allow to distinguish two similar atomic (or non-atomic) type, example:
15+
16+
```typescript
17+
export type Kilos<T> = T & { readonly discriminator: unique symbol };
18+
export type Pounds<T> = T & { readonly discriminator: unique symbol };
19+
20+
export interface MetricWeight {
21+
value: Kilos<number>
22+
}
23+
24+
export interface ImperialWeight {
25+
value: Pounds<number>
26+
}
27+
28+
const wm: MetricWeight = { value: 0 as Kilos<number> }
29+
const wi: ImperialWeight = { value: 0 as Pounds<number> }
30+
31+
wm.value = wi.value; // Gives compiler error
32+
wi.value = wi.value * 2; // Gives compiler error
33+
wm.value = wi.value * 2; // Gives compiler error
34+
const we: MetricWeight = { value: 0 } // Gives compiler error
35+
```
36+
37+
It improves the TypeSafety keeps notion of original type but comes with additional strain of casting `as Kilos<number>` here and there, though it shouldn't be a problem due to risk compensation (I guess).
38+
39+
--------------------
40+
141
# Node OpenCL
242

343
[![Build Status](http://pub-ci.ioweb.fr/api/badge/github.com/ioweb-fr/node-opencl/status.svg?branch=master)](http://pub-ci.ioweb.fr/github.com/ioweb-fr/node-opencl)
@@ -85,9 +125,7 @@ those behaviours so you can run them to check if it is a known issue.
85125

86126
## Int 64
87127

88-
Javascript does not support 64 bits integers. OpenCL returns some int64, mainly in getInfo functions. To resolve this, we return 64-bit values as an array of 2 32-bit integers [hi, lo] such that
89-
90-
value = (hi << 32) | lo
128+
Javascript does not support 64 bits integers however OpenCL returns Int64 values for mem-size related functions like `getDeviceInfo`, `getKernelWorkGroupInfo` and time-related function `getEventProfilingInfo`. In order to deal with the limitation for `getDeviceInfo`, `getKernelWorkGroupInfo` would return the amounts in kilobytes. For `getEventProfilingInfo` we return an array of two 32 bit integers that form the resulting Int64 value, if necessary the resulting value can be gathered together using formula `value = (hi << 32) | lo` however in absolute majority of cases only lower 32 bits of 64 bit integer are required.
91129

92130
## Differences between Node-OpenCL and WebCL
93131

examples/saxpy.js

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

examples/square.js

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

0 commit comments

Comments
 (0)