Permalink
Browse files

Added driverGetVersion and deviceGetCount methods and test.js.

  • Loading branch information...
1 parent cba2a79 commit 0c623a7e0b963581a804682c5b46dc4fd7ea25ff @kashif kashif committed Feb 24, 2011
Showing with 37 additions and 9 deletions.
  1. +2 −1 src/bindings.cpp
  2. +12 −2 src/cuda_device.cpp
  3. +16 −6 src/cuda_device.hpp
  4. +7 −0 test/test.js
View
@@ -3,5 +3,6 @@
extern "C"
void init (Handle<Object> target) {
- CudaDevice::Initialize(target);
+ HandleScope scope;
+ CudaDevice::Initialize(target);
}
View
@@ -1,5 +1,15 @@
#include "cuda_device.hpp"
-CudaDevice::CudaDevice(): EventEmitter() {
- cuDeviceGet(&m_device, 0);
+Handle<Value> CudaDevice::driverGetVersion(const Arguments& args) {
+ HandleScope scope;
+ int driverVersion = 0;
+ cuDriverGetVersion(&driverVersion);
+ return scope.Close(Integer::New(driverVersion));
+}
+
+Handle<Value> CudaDevice::deviceGetCount(const Arguments& args) {
+ HandleScope scope;
+ int count = 0;
+ cuDeviceGetCount(&count);
+ return scope.Close(Integer::New(count));
}
View
@@ -2,19 +2,29 @@
#define CUDA_DEVICE_HPP
#include <cuda.h>
-
#include "bindings.hpp"
class CudaDevice : public EventEmitter {
public:
- static void Initialize (Handle<Object> target);
- static Persistent<FunctionTemplate> constructor_template;
+ static void Initialize (Handle<Object> target) {
+ HandleScope scope;
+
+ cuInit(0);
+
+ NODE_SET_METHOD(target, "DriverGetVersion", driverGetVersion);
+ NODE_SET_METHOD(target, "DeviceGetCount", deviceGetCount);
+ }
protected:
- CUdevice m_device;
+ CUdevice m_device;
+
+ static v8::Handle<v8::Value> driverGetVersion(const v8::Arguments& args);
+ static v8::Handle<v8::Value> deviceGetCount(const v8::Arguments& args);
- CudaDevice();
- ~CudaDevice();
+ CudaDevice() : EventEmitter () {
+ m_device = NULL;
+ }
+ ~CudaDevice();
};
#endif
View
@@ -0,0 +1,7 @@
+var cu = require(__dirname + '/../build/default/binding');
+
+var driverVersion = cu.DriverGetVersion();
+console.log("Driver version: " + driverVersion);
+
+var count = cu.DeviceGetCount();
+console.log("Device count: " + count);

0 comments on commit 0c623a7

Please sign in to comment.