Skip to content

Commit

Permalink
Added further Cuda Context bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kashif Rasul committed Jul 23, 2011
1 parent 66d103b commit b97ecf0
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
55 changes: 55 additions & 0 deletions src/cuda_ctx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ void CudaCtx::Initialize(Handle<Object> target) {
constructor_template->SetClassName(String::NewSymbol("CudaCtx"));

NODE_SET_PROTOTYPE_METHOD(constructor_template, "Destroy", CudaCtx::destroy);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "PushCurrent", CudaCtx::pushCurrent);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "PopCurrent", CudaCtx::popCurrent);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "SetCurrent", CudaCtx::setCurrent);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "GetCurrent", CudaCtx::getCurrent);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "Synchronize", CudaCtx::synchronize);
NODE_SET_PROTOTYPE_METHOD(constructor_template, "GetApiVersion", CudaCtx::getApiVersion);

target->Set(String::NewSymbol("CudaCtx"), constructor_template->GetFunction());
}
Expand All @@ -35,4 +41,53 @@ Handle<Value> CudaCtx::destroy(const Arguments& args) {

CUresult error = cuCtxDestroy(pctx->m_context);
return scope.Close(Number::New(error));
}

Handle<Value> CudaCtx::pushCurrent(const Arguments& args) {
HandleScope scope;
CudaCtx *pctx = ObjectWrap::Unwrap<CudaCtx>(args.Holder());

CUresult error = cuCtxPushCurrent(pctx->m_context);
return scope.Close(Number::New(error));
}

Handle<Value> CudaCtx::popCurrent(const Arguments& args) {
HandleScope scope;
CudaCtx *pctx = ObjectWrap::Unwrap<CudaCtx>(args.Holder());

CUresult error = cuCtxPopCurrent(&(pctx->m_context));
return scope.Close(Number::New(error));
}

Handle<Value> CudaCtx::setCurrent(const Arguments& args) {
HandleScope scope;
CudaCtx *pctx = ObjectWrap::Unwrap<CudaCtx>(args.Holder());

CUresult error = cuCtxSetCurrent(pctx->m_context);
return scope.Close(Number::New(error));
}

Handle<Value> CudaCtx::getCurrent(const Arguments& args) {
HandleScope scope;
CudaCtx *pctx = ObjectWrap::Unwrap<CudaCtx>(args.Holder());

CUresult error = cuCtxGetCurrent(&(pctx->m_context));
return scope.Close(Number::New(error));
}

Handle<Value> CudaCtx::synchronize(const Arguments& args) {
HandleScope scope;

CUresult error = cuCtxSynchronize();
return scope.Close(Number::New(error));
}

Handle<Value> CudaCtx::getApiVersion(const Arguments& args) {
HandleScope scope;
CudaCtx *pctx = ObjectWrap::Unwrap<CudaCtx>(args.Holder());

unsigned int version;
CUresult error = cuCtxGetApiVersion(pctx->m_context, &version);

return scope.Close(Number::New(version));
}
8 changes: 7 additions & 1 deletion src/cuda_ctx.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ class CudaCtx : public EventEmitter
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(const Arguments& args);

CudaCtx () : EventEmitter () {
m_context = NULL;
}
Expand Down
9 changes: 8 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ console.log("Device compute capability: major=" + compute[0] + " minor=" + compu
//cuCtxCreate
var cuCtx = new cu.CudaCtx(0, cuDevice);

//cuCtxSynchronize
var error = cuCtx.Synchronize();
console.log("Context synchronize with error code: " + error);

//cuCtxGetApiVersion
console.log("Context API version: " + cuCtx.GetApiVersion());

//cuCtxDestroy
var error = cuCtx.Destroy();
error = cuCtx.Destroy();
console.log("Context destroyed with error code: " + error);

0 comments on commit b97ecf0

Please sign in to comment.