Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Clean up olds #66

Merged
merged 10 commits into from
Jan 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions .circleci/config.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Static Check"
on:
push:
branches:
- master
pull_request: {}

jobs:
cargo_check:
runs-on: ubuntu-latest
name: check
steps:
- uses: actions/checkout@v1
- name: Install LLVM libraries
run: |
sudo apt update
sudo apt install -y llvm-dev
- name: check
run: cargo check

cargo_fmt:
runs-on: ubuntu-latest
name: format
steps:
- uses: actions/checkout@v1
- name: format
run: cargo fmt -- --check
25 changes: 5 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
[package]
name = "accel"
version = "0.2.1-alpha.0"
authors = ["Toshiki Teramura <toshiki.teramura@gmail.com>"]
[workspace]
members = [
"accel",
"accel-derive",
]

description = "GPGPU Framework for Rust"
documentation = "https://docs.rs/accel"
repository = "https://github.com/termoshtt/accel"
keywords = ["GPGPU", "CUDA"]
license = "MIT"
readme = "README.md"
categories = []

[dependencies]
procedurals = "0.2.3"

[dependencies.cuda-sys]
version = "0.2.0"

[dev-dependencies.accel-derive]
path = "./accel-derive"
16 changes: 8 additions & 8 deletions accel-derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//! proc_macro for accel's #[kernel]
#![feature(proc_macro)]
#![recursion_limit = "128"]

extern crate nvptx;
Expand Down Expand Up @@ -37,7 +36,8 @@ impl Attributes {
/// Create a nvptx compiler-driver
fn create_driver(&self) -> nvptx::Driver {
let driver = nvptx::Driver::new().expect("Fail to create compiler-driver");
nvptx::manifest::generate(driver.path(), &self.crates).expect("Fail to generate Cargo.toml");
nvptx::manifest::generate(driver.path(), &self.crates)
.expect("Fail to generate Cargo.toml");
driver
}
}
Expand All @@ -55,9 +55,9 @@ const QUOTE: &[char] = &[' ', '"'];
/// equals to `accel-core = { path = "/some/path" }`
fn parse_crate(attr: &syn::Attribute) -> Crate {
let path = &attr.path;
let path = quote!{#path}.to_string();
let path = quote! {#path}.to_string();
let tts = &attr.tts;
let tts = quote!{#tts}.to_string();
let tts = quote! {#tts}.to_string();
let tokens: Vec<_> = tts
.trim_matches(PENE)
.split('=')
Expand Down Expand Up @@ -102,7 +102,7 @@ fn header(crates: &[Crate]) -> String {
.iter()
.map(|c| syn::Ident::from(c.name.replace("-", "_")))
.collect();
let tt = quote!{
let tt = quote! {
#![feature(abi_ptx)]
#![no_std]
#(extern crate #crates;), *
Expand All @@ -122,7 +122,7 @@ fn ptx_kernel(func: &syn::ItemFn) -> String {
let inputs = &decl.inputs;
let output = &decl.output;

let kernel = quote!{
let kernel = quote! {
#[no_mangle]
#vis #unsafety extern "ptx-kernel" #fn_token #ident(#inputs) #output #block
};
Expand Down Expand Up @@ -153,9 +153,9 @@ fn func2caller(ptx_str: &str, func: &syn::ItemFn) -> TokenStream {
_ => unreachable!(""),
})
.collect();
let kernel_name = quote!{ #ident }.to_string();
let kernel_name = quote! { #ident }.to_string();

let caller = quote!{
let caller = quote! {
#vis #fn_token #ident(grid: ::accel::Grid, block: ::accel::Block, #inputs) #output {
use ::accel::kernel::void_cast;
use ::accel::module::Module;
Expand Down
21 changes: 21 additions & 0 deletions accel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "accel"
version = "0.2.1-alpha.0"
authors = ["Toshiki Teramura <toshiki.teramura@gmail.com>"]

description = "GPGPU Framework for Rust"
documentation = "https://docs.rs/accel"
repository = "https://github.com/termoshtt/accel"
keywords = ["GPGPU", "CUDA"]
license = "MIT"
readme = "README.md"
categories = []

[dependencies]
procedurals = "0.2.3"

cuda-runtime-sys = "=0.3.0-alpha.1"
cuda-driver-sys = "=0.3.0-alpha.1"

[dev-dependencies.accel-derive]
path = "../accel-derive"
File renamed without changes.
17 changes: 10 additions & 7 deletions src/device.rs → accel/src/device.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cudart::*;
use error::*;
use ffi::cudart::*;
use std::mem;

pub use ffi::cudart::cudaComputeMode as ComputeMode;
pub use ffi::cudart::cudaDeviceProp as DeviceProp;
pub use cudart::cudaComputeMode as ComputeMode;
pub use cudart::cudaDeviceProp as DeviceProp;

pub fn sync() -> Result<()> {
unsafe { cudaDeviceSynchronize() }.check()
Expand Down Expand Up @@ -54,7 +54,7 @@ impl Device {
let mut devs = Vec::new();
for i in 0..n {
let dev = Device::set(i)?;
if dev.compute_mode()? != ComputeMode::Prohibited {
if dev.compute_mode()? != ComputeMode::cudaComputeModeProhibited as i32 {
devs.push(dev)
}
}
Expand Down Expand Up @@ -99,7 +99,10 @@ impl Device {
}
})
.collect();
Ok(String::from_utf8(name).expect("Invalid GPU name").trim().to_string())
Ok(String::from_utf8(name)
.expect("Invalid GPU name")
.trim()
.to_string())
}

pub fn cores(&self) -> Result<u32> {
Expand Down Expand Up @@ -128,14 +131,14 @@ impl Device {
Ok(mpc * rate * cores)
}

pub fn compute_mode(&self) -> Result<ComputeMode> {
pub fn compute_mode(&self) -> Result<i32> {
let prop = self.get_property()?;
Ok(prop.computeMode)
}

pub fn get_property(&self) -> Result<DeviceProp> {
unsafe {
let mut prop = mem::uninitialized();
let mut prop = mem::MaybeUninit::uninit().assume_init();
cudaGetDeviceProperties(&mut prop as *mut _, self.0).check()?;
Ok(prop)
}
Expand Down
18 changes: 3 additions & 15 deletions src/error.rs → accel/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#![allow(non_camel_case_types)]

pub use ffi::cublas::cublasStatus_t as cublasError;
pub use ffi::cuda::cudaError_t as cudaError;
pub use ffi::cudart::cudaError_t as cudaRuntimeError;
pub use cuda::cudaError_enum as cudaError;
pub use cudart::cudaError_t as cudaRuntimeError;

pub type Result<T> = ::std::result::Result<T, Error>;

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, IntoEnum)]
pub enum Error {
cudaError(cudaError),
cudaRuntimeError(cudaRuntimeError),
cublasError(cublasError),
}

pub trait Check {
Expand All @@ -29,17 +27,7 @@ impl Check for cudaError {

impl Check for cudaRuntimeError {
fn check(self) -> Result<()> {
if self == cudaRuntimeError::Success {
Ok(())
} else {
Err(self.into())
}
}
}

impl Check for cublasError {
fn check(self) -> Result<()> {
if self == cublasError::SUCCESS {
if self == cudaRuntimeError::cudaSuccess {
Ok(())
} else {
Err(self.into())
Expand Down
14 changes: 10 additions & 4 deletions src/kernel.rs → accel/src/kernel.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Execution control in
//! [CUDA Deriver APIs](http://docs.nvidia.com/cuda/cuda-driver-api/group__CUDA__EXEC.html)

use cuda::*;
use cudart::*;
use error::*;
use ffi::cuda::*;
use ffi::vector_types::*;

use std::os::raw::*;
use std::ptr::null_mut;
Expand All @@ -19,7 +19,12 @@ pub struct Kernel<'m> {

impl<'m> Kernel<'m> {
/// Launch CUDA kernel using `cuLaunchKernel`
pub unsafe fn launch(&mut self, args: *mut *mut c_void, grid: Grid, block: Block) -> Result<()> {
pub unsafe fn launch(
&mut self,
args: *mut *mut c_void,
grid: Grid,
block: Block,
) -> Result<()> {
cuLaunchKernel(
self.func,
grid.x,
Expand All @@ -32,7 +37,8 @@ impl<'m> Kernel<'m> {
null_mut(), // use default stream
args,
null_mut(), // no extra
).check()
)
.check()
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs → accel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
//! ==============================
//!

extern crate cuda_sys as ffi;
extern crate cuda_driver_sys as cuda;
extern crate cuda_runtime_sys as cudart;

#[macro_use]
extern crate procedurals;

pub mod device;
pub mod error;
pub mod kernel;
pub mod module;
pub mod uvec;
pub mod mvec;
pub mod uvec;

pub use kernel::{Block, Grid};
pub use uvec::UVec;
pub use mvec::MVec;
pub use uvec::UVec;
Loading