Skip to content
GPGPU Framework for Rust
Rust
Branch: master
Clone or download
Latest commit fecbf4b Aug 9, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Install nvptx Jul 30, 2018
accel-core Add link to target triple for xargo release Jun 14, 2018
accel-derive drop ptx_mod Aug 1, 2018
cuda-sys Format cuda-sys Jul 29, 2018
examples Fix host vector init #50 Aug 9, 2018
src Create Vec based on Managed Memory Aug 2, 2018
.gitignore Add -o option Nov 5, 2017
Cargo.toml Use latest derive Jul 30, 2018
LICENSE Initial commit Nov 1, 2017
README.md Update README [skip ci] Jul 30, 2018
rustfmt.toml Fix format config Jul 29, 2018

README.md

Accel: GPGPU Framework for Rust

Crate docs.rs CircleCI

CUDA-based GPGPU framework for Rust

Features

Sub Crates

Pre-requirements

  • Install CUDA on your system
  • Install LLVM 6.0 or later (use llc and llvm-link to generate PTX)
  • Install Rust using rustup.rs
    • Use the nightly Rust toolchain with rustup override nightly
  • Install nvptx, and install accel-nvptx toolchain
cargo install nvptx
nvptx install       # install accel-nvptx toolchain to $XDG_DATA_HOME/accel-nvptx

Or, you can use termoshtt/rust-cuda container whith satisfies these requirements.

docker run -it --rm --runtime=nvidia termoshtt/rust-cuda

See also nvidia-docker

Example

#![feature(proc_macro, proc_macro_gen)]

extern crate accel;
extern crate accel_derive;

use accel_derive::kernel;
use accel::*;

#[kernel]
#[crate("accel-core" = "0.2.0-alpha")]
pub unsafe fn add(a: *const f64, b: *const f64, c: *mut f64, n: usize) {
    let i = accel_core::index();
    if (i as usize) < n {
        *c.offset(i) = *a.offset(i) + *b.offset(i);
    }
}

fn main() {
    let n = 32;
    let mut a = UVec::new(n).unwrap();
    let mut b = UVec::new(n).unwrap();
    let mut c = UVec::new(n).unwrap();

    for i in 0..n {
        a[i] = i as f64;
        b[i] = 2.0 * i as f64;
    }
    println!("a = {:?}", a.as_slice());
    println!("b = {:?}", b.as_slice());

    let grid = Grid::x(1);
    let block = Block::x(n as u32);
    add(grid, block, a.as_ptr(), b.as_ptr(), c.as_mut_ptr(), n);

    device::sync().unwrap();
    println!("c = {:?}", c.as_slice());
}

Licence

MIT-License

You can’t perform that action at this time.