Skip to content

Commit

Permalink
Feat: rename Dslice to DeviceSlice, fix clippy errs, start adding CI
Browse files Browse the repository at this point in the history
  • Loading branch information
RDambrosio016 committed Nov 24, 2021
1 parent 017d5da commit 555c531
Show file tree
Hide file tree
Showing 37 changed files with 286 additions and 228 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Rust CI

on:
pull_request:
push:
branches:
- master

env:
RUST_LOG: info
RUST_BACKTRACE: 1

jobs:
rust:
name: Rust ${{ matrix.rust }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { rust: nightly, os: ubuntu-latest }
- { rust: nightly, os: windows-latest }
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install CUDA
uses: Jimver/cuda-toolkit@v0.2.4
id: cuda-toolkit
with:
cuda: '11.5.0'

- name: Setup Rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: ${{ matrix.rust }}
components: clippy,rustfmt

- name: Load Rust Cache
uses: Swatinem/rust-cache@v1

- name: Rustfmt
if: contains(matrix.os, 'ubuntu')
run: cargo fmt --all -- --check

- name: Build
run: cargo build --workspace

# Don't currently test because many tests rely on the system having a CUDA GPU
# - name: Test
# run: cargo test --workspace

- name: Clippy
if: contains(matrix.os, 'ubuntu')
env:
RUSTFLAGS: -Dwarnings
run: cargo clippy --workspace

- name: Check documentation
env:
RUSTDOCFLAGS: -Dwarnings
run: cargo doc --workspace --all-features --document-private-items --no-deps
10 changes: 4 additions & 6 deletions crates/cuda_builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ impl CudaBuilder {
println!("cargo:rerun-if-changed={}", self.path_to_crate.display());
let path = invoke_rustc(&self)?;
if let Some(copy_path) = self.ptx_file_copy_path {
std::fs::copy(path, &copy_path)
.map_err(|x| CudaBuilderError::FailedToCopyPtxFile(x))?;
std::fs::copy(path, &copy_path).map_err(CudaBuilderError::FailedToCopyPtxFile)?;
Ok(copy_path)
} else {
Ok(path)
Expand Down Expand Up @@ -282,7 +281,8 @@ fn find_rustc_codegen_nvvm() -> PathBuf {
fn add_libnvvm_to_path() {
let split_paths = env::var_os(dylib_path_envvar()).unwrap_or_default();
let mut paths = env::split_paths(&split_paths).collect::<Vec<_>>();
let libnvvm_path = PathBuf::from(find_cuda_helper::find_cuda_root().unwrap())
let libnvvm_path = find_cuda_helper::find_cuda_root()
.unwrap()
.join("nvvm")
.join("bin");
paths.push(libnvvm_path);
Expand Down Expand Up @@ -324,9 +324,7 @@ fn invoke_rustc(builder: &CudaBuilder) -> Result<PathBuf, CudaBuilderError> {
rustflags.push(format!("--emit={}", string));
}

let mut llvm_args = vec![];

llvm_args.push(NvvmOption::Arch(builder.arch).to_string());
let mut llvm_args = vec![NvvmOption::Arch(builder.arch).to_string()];

if !builder.nvvm_opts {
llvm_args.push("-opt=0".to_string());
Expand Down
2 changes: 1 addition & 1 deletion crates/cuda_std/src/float_ext.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Extension trait for [`f32`] and [`f64`], providing high level wrappers on top of
//! raw libdevice intrinsics from [`intrinsics`](crate::instrinsics).
//! raw libdevice intrinsics from [`intrinsics`](crate::intrinsics).

use crate::intrinsics as raw;

Expand Down
2 changes: 1 addition & 1 deletion crates/cuda_std_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn gpu_only(_attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -
cloned_attrs.retain(|a| {
!a.path
.get_ident()
.map(|x| x.to_string() == "nvvm_internal")
.map(|x| *x == "nvvm_internal")
.unwrap_or_default()
});

Expand Down
1 change: 1 addition & 0 deletions crates/cust/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Notable changes to this project will be documented in this file.
- Rename `DBuffer` -> `DeviceBuffer`. This is how it was in rustacuda, but it was changed
at some point, but now we reconsidered that it may be the wrong choice.
- Renamed `DBox` -> `DeviceBox`.
- Renamed `DSlice` -> `DeviceSlice`.
- Fixed some doctests that were using old APIs.
- Remove `GpuBox::as_device_ptr_mut` and `GpuBuffer::as_device_ptr_mut`.
- Change `GpuBox::as_device_ptr` and `GpuBuffer::as_device_ptr` to take `&self` instead of `&mut self`.
4 changes: 2 additions & 2 deletions crates/cust/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl From<(u32, u32, u32)> for GridSize {
}
impl<'a> From<&'a GridSize> for GridSize {
fn from(other: &GridSize) -> GridSize {
other.clone()
*other
}
}
#[cfg(feature = "vek")]
Expand Down Expand Up @@ -137,7 +137,7 @@ impl From<(u32, u32, u32)> for BlockSize {
}
impl<'a> From<&'a BlockSize> for BlockSize {
fn from(other: &BlockSize) -> BlockSize {
other.clone()
*other
}
}
#[cfg(feature = "vek")]
Expand Down
12 changes: 6 additions & 6 deletions crates/cust/src/memory/device/device_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::{CudaResult, DropResult, ToResult};
use crate::memory::device::{AsyncCopyDestination, CopyDestination, DSlice};
use crate::memory::device::{AsyncCopyDestination, CopyDestination, DeviceSlice};
use crate::memory::malloc::{cuda_free, cuda_malloc};
use crate::memory::DeviceCopy;
use crate::memory::DevicePointer;
Expand Down Expand Up @@ -227,22 +227,22 @@ impl<T: DeviceCopy> DeviceBuffer<T> {
}
}
impl<T> Deref for DeviceBuffer<T> {
type Target = DSlice<T>;
type Target = DeviceSlice<T>;

fn deref(&self) -> &DSlice<T> {
fn deref(&self) -> &DeviceSlice<T> {
unsafe {
DSlice::from_slice(::std::slice::from_raw_parts(
DeviceSlice::from_slice(::std::slice::from_raw_parts(
self.buf.as_raw(),
self.capacity,
))
}
}
}
impl<T> DerefMut for DeviceBuffer<T> {
fn deref_mut(&mut self) -> &mut DSlice<T> {
fn deref_mut(&mut self) -> &mut DeviceSlice<T> {
unsafe {
&mut *(::std::slice::from_raw_parts_mut(self.buf.as_raw_mut(), self.capacity)
as *mut [T] as *mut DSlice<T>)
as *mut [T] as *mut DeviceSlice<T>)
}
}
}
Expand Down
Loading

0 comments on commit 555c531

Please sign in to comment.