Giter Site home page Giter Site logo

node-nvrtc's Introduction

node-nvrtc 让Node.js使用NVRTC的扩展

node-nvrtc是一个简易的使用nvrtcnode.js扩展,目前只包含简单的nvrtc功能和cuda内存交换相关功能。

安装

npm install node-nvrtc

目前已经编译过的环境有win-x86_64以及linux-x86_64,编译的cuda版本为10.2,其他环境需要手动根据cuda开发环境重新进行编译。

如果要在win64或者linux-x86_64下直接使用的话需要安装cuda10.2

  • 需要注意的是nvrtc本身并不支持32位系统

使用

基本的使用方式如下

var NVRTC = require("node-nvrtc");

/**可用的设备数量 */
var deviceCount = NVRTC.getDeviceCount();

if(deviceCount <= 0){
  throw new Error("无法运行例子,因为并没有找到合适的设备");
}

//查看所有设备的信息
for(var i = 0;i < deviceCount;i++){
  console.log(`设备${i}`,NVRTC.getDeviceProperties(i));
}


/**用于计算的数据 */
var data = new Float32Array([1,2,3,4,5]);
/**显存空间 */
var cudaData = new NVRTC.CudaBuffer(data.byteLength);
//将js数据写入到cuda显存
cudaData.writeData(data.buffer);



/**用于测试的cuda代码,计算数的平方 */
var code = `my_program
__global__
void my_kernel(float* data) {
    data[threadIdx.x] = data[threadIdx.x] * data[threadIdx.x];
}`;

/**初始化计算用的启动器 */
var launcher = new NVRTC.CudaProgram(code).createKernel("my_kernel").createInstantiate([]).createLauncher([1,1,1],[data.length,1,1]);

//进行一次cuda运算
launcher.run(cudaData);

//读取计算结果
cudaData.readData(data.buffer);
console.log(data);

node-nvrtc's People

Stargazers

 avatar Zerl(o) avatar chenyang avatar 老城哥 avatar

Watchers

James Cloos avatar 老城哥 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.