Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

whitespace fixes

  • Loading branch information...
commit 6728e7a6e4c56f75e4c3ac676e0599e8be722179 1 parent 56b3c9f
@kashif authored
View
6 index.js
@@ -43,12 +43,12 @@ function alignUp(offset, alignment) {
module.exports.prepareArguments = function (args) {
var paramBufferSize = 0;
-
+
for (var i in args) {
var type = args[i].type;
paramBufferSize = alignUp(paramBufferSize, typeAlignment[type]);
-
+
if (typeof(typeByteSize[type]) != "number")
throw "Invalid type given";
@@ -60,7 +60,7 @@ module.exports.prepareArguments = function (args) {
var offset = 0;
for (var i in args) {
var type = args[i].type;
-
+
offset = alignUp(offset, typeAlignment[type]);
if (type == "DevicePtr") {
View
4 src/bindings.hpp
@@ -9,8 +9,8 @@ using namespace node;
namespace NodeCuda {
-static Handle<Value> GetDriverVersion(Local<String> property, const AccessorInfo &info);
-static Handle<Value> GetDeviceCount(Local<String> property, const AccessorInfo &info);
+ static Handle<Value> GetDriverVersion(Local<String> property, const AccessorInfo &info);
+ static Handle<Value> GetDeviceCount(Local<String> property, const AccessorInfo &info);
}
View
16 src/ctx.cpp
@@ -7,7 +7,7 @@ Persistent<FunctionTemplate> Ctx::constructor_template;
void Ctx::Initialize(Handle<Object> target) {
HandleScope scope;
-
+
Local<FunctionTemplate> t = FunctionTemplate::New(Ctx::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
@@ -26,13 +26,13 @@ void Ctx::Initialize(Handle<Object> target) {
Handle<Value> Ctx::New(const Arguments& args) {
HandleScope scope;
-
+
Ctx *pctx = new Ctx();
pctx->Wrap(args.This());
-
+
unsigned int flags = args[0]->Uint32Value();
pctx->m_device = ObjectWrap::Unwrap<Device>(args[1]->ToObject())->m_device;
-
+
cuCtxCreate(&(pctx->m_context), flags, pctx->m_device);
return args.This();
@@ -121,10 +121,10 @@ void Ctx::EIO_Synchronize(eio_req *req) {
params->error = cuCtxPushCurrent(params->ctx->m_context);
if (params->error) return;
-
+
params->error = cuCtxSynchronize();
if (params->error) return;
-
+
params->error = cuCtxPopCurrent(NULL);
}
@@ -132,7 +132,7 @@ int Ctx::EIO_AfterSynchronize(eio_req *req) {
HandleScope scope;
SynchronizeParams *params = static_cast<SynchronizeParams*>(req->data);
ev_unref(EV_DEFAULT_UC);
-
+
params->ctx->Unref();
params->ctx->sync_in_progress = false;
@@ -158,6 +158,6 @@ Handle<Value> Ctx::GetApiVersion(Local<String> property, const AccessorInfo &inf
unsigned int version;
CUresult error = cuCtxGetApiVersion(pctx->m_context, &version);
-
+
return scope.Close(Number::New(version));
}
View
58 src/ctx.hpp
@@ -7,35 +7,35 @@
namespace NodeCuda {
-class Ctx : public ObjectWrap {
-public:
- static void Initialize(Handle<Object> target);
-
-protected:
- static Persistent<FunctionTemplate> constructor_template;
-
- static Handle<Value> New(const Arguments& args);
- static Handle<Value> Destroy(const Arguments& args);
- static Handle<Value> PushCurrent(const Arguments& args);
- static Handle<Value> PopCurrent(const Arguments& args);
- static Handle<Value> SetCurrent(const Arguments& args);
- static Handle<Value> GetCurrent(const Arguments& args);
- static Handle<Value> Synchronize(const Arguments& args);
- static Handle<Value> GetApiVersion(Local<String> property, const AccessorInfo &info);
-
- Ctx() : ObjectWrap(), m_context(NULL), m_device(0), sync_in_progress(false) {}
-
- ~Ctx () {}
-
-private:
- CUcontext m_context;
- CUdevice m_device;
-
- bool sync_in_progress;
-
- static void EIO_Synchronize(eio_req *req);
- static int EIO_AfterSynchronize(eio_req *req);
-};
+ class Ctx : public ObjectWrap {
+ public:
+ static void Initialize(Handle<Object> target);
+
+ protected:
+ static Persistent<FunctionTemplate> constructor_template;
+
+ static Handle<Value> New(const Arguments& args);
+ static Handle<Value> Destroy(const Arguments& args);
+ static Handle<Value> PushCurrent(const Arguments& args);
+ static Handle<Value> PopCurrent(const Arguments& args);
+ static Handle<Value> SetCurrent(const Arguments& args);
+ static Handle<Value> GetCurrent(const Arguments& args);
+ static Handle<Value> Synchronize(const Arguments& args);
+ static Handle<Value> GetApiVersion(Local<String> property, const AccessorInfo &info);
+
+ Ctx() : ObjectWrap(), m_context(NULL), m_device(0), sync_in_progress(false) {}
+
+ ~Ctx () {}
+
+ private:
+ CUcontext m_context;
+ CUdevice m_device;
+
+ bool sync_in_progress;
+
+ static void EIO_Synchronize(eio_req *req);
+ static int EIO_AfterSynchronize(eio_req *req);
+ };
}
View
8 src/device.cpp
@@ -22,7 +22,7 @@ void Device::Initialize(Handle<Object> target) {
static Handle<Value> GetName_(CUdevice device) {
HandleScope scope;
char deviceName[256];
-
+
cuDeviceGetName(deviceName, 256, device);
Local<String> result = String::New(deviceName);
return scope.Close(result);
@@ -36,7 +36,7 @@ Handle<Value> Device::New(const Arguments& args) {
if (!constructor_template->HasInstance(result)) {
result = constructor_template->InstanceTemplate()->NewInstance();
}
-
+
Device *pdevice = new Device();
cuDeviceGet(&(pdevice->m_device), ordinal);
@@ -50,7 +50,7 @@ Handle<Value> Device::GetComputeCapability(Local<String> property, const Accesso
Device *pdevice = ObjectWrap::Unwrap<Device>(info.Holder());
int major = 0, minor = 0;
cuDeviceComputeCapability(&major, &minor, pdevice->m_device);
-
+
Local<Object> result = Object::New();
result->Set(String::New("major"), Integer::New(major));
result->Set(String::New("minor"), Integer::New(minor));
@@ -70,6 +70,6 @@ Handle<Value> Device::GetTotalMem(Local<String> property, const AccessorInfo &in
Device *pdevice = ObjectWrap::Unwrap<Device>(info.Holder());
size_t totalGlobalMem;
cuDeviceTotalMem(&totalGlobalMem, pdevice->m_device);
-
+
return scope.Close(Number::New(totalGlobalMem));
}
View
34 src/device.hpp
@@ -6,30 +6,30 @@
namespace NodeCuda {
-class Device : public ObjectWrap {
-public:
- static void Initialize(Handle<Object> target);
+ class Device : public ObjectWrap {
+ public:
+ static void Initialize(Handle<Object> target);
-protected:
- static Persistent<FunctionTemplate> constructor_template;
+ protected:
+ static Persistent<FunctionTemplate> constructor_template;
- static Handle<Value> New(const Arguments& args);
- static Handle<Value> GetComputeCapability(Local<String> property, const AccessorInfo &info);
- static Handle<Value> GetName(Local<String> property, const AccessorInfo &info);
- static Handle<Value> GetTotalMem(Local<String> property, const AccessorInfo &info);
+ static Handle<Value> New(const Arguments& args);
+ static Handle<Value> GetComputeCapability(Local<String> property, const AccessorInfo &info);
+ static Handle<Value> GetName(Local<String> property, const AccessorInfo &info);
+ static Handle<Value> GetTotalMem(Local<String> property, const AccessorInfo &info);
- // TODO: cuDeviceGetAttribute
- // TODO: cuDeviceGetProperties
+ // TODO: cuDeviceGetAttribute
+ // TODO: cuDeviceGetProperties
- Device() : ObjectWrap(), m_device(NULL) {}
+ Device() : ObjectWrap(), m_device(NULL) {}
- ~Device() {}
+ ~Device() {}
-private:
- CUdevice m_device;
+ private:
+ CUdevice m_device;
- friend class Ctx;
-};
+ friend class Ctx;
+ };
}
View
8 src/function.cpp
@@ -15,7 +15,7 @@ void NodeCuda::Function::Initialize(Handle<Object> target) {
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("CudaFunction"));
-
+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "launchKernel", NodeCuda::Function::LaunchKernel);
// Function objects can only be created by cuModuleGetFunction
@@ -55,9 +55,9 @@ Handle<Value> NodeCuda::Function::LaunchKernel(const Arguments& args) {
};
CUresult error = cuLaunchKernel(pfunction->m_function,
- gridDimX, gridDimY, gridDimZ,
- blockDimX, blockDimY, blockDimZ,
- 0, 0, NULL, cuExtra);
+ gridDimX, gridDimY, gridDimZ,
+ blockDimX, blockDimY, blockDimZ,
+ 0, 0, NULL, cuExtra);
return scope.Close(Number::New(error));
}
View
26 src/function.hpp
@@ -7,26 +7,26 @@
namespace NodeCuda {
-class Function : public ObjectWrap {
-public:
- static void Initialize(Handle<Object> target);
+ class Function : public ObjectWrap {
+ public:
+ static void Initialize(Handle<Object> target);
-protected:
- static Persistent<FunctionTemplate> constructor_template;
+ protected:
+ static Persistent<FunctionTemplate> constructor_template;
- static Handle<Value> LaunchKernel(const Arguments& args);
+ static Handle<Value> LaunchKernel(const Arguments& args);
- Function() : ObjectWrap(), m_function(0) {}
+ Function() : ObjectWrap(), m_function(0) {}
- ~Function() {}
+ ~Function() {}
-private:
- static Handle<Value> New(const Arguments& args);
+ private:
+ static Handle<Value> New(const Arguments& args);
- CUfunction m_function;
+ CUfunction m_function;
- friend Handle<Value> Module::GetFunction(const Arguments&);
-};
+ friend Handle<Value> Module::GetFunction(const Arguments&);
+ };
}
View
2  src/mem.cpp
@@ -17,7 +17,7 @@ void Mem::Initialize(Handle<Object> target) {
// Mem objects can only be created by allocation functions
NODE_SET_METHOD(target, "memAlloc", Mem::Alloc);
NODE_SET_METHOD(target, "memAllocPitch", Mem::AllocPitch);
-
+
constructor_template->InstanceTemplate()->SetAccessor(String::New("devicePtr"), Mem::GetDevicePtr);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "free", Mem::Free);
View
38 src/mem.hpp
@@ -7,32 +7,32 @@
namespace NodeCuda {
-class Mem : public ObjectWrap {
-public:
- static void Initialize(Handle<Object> target);
+ class Mem : public ObjectWrap {
+ public:
+ static void Initialize(Handle<Object> target);
-protected:
- static Persistent<FunctionTemplate> constructor_template;
+ protected:
+ static Persistent<FunctionTemplate> constructor_template;
- static Handle<Value> Alloc(const Arguments& args);
- static Handle<Value> AllocPitch(const Arguments& args);
- static Handle<Value> Free(const Arguments& args);
- static Handle<Value> CopyHtoD(const Arguments& args);
- static Handle<Value> CopyDtoH(const Arguments& args);
+ static Handle<Value> Alloc(const Arguments& args);
+ static Handle<Value> AllocPitch(const Arguments& args);
+ static Handle<Value> Free(const Arguments& args);
+ static Handle<Value> CopyHtoD(const Arguments& args);
+ static Handle<Value> CopyDtoH(const Arguments& args);
- static Handle<Value> GetDevicePtr(Local<String> property, const AccessorInfo &info);
-
- Mem() : ObjectWrap(), m_devicePtr(0) {}
+ static Handle<Value> GetDevicePtr(Local<String> property, const AccessorInfo &info);
- ~Mem() {}
+ Mem() : ObjectWrap(), m_devicePtr(0) {}
-private:
- static Handle<Value> New(const Arguments& args);
+ ~Mem() {}
- CUdeviceptr m_devicePtr;
+ private:
+ static Handle<Value> New(const Arguments& args);
- friend class NodeCuda::Function;
-};
+ CUdeviceptr m_devicePtr;
+
+ friend class NodeCuda::Function;
+ };
}
View
12 src/module.cpp
@@ -7,7 +7,7 @@ Persistent<FunctionTemplate> Module::constructor_template;
void Module::Initialize(Handle<Object> target) {
HandleScope scope;
-
+
Local<FunctionTemplate> t = FunctionTemplate::New(Module::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
@@ -15,7 +15,7 @@ void Module::Initialize(Handle<Object> target) {
// Module objects can only be created by load functions
NODE_SET_METHOD(target, "moduleLoad", Module::Load);
-
+
NODE_SET_PROTOTYPE_METHOD(constructor_template, "getFunction", Module::GetFunction);
}
@@ -35,10 +35,10 @@ Handle<Value> Module::Load(const Arguments& args) {
String::AsciiValue fname(args[0]);
CUresult error = cuModuleLoad(&(pmodule->m_module), *fname);
-
+
result->Set(String::New("fname"), args[0]);
result->Set(String::New("error"), Integer::New(error));
-
+
return scope.Close(result);
}
@@ -50,10 +50,10 @@ Handle<Value> Module::GetFunction(const Arguments& args) {
String::AsciiValue name(args[0]);
CUresult error = cuModuleGetFunction(&(pfunction->m_function), pmodule->m_module, *name);
-
+
result->Set(String::New("name"), args[0]);
result->Set(String::New("error"), Integer::New(error));
-
+
return scope.Close(result);
}
View
38 src/module.hpp
@@ -6,25 +6,25 @@
namespace NodeCuda {
-class Module : public ObjectWrap {
-public:
- static void Initialize(Handle<Object> target);
- static Handle<Value> GetFunction(const Arguments& args);
-
-protected:
- static Persistent<FunctionTemplate> constructor_template;
-
- static Handle<Value> Load(const Arguments& args);
-
- Module() : ObjectWrap(), m_module(0) {}
-
- ~Module() {}
-
-private:
- static Handle<Value> New(const Arguments& args);
-
- CUmodule m_module;
-};
+ class Module : public ObjectWrap {
+ public:
+ static void Initialize(Handle<Object> target);
+ static Handle<Value> GetFunction(const Arguments& args);
+
+ protected:
+ static Persistent<FunctionTemplate> constructor_template;
+
+ static Handle<Value> Load(const Arguments& args);
+
+ Module() : ObjectWrap(), m_module(0) {}
+
+ ~Module() {}
+
+ private:
+ static Handle<Value> New(const Arguments& args);
+
+ CUmodule m_module;
+ };
}
View
47 test/test.js
@@ -5,24 +5,22 @@ var cu = require(__dirname + '/../index');
//cuDeviceGetCount
console.log("Node-cuda exports:", cu);
-for (var i=0; i<cu.deviceCount; i++) {
- //cuDeviceGet
- var cuDevice = new cu.Device(i);
-
- //cuDeviceComputeCapability
- //cuDeviceGetName
- //cuDeviceTotalMem
- console.log("Device " + i + ":", cuDevice);
+for (var i = 0; i < cu.deviceCount; i++) {
+ //cuDeviceGet
+ var cuDevice = new cu.Device(i);
+
+ //cuDeviceComputeCapability
+ //cuDeviceGetName
+ //cuDeviceTotalMem
+ console.log("Device " + i + ":", cuDevice);
}
-
//cuCtxCreate
var cuCtx = new cu.Ctx(0, cu.Device(0));
//cuCtxGetApiVersion
console.log("Created context:", cuCtx);
-
//cuMemAllocPitch
var cuMem = cu.memAllocPitch(100, 100, 8);
console.log("Allocated 100x100 array of doubles:", cuMem);
@@ -36,8 +34,8 @@ var cuMem = cu.memAlloc(100);
console.log("Allocated 100 bytes:", cuMem);
var buf = new Buffer(100);
-for (var i=0; i<buf.length; i++) {
- buf[i] = (i+1) % 256;
+for (var i = 0; i < buf.length; i++) {
+ buf[i] = (i + 1) % 256;
}
console.log("Created buffer of 100 bytes:", buf);
@@ -45,7 +43,6 @@ console.log("Created buffer of 100 bytes:", buf);
var error = cuMem.copyHtoD(buf);
console.log("Copied buffer to device:", error);
-
//cuModuleLoad
var cuModule = cu.moduleLoad("test/test.cubin");
console.log("Loaded module:", cuModule);
@@ -55,25 +52,27 @@ var cuFunction = cuModule.getFunction("helloWorld");
console.log("Got function:", cuFunction);
//cuLaunchKernel
-var error = cu.launch(cuFunction, [3,1,1], [2,2,2],
- [ { type: "DevicePtr", value: cuMem.devicePtr } ]);
+var error = cu.launch(cuFunction, [3, 1, 1], [2, 2, 2],
+[{
+ type: "DevicePtr",
+ value: cuMem.devicePtr
+}]);
console.log("Launched kernel:", error);
-
// cuMemcpyDtoH
var error = cuMem.copyDtoH(buf, true);
console.log("Copied buffer to host:", error);
//cuCtxSynchronize
-var error = cuCtx.synchronize(function (error) {
- console.log("Context synchronize with error code: " + error);
+var error = cuCtx.synchronize(function(error) {
+ console.log("Context synchronize with error code: " + error);
- //cuMemFree
- var error = cuMem.free();
- console.log("Mem Free with error code: " + error);
+ //cuMemFree
+ var error = cuMem.free();
+ console.log("Mem Free with error code: " + error);
- //cuCtxDestroy
- error = cuCtx.destroy();
- console.log("Context destroyed with error code: " + error);
+ //cuCtxDestroy
+ error = cuCtx.destroy();
+ console.log("Context destroyed with error code: " + error);
});
Please sign in to comment.
Something went wrong with that request. Please try again.