-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript support #70
base: master
Are you sure you want to change the base?
Changes from all commits
54712c7
89f006d
3f9d6c0
7d2de1f
9bdbdda
ed2ccbd
69507c0
0393dde
efda566
6413147
f1fbff9
aeea819
964da8b
209cb50
50c2981
c36300c
4fcad23
6adb7ec
5f391a8
515d27b
3e54df5
f2c7c41
8a825a2
6a5f1d4
64afb34
938ba1f
9062771
e33ed63
d73b663
8070411
c64da8d
87c4e63
f029a1c
39c4486
33f26f9
140c2cc
9dc971e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
CMakeLists.txt | ||
node_modules | ||
build | ||
dist | ||
.idea/ | ||
docker/amd-app-sdk.tar.bz2 | ||
docker/nodejs-0.10/amd-app-sdk.tar.bz2 | ||
*~ | ||
*.swp | ||
.idea | ||
.vscode | ||
!.vscode/launch.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea | ||
.vscode | ||
build | ||
dist | ||
docker | ||
node_modules |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug C++ (Wait for JavaScript)", | ||
"program": "node", | ||
"args": [ | ||
// Allow current instance to use up to 10 gigs of RAM, because why not? :) | ||
"--max_old_space_size=10240", | ||
"--inspect-brk=7777", | ||
"--require", | ||
"ts-node/register", | ||
"${file}" | ||
], | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
{ | ||
"type": "lldb", | ||
"request": "launch", | ||
"name": "Debug C++", | ||
"program": "node", | ||
"args": [ | ||
// Allow current instance to use up to 10 gigs of RAM, because why not? :) | ||
"--max_old_space_size=10240", | ||
"--require", | ||
"ts-node/register", | ||
"${file}" | ||
], | ||
"cwd": "${workspaceFolder}" | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "Debug tests", | ||
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", | ||
"args": [ | ||
"-u", | ||
"tdd", | ||
"--timeout", | ||
"999999", | ||
"--colors", | ||
"${workspaceFolder}/test", | ||
// "${workspaceFolder}/test/test.svm.js", | ||
// "${workspaceFolder}/test/test.program.js", | ||
"--device=1", | ||
], | ||
"internalConsoleOptions": "openOnSessionStart" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,43 @@ | ||
# Node OpenCL (TypeScript) | ||
|
||
This is a fork of mikeseven's node-opencl project from: | ||
https://github.com/mikeseven/node-opencl (by https://github.com/mikeseven) | ||
|
||
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`. | ||
|
||
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`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we move the TS-specific docs to a subsection? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can stick to original readme, or have new one created, no need for message above |
||
|
||
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). | ||
|
||
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. | ||
|
||
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: | ||
|
||
```typescript | ||
export type Kilos<T> = T & { readonly discriminator: unique symbol }; | ||
export type Pounds<T> = T & { readonly discriminator: unique symbol }; | ||
|
||
export interface MetricWeight { | ||
value: Kilos<number> | ||
} | ||
|
||
export interface ImperialWeight { | ||
value: Pounds<number> | ||
} | ||
|
||
const wm: MetricWeight = { value: 0 as Kilos<number> } | ||
const wi: ImperialWeight = { value: 0 as Pounds<number> } | ||
|
||
wm.value = wi.value; // Gives compiler error | ||
wi.value = wi.value * 2; // Gives compiler error | ||
wm.value = wi.value * 2; // Gives compiler error | ||
const we: MetricWeight = { value: 0 } // Gives compiler error | ||
``` | ||
|
||
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). | ||
|
||
-------------------- | ||
|
||
# Node OpenCL | ||
|
||
[![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. | |
|
||
## Int 64 | ||
|
||
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 | ||
|
||
value = (hi << 32) | lo | ||
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. | ||
|
||
## Differences between Node-OpenCL and WebCL | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,15 +44,23 @@ | |
['OS in "linux freebsd openbsd solaris android"', { | ||
'variables' : { | ||
# AMD APP SDK | ||
'OPENCL_SDK' : '<!(echo $AMDAPPSDKROOT)', | ||
'OPENCL_SDK_INCLUDE' : '<(OPENCL_SDK)/include', | ||
'OPENCL_SDK_LIB' : '<(OPENCL_SDK)/lib/x86_64', | ||
'AMD_OPENCL_SDK' : '<!(echo $AMDAPPSDKROOT)', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT this may knock out linux intel -- so we should test on some? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I've just noticed, it's not just renaming |
||
'AMD_OPENCL_SDK_INCLUDE' : '<(AMD_OPENCL_SDK)/include', | ||
'AMD_OPENCL_SDK_LIB' : '<(AMD_OPENCL_SDK)/lib/x86_64', | ||
|
||
# NVIDA CUDA SDK | ||
'NVIDA_CUDA_SDK' : '<!(echo ${CUDA_PATH:-/usr/local/cuda})', | ||
'NVIDA_CUDA_SDK_INCLUDE' : '<(NVIDA_CUDA_SDK)/include', | ||
'NVIDA_CUDA_SDK_LIB' : '<(NVIDA_CUDA_SDK)/lib64', | ||
}, | ||
'include_dirs' : [ | ||
"<(OPENCL_SDK_INCLUDE)", | ||
"<(AMD_OPENCL_SDK_INCLUDE)", "<(NVIDA_CUDA_SDK_INCLUDE)" | ||
], | ||
'library_dirs' : [ | ||
"<(AMD_OPENCL_SDK_LIB)", "<(NVIDA_CUDA_SDK_LIB)" | ||
], | ||
'libraries': ['-L<(OPENCL_SDK_LIB)','-lOpenCL'], | ||
'cflags_cc': ['-std=c++11',' -Wall','-O3'] | ||
'libraries': ['-lOpenCL'], | ||
'cflags_cc': ['-std=c++11', '-Wall', '-O3', '-Wno-ignored-attributes'] | ||
}], | ||
['OS=="win"', { | ||
'variables' : | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is default Visual Studio Code
launch.json
config file, I think it is reasonable to remove it