Permalink
Browse files

Moved some functions around. Cleaned up formatting.

  • Loading branch information...
1 parent 471946d commit b89d2b6f49959a06b846532f298c274d6ada3435 Jitu Das committed Mar 23, 2012
Showing with 58 additions and 51 deletions.
  1. +24 −1 src/bindings.cpp
  2. +3 −0 src/bindings.hpp
  3. +1 −1 src/cuda_ctx.cpp
  4. +7 −8 src/cuda_ctx.hpp
  5. +1 −20 src/cuda_device.cpp
  6. +9 −11 src/cuda_device.hpp
  7. +1 −1 src/cuda_mem.cpp
  8. +10 −7 src/cuda_mem.hpp
  9. +1 −1 test/test.js
  10. +1 −1 wscript
View
@@ -5,9 +5,32 @@
void init (Handle<Object> target) {
HandleScope scope;
+
+ // Initiailze the cuda driver api
+ cuInit(0);
+
+ // These methods don't need instances
+ NODE_SET_METHOD(target, "DriverGetVersion", driverGetVersion);
+ NODE_SET_METHOD(target, "DeviceGetCount", deviceGetCount);
+
+ // Initialize driver api bindings
CudaDevice::Initialize(target);
CudaCtx::Initialize(target);
CudaMem::Initialize(target);
}
-NODE_MODULE(cuda, init);
+Handle<Value> driverGetVersion(const Arguments& args) {
+ HandleScope scope;
+ int driverVersion = 0;
+ cuDriverGetVersion(&driverVersion);
+ return scope.Close(Integer::New(driverVersion));
+}
+
+Handle<Value> deviceGetCount(const Arguments& args) {
+ HandleScope scope;
+ int count = 0;
+ cuDeviceGetCount(&count);
+ return scope.Close(Integer::New(count));
+}
+
+NODE_MODULE(cuda, init);
View
@@ -7,4 +7,7 @@
using namespace v8;
using namespace node;
+static Handle<Value> driverGetVersion(const Arguments& args);
+static Handle<Value> deviceGetCount(const Arguments& args);
+
#endif
View
@@ -90,4 +90,4 @@ Handle<Value> CudaCtx::getApiVersion(const Arguments& args) {
CUresult error = cuCtxGetApiVersion(pctx->m_context, &version);
return scope.Close(Number::New(version));
-}
+}
View
@@ -4,13 +4,13 @@
#include <cuda.h>
#include "bindings.hpp"
-class CudaCtx : public ObjectWrap
-{
+class CudaCtx : public ObjectWrap {
public:
- static void Initialize (Handle<Object> target);
+ 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);
@@ -20,12 +20,11 @@ class CudaCtx : public ObjectWrap
static Handle<Value> synchronize(const Arguments& args);
static Handle<Value> getApiVersion(const Arguments& args);
- CudaCtx () : ObjectWrap () {
- m_context = NULL;
- }
- ~CudaCtx (){}
+ CudaCtx() : ObjectWrap(), m_context(NULL) {}
+
+ ~CudaCtx () {}
private:
CUcontext m_context;
};
-#endif
+#endif
View
@@ -5,11 +5,6 @@ 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);
@@ -22,20 +17,6 @@ void CudaDevice::Initialize (Handle<Object> target) {
target->Set(String::NewSymbol("CudaDevice"), constructor_template->GetFunction());
}
-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));
-}
-
Handle<Value> CudaDevice::New(const Arguments& args) {
HandleScope scope;
@@ -79,4 +60,4 @@ Handle<Value> CudaDevice::totalMem(const Arguments& args) {
cuDeviceTotalMem(&totalGlobalMem, cu->m_device);
return scope.Close(Number::New(totalGlobalMem));
-}
+}
View
@@ -6,26 +6,24 @@
class CudaDevice : public ObjectWrap {
public:
- static void Initialize (Handle<Object> target);
-
- CUdevice m_device;
+ static void Initialize(Handle<Object> target);
protected:
static Persistent<FunctionTemplate> constructor_template;
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);
static Handle<Value> computeCapability(const Arguments& args);
static Handle<Value> totalMem(const Arguments& args);
- CudaDevice() : ObjectWrap () {
- m_device = NULL;
- }
+ CudaDevice() : ObjectWrap(), m_device(NULL) {}
+
+ ~CudaDevice() {}
+
+private:
+ CUdevice m_device;
- ~CudaDevice(){
- }
+ friend class CudaCtx;
};
-#endif
+#endif
View
@@ -57,4 +57,4 @@ Handle<Value> CudaMem::free(const Arguments& args) {
CUresult error = cuMemFree(cuptr->m_devicePtr);
return scope.Close(Number::New(error));
-}
+}
View
@@ -6,19 +6,22 @@
class CudaMem : public ObjectWrap {
public:
+ static void Initialize(Handle<Object> target);
+
+protected:
static Persistent<FunctionTemplate> constructor_template;
- static void Initialize (Handle<Object> target);
+
static Handle<Value> New(const Arguments& args);
static Handle<Value> alloc(const Arguments& args);
static Handle<Value> allocPitch(const Arguments& args);
static Handle<Value> free(const Arguments& args);
+ CudaMem() : ObjectWrap(), m_devicePtr(0) {}
+
+ ~CudaMem() {}
+
+private:
CUdeviceptr m_devicePtr;
-protected:
- CudaMem () : ObjectWrap () {
- m_devicePtr = 0;
- }
- ~CudaMem (){}
};
-#endif
+#endif
View
@@ -46,4 +46,4 @@ cuMem.Free();
//cuCtxDestroy
error = cuCtx.Destroy();
-console.log("Context destroyed with error code: " + error);
+console.log("Context destroyed with error code: " + error);
View
@@ -12,7 +12,7 @@ def configure(conf):
conf.check_tool("node_addon")
if not conf.check(lib="cuda",
- libpath=['/usr/local/cuda/lib'],
+ libpath=['/usr/local/cuda/lib', '/usr/lib64/nvidia-graphics-current'],
includes=['/usr/local/cuda/include'],
uselib_store="CUDA"):
conf.fatal('Cannot find CUDA library.');

0 comments on commit b89d2b6

Please sign in to comment.