Skip to content

Commit

Permalink
Added cuDeviceGet() and cuDeviceGetName() methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashif Rasul committed Mar 8, 2011
1 parent 58c0de7 commit 4abd0da
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
25 changes: 21 additions & 4 deletions src/cuda_device.cpp
Expand Up @@ -5,15 +5,17 @@ Persistent<FunctionTemplate> CudaDevice::constructor_template;
void CudaDevice::Initialize (Handle<Object> target) { void CudaDevice::Initialize (Handle<Object> target) {
HandleScope scope; HandleScope scope;


cuInit(0);

NODE_SET_METHOD(target, "DriverGetVersion", driverGetVersion);
NODE_SET_METHOD(target, "DeviceGetCount", deviceGetCount);

Local<FunctionTemplate> t = FunctionTemplate::New(CudaDevice::New); Local<FunctionTemplate> t = FunctionTemplate::New(CudaDevice::New);
constructor_template = Persistent<FunctionTemplate>::New(t); constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("CudaDevice")); constructor_template->SetClassName(String::NewSymbol("CudaDevice"));


cuInit(0); NODE_SET_PROTOTYPE_METHOD(constructor_template, "GetName", CudaDevice::getName);

NODE_SET_METHOD(target, "DriverGetVersion", driverGetVersion);
NODE_SET_METHOD(target, "DeviceGetCount", deviceGetCount);


target->Set(String::NewSymbol("CudaDevice"), constructor_template->GetFunction()); target->Set(String::NewSymbol("CudaDevice"), constructor_template->GetFunction());
} }
Expand All @@ -34,7 +36,22 @@ Handle<Value> CudaDevice::deviceGetCount(const Arguments& args) {


Handle<Value> CudaDevice::New(const Arguments& args) { Handle<Value> CudaDevice::New(const Arguments& args) {
HandleScope scope; HandleScope scope;

int ordinal = args[0]->IntegerValue();
CudaDevice *cu = new CudaDevice(); CudaDevice *cu = new CudaDevice();
cuDeviceGet(&(cu->m_device), ordinal);

cu->Wrap(args.This()); cu->Wrap(args.This());
return args.This(); return args.This();
}

Handle<Value> CudaDevice::getName(const Arguments& args) {
HandleScope scope;

CudaDevice *cu = ObjectWrap::Unwrap<CudaDevice>(args.Holder());
char deviceName[256];
cuDeviceGetName(deviceName, 256, cu->m_device);

Local<String> result = String::New(deviceName);
return scope.Close(result);
} }
5 changes: 4 additions & 1 deletion src/cuda_device.hpp
Expand Up @@ -14,11 +14,14 @@ class CudaDevice : public EventEmitter {
static Handle<Value> New(const Arguments& args); static Handle<Value> New(const Arguments& args);
static Handle<Value> driverGetVersion(const Arguments& args); static Handle<Value> driverGetVersion(const Arguments& args);
static Handle<Value> deviceGetCount(const Arguments& args); static Handle<Value> deviceGetCount(const Arguments& args);
static Handle<Value> getName(const Arguments& args);


CudaDevice() : EventEmitter () { CudaDevice() : EventEmitter () {
m_device = NULL; m_device = NULL;
} }
~CudaDevice();
~CudaDevice(){
}


private: private:
CUdevice m_device; CUdevice m_device;
Expand Down
13 changes: 8 additions & 5 deletions test/test.js
@@ -1,11 +1,14 @@
var cu = require(__dirname + '/../build/default/binding'); var cu = require(__dirname + '/../build/default/binding');


var driverVersion = cu.DriverGetVersion(); //cuDriverGetVersion() //cuDriverGetVersion()
var driverVersion = cu.DriverGetVersion();
console.log("Driver version: " + driverVersion); console.log("Driver version: " + driverVersion);


var count = cu.DeviceGetCount(); //cuDeviceGetCount //cuDeviceGetCount
var count = cu.DeviceGetCount();
console.log("Device count: " + count); console.log("Device count: " + count);



//cuDeviceGet
var device = new cu.CudaDevice(); var cuDevice = new cu.CudaDevice(0);
//var device = new cu.DeviceGet(0); //cuDeviceGet(0) //cuDeviceGetName
console.log("Device name: " + cuDevice.GetName());

0 comments on commit 4abd0da

Please sign in to comment.