Permalink
Browse files

Added cuDeviceGet() and cuDeviceGetName() methods.

  • Loading branch information...
1 parent 58c0de7 commit 4abd0da216c306a08feb55f2a1e9d0e575eb966f @kashif kashif committed Mar 8, 2011
Showing with 33 additions and 10 deletions.
  1. +21 −4 src/cuda_device.cpp
  2. +4 −1 src/cuda_device.hpp
  3. +8 −5 test/test.js
View
@@ -5,15 +5,17 @@ Persistent<FunctionTemplate> CudaDevice::constructor_template;
void CudaDevice::Initialize (Handle<Object> target) {
HandleScope scope;
+ cuInit(0);
+
+ NODE_SET_METHOD(target, "DriverGetVersion", driverGetVersion);
+ NODE_SET_METHOD(target, "DeviceGetCount", deviceGetCount);
+
Local<FunctionTemplate> t = FunctionTemplate::New(CudaDevice::New);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("CudaDevice"));
- cuInit(0);
-
- NODE_SET_METHOD(target, "DriverGetVersion", driverGetVersion);
- NODE_SET_METHOD(target, "DeviceGetCount", deviceGetCount);
+ NODE_SET_PROTOTYPE_METHOD(constructor_template, "GetName", CudaDevice::getName);
target->Set(String::NewSymbol("CudaDevice"), constructor_template->GetFunction());
}
@@ -34,7 +36,22 @@ Handle<Value> CudaDevice::deviceGetCount(const Arguments& args) {
Handle<Value> CudaDevice::New(const Arguments& args) {
HandleScope scope;
+
+ int ordinal = args[0]->IntegerValue();
CudaDevice *cu = new CudaDevice();
+ cuDeviceGet(&(cu->m_device), ordinal);
+
cu->Wrap(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);
}
View
@@ -14,11 +14,14 @@ class CudaDevice : public EventEmitter {
static Handle<Value> New(const Arguments& args);
static Handle<Value> driverGetVersion(const Arguments& args);
static Handle<Value> deviceGetCount(const Arguments& args);
+ static Handle<Value> getName(const Arguments& args);
CudaDevice() : EventEmitter () {
m_device = NULL;
}
- ~CudaDevice();
+
+ ~CudaDevice(){
+ }
private:
CUdevice m_device;
View
@@ -1,11 +1,14 @@
var cu = require(__dirname + '/../build/default/binding');
-var driverVersion = cu.DriverGetVersion(); //cuDriverGetVersion()
+//cuDriverGetVersion()
+var driverVersion = cu.DriverGetVersion();
console.log("Driver version: " + driverVersion);
-var count = cu.DeviceGetCount(); //cuDeviceGetCount
+//cuDeviceGetCount
+var count = cu.DeviceGetCount();
console.log("Device count: " + count);
-
-var device = new cu.CudaDevice();
-//var device = new cu.DeviceGet(0); //cuDeviceGet(0)
+//cuDeviceGet
+var cuDevice = new cu.CudaDevice(0);
+//cuDeviceGetName
+console.log("Device name: " + cuDevice.GetName());

0 comments on commit 4abd0da

Please sign in to comment.