Skip to content
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

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
54712c7
upgraded to latest NAN 2.8.0, checked tests on MacBook Pro's crappy O…
mikeseven Nov 24, 2017
89f006d
updated with CL 2.1 headers (methods not implemented yet)
mikeseven Nov 26, 2017
3f9d6c0
updated with CL 2.2 header (no method implementation yet)
mikeseven Nov 26, 2017
7d2de1f
cleaned up deprecated warnings with v8 and nan
mikeseven Nov 26, 2017
9bdbdda
updated examples to support OCL 1.2 and 2. Tested on Mac (opencl 1.2).
mikeseven Feb 25, 2018
ed2ccbd
blacklisted some tests not working, buggy driver, on Mac OS X.
mikeseven Feb 25, 2018
69507c0
move some things from dependencies to devDependencies
trxcllnt Apr 27, 2018
0393dde
upgraded to latest NAN 2.8.0, checked tests on MacBook Pro's crappy O…
mikeseven Nov 24, 2017
efda566
updated with CL 2.1 headers (methods not implemented yet)
mikeseven Nov 26, 2017
6413147
updated with CL 2.2 header (no method implementation yet)
mikeseven Nov 26, 2017
f1fbff9
cleaned up deprecated warnings with v8 and nan
mikeseven Nov 26, 2017
aeea819
updated examples to support OCL 1.2 and 2. Tested on Mac (opencl 1.2).
mikeseven Feb 25, 2018
964da8b
blacklisted some tests not working, buggy driver, on Mac OS X.
mikeseven Feb 25, 2018
209cb50
Merge branch 'feature/upgrade_to_NAN_2.8.0' of https://github.com/mik…
trxcllnt Apr 28, 2018
50c2981
schedule AsyncQueueWorker to be called on the main thread
trxcllnt May 19, 2018
c36300c
support cl_nv_device_attribute_query
trxcllnt Jun 21, 2018
4fcad23
update withContext test util to use opencl2 createContextWithType
trxcllnt Jan 11, 2019
6adb7ec
use updated node-memwatch, cleanup test_leak1 test
trxcllnt Jan 11, 2019
5f391a8
fix test.svm tests for intel-opencl 2.1
trxcllnt Jan 11, 2019
515d27b
add vscode debugging launch configuration
trxcllnt Jan 11, 2019
3e54df5
fix createImage host_ptr argument index
trxcllnt Jan 21, 2019
f2c7c41
fix or ignore failing tests to make everything pass in Intel Experime…
trxcllnt Jan 21, 2019
8a825a2
skip some tests that segfault on nvidia pascal
trxcllnt Apr 25, 2019
6a5f1d4
fix node v12.0.0 compilation errors
trxcllnt Apr 25, 2019
64afb34
fix -Wdeprecated-declarations warnings
trxcllnt Apr 25, 2019
938ba1f
ignore gcc std::vector alignment warning (https://stackoverflow.com/a…
trxcllnt Apr 25, 2019
9062771
add scripts to debug c++ in vscode
trxcllnt Apr 25, 2019
e33ed63
get program binaries and create program from binary
trxcllnt Apr 25, 2019
d73b663
cleanup more cl objects in tests
trxcllnt Apr 26, 2019
8070411
use nan@^2.13.2
trxcllnt Apr 26, 2019
c64da8d
use FromJust() instead of ToChecked() for backwards-compatibility wit…
trxcllnt Apr 29, 2019
87c4e63
Add missing Nan support, for sampler.cpp, less than OpencCL version 2
lu4 Jun 6, 2019
f029a1c
Minor code quality improvements
lu4 Jun 6, 2019
39c4486
Based on https://github.com/mikeseven/node-opencl/pull/66/commits/360…
lu4 Jun 6, 2019
33f26f9
TypeScript support, initial commit
lu4 Jun 9, 2019
140c2cc
Intermediate commit
lu4 Aug 14, 2019
9dc971e
Merge pull request #1 from lu4/TypeScriptSupport
lu4 Aug 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
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
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
.vscode
build
dist
docker
node_modules
55 changes: 55 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
// Use IntelliSense to learn about possible attributes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid json?

Copy link
Contributor Author

@lu4 lu4 Nov 26, 2019

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

// 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"
}
]
}
44 changes: 41 additions & 3 deletions README.md
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`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the TS-specific docs to a subsection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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

Expand Down
20 changes: 14 additions & 6 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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' :
Expand Down
126 changes: 0 additions & 126 deletions examples/saxpy.js

This file was deleted.

Loading