Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

use stdsimd #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ name = "kernel"
version = "0.1.0"

[dependencies]
nvptx-builtins = "0.1.0"
stdsimd = { git = "https://github.com/rust-lang-nursery/stdsimd", features = [ ] }
28 changes: 15 additions & 13 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#![feature(abi_ptx)]
#![no_std]

extern crate nvptx_builtins as intrinsics;
extern crate stdsimd;

use stdsimd::nvptx;

/// Add two "vectors" of length `n`. `c <- a + b`
#[no_mangle]
pub unsafe extern "ptx-kernel" fn add(a: *const f32,
b: *const f32,
c: *mut f32,
n: usize) {
let i = intrinsics::block_dim_x()
.wrapping_mul(intrinsics::block_idx_x())
.wrapping_add(intrinsics::thread_idx_x()) as isize;
let i = nvptx::_block_dim_x()
.wrapping_mul(nvptx::_block_idx_x())
.wrapping_add(nvptx::_thread_idx_x()) as isize;

if (i as usize) < n {
*c.offset(i) = *a.offset(i) + *b.offset(i);
Expand All @@ -23,9 +25,9 @@ pub unsafe extern "ptx-kernel" fn add(a: *const f32,
pub unsafe extern "ptx-kernel" fn memcpy(dst: *mut f32,
src: *const f32,
n: usize) {
let i = (intrinsics::block_dim_x())
.wrapping_mul(intrinsics::block_idx_x())
.wrapping_add(intrinsics::thread_idx_x()) as isize;
let i = (nvptx::_block_dim_x())
.wrapping_mul(nvptx::_block_idx_x())
.wrapping_add(nvptx::_thread_idx_x()) as isize;

if (i as usize) < n {
*dst.offset(i) = *src.offset(i);
Expand All @@ -45,12 +47,12 @@ pub unsafe extern "ptx-kernel" fn rgba2gray(rgba: *const Rgba,
gray: *mut u8,
width: i32,
height: i32) {
let x = intrinsics::block_idx_x()
.wrapping_mul(intrinsics::block_dim_x())
.wrapping_add(intrinsics::thread_idx_x());
let y = intrinsics::block_idx_y()
.wrapping_mul(intrinsics::block_dim_y())
.wrapping_add(intrinsics::thread_idx_y());
let x = nvptx::_block_idx_x()
.wrapping_mul(nvptx::_block_dim_x())
.wrapping_add(nvptx::_thread_idx_x());
let y = nvptx::_block_idx_y()
.wrapping_mul(nvptx::_block_dim_y())
.wrapping_add(nvptx::_thread_idx_y());

if x < width && y < height {
let i = y.wrapping_mul(width).wrapping_add(x) as isize;
Expand Down