node-webcl
Advanced tools
Comparing version
@@ -55,9 +55,34 @@ // Copyright (c) 2011-2012, Motorola Mobility, Inc. | ||
//Pick platform | ||
var platformList=WebCL.getPlatforms(); | ||
platform=platformList[0]; | ||
// //Pick platform | ||
// var platformList=WebCL.getPlatforms(); | ||
// platform=platformList[0]; | ||
//Query the set of devices on this platform | ||
devices = platform.getDevices(WebCL.DEVICE_TYPE_DEFAULT); | ||
log(" # of Devices Available = " + devices.length); | ||
// //Query the set of devices on this platform | ||
// devices = platform.getDevices(WebCL.DEVICE_TYPE_DEFAULT); | ||
// log(" # of Devices Available = " + devices.length); | ||
// var device = devices[0]; | ||
// log(" Using Device 0: " + device.getInfo(WebCL.DEVICE_NAME)+" from "+device.getInfo(WebCL.DEVICE_VENDOR)); | ||
// if(device.getInfo(WebCL.DEVICE_VENDOR).indexOf("Intel")>=0) { | ||
// device = devices[1]; | ||
// log(" Using Device 1: " + device.getInfo(WebCL.DEVICE_NAME)+" from "+device.getInfo(WebCL.DEVICE_VENDOR)); | ||
// } | ||
// // create GPU context for this platform | ||
// context=WebCL.createContext({ | ||
// deviceType: WebCL.DEVICE_TYPE_DEFAULT, | ||
// platform: platform | ||
// }); | ||
var context=null; | ||
try { | ||
context=WebCL.createContext({ | ||
deviceType: WebCL.DEVICE_TYPE_ALL, | ||
}); | ||
} | ||
catch(ex) { | ||
throw new Exception("Can't create CL context"); | ||
} | ||
var devices=context.getInfo(WebCL.CONTEXT_DEVICES); | ||
log("Found "+devices.length+" devices"); | ||
var device = devices[0]; | ||
@@ -70,8 +95,2 @@ log(" Using Device 0: " + device.getInfo(WebCL.DEVICE_NAME)+" from "+device.getInfo(WebCL.DEVICE_VENDOR)); | ||
// create GPU context for this platform | ||
context=WebCL.createContext({ | ||
deviceType: WebCL.DEVICE_TYPE_DEFAULT, | ||
platform: platform | ||
}); | ||
kernelSourceCode = [ | ||
@@ -106,23 +125,9 @@ "__kernel void vadd(__global int *a, __global int *b, __global int *c, uint iNumElements) ", | ||
//Create buffer for A and copy host contents | ||
aBuffer = context.createBuffer(WebCL.MEM_READ_ONLY, size); | ||
map=queue.enqueueMapBuffer(aBuffer, WebCL.TRUE, WebCL.MAP_WRITE, 0, BUFFER_SIZE * Uint32Array.BYTES_PER_ELEMENT); | ||
// WARNING: this feature for typed arrays is only in nodejs 0.7.x | ||
var buf=new Uint32Array(map); | ||
for(var i=0;i<BUFFER_SIZE;i++) { | ||
buf.set(i, A[i]); | ||
} | ||
queue.enqueueUnmapMemObject(aBuffer, map); | ||
aBuffer = context.createBuffer(WebCL.MEM_READ_ONLY | WebCL.MEM_COPY_HOST_PTR, size, A); | ||
//Create buffer for B and copy host contents | ||
bBuffer = context.createBuffer(WebCL.MEM_READ_ONLY, size); | ||
map=queue.enqueueMapBuffer(bBuffer, WebCL.TRUE, WebCL.MAP_WRITE, 0, BUFFER_SIZE * Uint32Array.BYTES_PER_ELEMENT); | ||
buf=new Uint32Array(map); | ||
for(var i=0;i<BUFFER_SIZE;i++) { | ||
buf[i]=B[i]; | ||
} | ||
queue.enqueueUnmapMemObject(bBuffer, map); | ||
bBuffer = context.createBuffer(WebCL.MEM_READ_ONLY | WebCL.MEM_COPY_HOST_PTR, size, B); | ||
//Create buffer for that uses the host ptr C | ||
cBuffer = context.createBuffer(WebCL.MEM_READ_WRITE, size); | ||
cBuffer = context.createBuffer(WebCL.MEM_WRITE_ONLY | WebCL.MEM_COPY_HOST_PTR, size, C); | ||
@@ -136,4 +141,6 @@ //Set kernel args | ||
// Execute the OpenCL kernel on the list | ||
var localWS = [5]; // process one list at a time | ||
var globalWS = [clu.roundUp(localWS, BUFFER_SIZE)]; // process entire list | ||
// var localWS = [5]; // process one list at a time | ||
// var globalWS = [clu.roundUp(localWS, BUFFER_SIZE)]; // process entire list | ||
var localWS=null; | ||
var globalWS=[BUFFER_SIZE]; | ||
@@ -154,3 +161,3 @@ log("Global work item size: " + globalWS); | ||
// the host backing space, remember we choose GPU device. | ||
map=queue.enqueueMapBuffer( | ||
var map=queue.enqueueMapBuffer( | ||
cBuffer, | ||
@@ -162,10 +169,11 @@ WebCL.TRUE, // block | ||
buf=new Uint32Array(map); | ||
for(var i=0;i<BUFFER_SIZE;i++) { | ||
C[i]=buf[i]; | ||
var output = "\nC = "; | ||
for (var i = 0; i < BUFFER_SIZE; i++) { | ||
output += map[i] + ", "; | ||
} | ||
log(output); | ||
queue.enqueueUnmapMemObject(cBuffer, map); | ||
queue.finish(); //Finish all the operations | ||
// queue.finish(); //Finish all the operations | ||
@@ -172,0 +180,0 @@ printResults(A,B,C); |
{ | ||
"name":"node-webcl", | ||
"version":"0.7.0", | ||
"version":"0.7.1", | ||
"description":"A WebCL implementation for desktops with NodeJS", | ||
@@ -39,5 +39,5 @@ "main":"webcl.js", | ||
"dependencies":{ | ||
"node-webgl" : "0.2.0" | ||
"node-webgl" : ">=0.2.0" | ||
} | ||
} | ||
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
1561695
0.03%6318
0.11%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
Updated