-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added initial Cuda Context bindings.
- Loading branch information
Kashif Rasul
committed
Jul 23, 2011
1 parent
0992bde
commit 66d103b
Showing
7 changed files
with
73 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
#include "bindings.hpp" | ||
#include "cuda_device.hpp" | ||
#include "cuda_ctx.hpp" | ||
|
||
extern "C" | ||
void init (Handle<Object> target) { | ||
HandleScope scope; | ||
CudaDevice::Initialize(target); | ||
CudaCtx::Initialize(target); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "cuda_ctx.hpp" | ||
#include "cuda_device.hpp" | ||
|
||
Persistent<FunctionTemplate> CudaCtx::constructor_template; | ||
|
||
void CudaCtx::Initialize(Handle<Object> target) { | ||
HandleScope scope; | ||
|
||
Local<FunctionTemplate> t = FunctionTemplate::New(CudaCtx::New); | ||
constructor_template = Persistent<FunctionTemplate>::New(t); | ||
constructor_template->InstanceTemplate()->SetInternalFieldCount(1); | ||
constructor_template->SetClassName(String::NewSymbol("CudaCtx")); | ||
|
||
NODE_SET_PROTOTYPE_METHOD(constructor_template, "Destroy", CudaCtx::destroy); | ||
|
||
target->Set(String::NewSymbol("CudaCtx"), constructor_template->GetFunction()); | ||
} | ||
|
||
Handle<Value> CudaCtx::New(const Arguments& args) { | ||
HandleScope scope; | ||
|
||
CudaCtx *pctx = new CudaCtx(); | ||
pctx->Wrap(args.Holder()); | ||
|
||
unsigned int flags = args[0]->Uint32Value(); | ||
CudaDevice *pdev = ObjectWrap::Unwrap<CudaDevice>(args[1]->ToObject()); | ||
|
||
CUresult error = cuCtxCreate(&(pctx->m_context), flags, pdev->m_device); | ||
return args.This(); | ||
} | ||
|
||
Handle<Value> CudaCtx::destroy(const Arguments& args) { | ||
HandleScope scope; | ||
CudaCtx *pctx = ObjectWrap::Unwrap<CudaCtx>(args.Holder()); | ||
|
||
CUresult error = cuCtxDestroy(pctx->m_context); | ||
return scope.Close(Number::New(error)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef CUDA_CTX_HPP | ||
#define CUDA_CTX_HPP | ||
|
||
#include <cuda.h> | ||
#include "bindings.hpp" | ||
|
||
class CudaCtx : public EventEmitter | ||
{ | ||
public: | ||
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); | ||
|
||
CudaCtx () : EventEmitter () { | ||
m_context = NULL; | ||
} | ||
~CudaCtx (){} | ||
|
||
private: | ||
CUcontext m_context; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters