Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ Please note that while node-gyp should work for compilation, it is possible that

You need to update your path in order to to get AMD APP SDK's OpenCL.dll first in path resolution order.

## Android / Termux

Install Termux (https://termux.com)

Install Termux Packages
- pkg install clang lldb lldb-dev liblldb libuv-dev
- pkg install nodejs-lts nodejs-lts-dev

Install OpenCL headers and libraries
- Copy libOpenCL.so to /data/data/com.termux/files/usr/lib
- Copy opencl header files to /data/data/com.termux/files/usr/include/CL

npm install

When running tests and examples, it may be necessary to set LD_LIBRARY_PATH
- LD_LIBRARY_PATH=/system/lib64:$LD_LIBRARY_PATH

# Usage

For now you can simply require this project and call native-like functions on the global object returned.
Expand Down
14 changes: 13 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
'libraries': ['-framework OpenCL'],
}],
['OS in "linux freebsd openbsd solaris android"', {
['OS in "linux freebsd openbsd solaris"', {
'variables' : {
# AMD APP SDK
'OPENCL_SDK' : '<!(echo $AMDAPPSDKROOT)',
Expand All @@ -54,6 +54,18 @@
'libraries': ['-L<(OPENCL_SDK_LIB)','-lOpenCL'],
'cflags_cc': ['-std=c++11',' -Wall','-O3']
}],
['OS=="android"', {
'variables' : {
'OPENCL_SDK' : '<!(echo $AMDAPPSDKROOT)',
'OPENCL_SDK_INCLUDE' : '<(OPENCL_SDK)/include',
'OPENCL_SDK_LIB' : '<(OPENCL_SDK)/lib/x86_64',
},
'include_dirs' : [
"<(OPENCL_SDK_INCLUDE)",
],
'libraries': ['-L<(OPENCL_SDK_LIB)','-lOpenCL', '-luv'],
'cflags_cc': ['-std=c++11',' -Wall','-O3',' -fPIC']
}],
['OS=="win"', {
'variables' :
{
Expand Down
24 changes: 20 additions & 4 deletions examples/square_events.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var cl = require("../lib/opencl");
var fs = require("fs");

var bcallback = false;

var Square = function() {

var ctx = cl.createContextFromType(
Expand Down Expand Up @@ -46,14 +48,19 @@ var Square = function() {
// here we use the returned user event to associate a callback that will be called from OpenCL
// once read buffer is complete.
var ev = cl.enqueueReadBuffer(cq, outputsMem, true, 0, NVALUES * 4, outputs, [], true);
console.log('have event');
console.log(ev);

cl.setEventCallback(ev, cl.COMPLETE, function(){
cl.setEventCallback(ev, cl.COMPLETE, function(ev2,estat,userData){
console.log('event handler');
console.log("\nLast value is : " + outputs.readUInt32LE(4*(NVALUES-1)));

console.log({event: ev2,error_status: estat,userData});

// now the program can end
console.log("== CL callback thread terminated ==");
process.exit();
});
bcallback = true;
},{data:"hello"});

};

Expand All @@ -62,4 +69,13 @@ Square();

// Main thread will always finish before CL callbacks are finished.
// Calling process.exit() in the main thread would skip CL callbacks from executing
console.log("\n== Main thread terminated ==");

(function wait () {
if (!bcallback) {
setTimeout(wait, 1000);
}
else {
console.log("\n== Main thread terminated ==");
}
})();

Loading