Skip to content

Commit 555c531

Browse files
committed
Feat: rename Dslice to DeviceSlice, fix clippy errs, start adding CI
1 parent 017d5da commit 555c531

File tree

37 files changed

+286
-228
lines changed

37 files changed

+286
-228
lines changed

.github/workflows/rust.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Rust CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
env:
10+
RUST_LOG: info
11+
RUST_BACKTRACE: 1
12+
13+
jobs:
14+
rust:
15+
name: Rust ${{ matrix.rust }} on ${{ matrix.os }}
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
- { rust: nightly, os: ubuntu-latest }
22+
- { rust: nightly, os: windows-latest }
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v2
26+
27+
- name: Install CUDA
28+
uses: Jimver/[email protected]
29+
id: cuda-toolkit
30+
with:
31+
cuda: '11.5.0'
32+
33+
- name: Setup Rust
34+
uses: hecrj/setup-rust-action@v1
35+
with:
36+
rust-version: ${{ matrix.rust }}
37+
components: clippy,rustfmt
38+
39+
- name: Load Rust Cache
40+
uses: Swatinem/rust-cache@v1
41+
42+
- name: Rustfmt
43+
if: contains(matrix.os, 'ubuntu')
44+
run: cargo fmt --all -- --check
45+
46+
- name: Build
47+
run: cargo build --workspace
48+
49+
# Don't currently test because many tests rely on the system having a CUDA GPU
50+
# - name: Test
51+
# run: cargo test --workspace
52+
53+
- name: Clippy
54+
if: contains(matrix.os, 'ubuntu')
55+
env:
56+
RUSTFLAGS: -Dwarnings
57+
run: cargo clippy --workspace
58+
59+
- name: Check documentation
60+
env:
61+
RUSTDOCFLAGS: -Dwarnings
62+
run: cargo doc --workspace --all-features --document-private-items --no-deps

crates/cuda_builder/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ impl CudaBuilder {
237237
println!("cargo:rerun-if-changed={}", self.path_to_crate.display());
238238
let path = invoke_rustc(&self)?;
239239
if let Some(copy_path) = self.ptx_file_copy_path {
240-
std::fs::copy(path, &copy_path)
241-
.map_err(|x| CudaBuilderError::FailedToCopyPtxFile(x))?;
240+
std::fs::copy(path, &copy_path).map_err(CudaBuilderError::FailedToCopyPtxFile)?;
242241
Ok(copy_path)
243242
} else {
244243
Ok(path)
@@ -282,7 +281,8 @@ fn find_rustc_codegen_nvvm() -> PathBuf {
282281
fn add_libnvvm_to_path() {
283282
let split_paths = env::var_os(dylib_path_envvar()).unwrap_or_default();
284283
let mut paths = env::split_paths(&split_paths).collect::<Vec<_>>();
285-
let libnvvm_path = PathBuf::from(find_cuda_helper::find_cuda_root().unwrap())
284+
let libnvvm_path = find_cuda_helper::find_cuda_root()
285+
.unwrap()
286286
.join("nvvm")
287287
.join("bin");
288288
paths.push(libnvvm_path);
@@ -324,9 +324,7 @@ fn invoke_rustc(builder: &CudaBuilder) -> Result<PathBuf, CudaBuilderError> {
324324
rustflags.push(format!("--emit={}", string));
325325
}
326326

327-
let mut llvm_args = vec![];
328-
329-
llvm_args.push(NvvmOption::Arch(builder.arch).to_string());
327+
let mut llvm_args = vec![NvvmOption::Arch(builder.arch).to_string()];
330328

331329
if !builder.nvvm_opts {
332330
llvm_args.push("-opt=0".to_string());

crates/cuda_std/src/float_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Extension trait for [`f32`] and [`f64`], providing high level wrappers on top of
2-
//! raw libdevice intrinsics from [`intrinsics`](crate::instrinsics).
2+
//! raw libdevice intrinsics from [`intrinsics`](crate::intrinsics).
33
44
use crate::intrinsics as raw;
55

crates/cuda_std_macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn gpu_only(_attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -
158158
cloned_attrs.retain(|a| {
159159
!a.path
160160
.get_ident()
161-
.map(|x| x.to_string() == "nvvm_internal")
161+
.map(|x| *x == "nvvm_internal")
162162
.unwrap_or_default()
163163
});
164164

crates/cust/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project will be documented in this file.
77
- Rename `DBuffer` -> `DeviceBuffer`. This is how it was in rustacuda, but it was changed
88
at some point, but now we reconsidered that it may be the wrong choice.
99
- Renamed `DBox` -> `DeviceBox`.
10+
- Renamed `DSlice` -> `DeviceSlice`.
1011
- Fixed some doctests that were using old APIs.
1112
- Remove `GpuBox::as_device_ptr_mut` and `GpuBuffer::as_device_ptr_mut`.
1213
- Change `GpuBox::as_device_ptr` and `GpuBuffer::as_device_ptr` to take `&self` instead of `&mut self`.

crates/cust/src/function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl From<(u32, u32, u32)> for GridSize {
5757
}
5858
impl<'a> From<&'a GridSize> for GridSize {
5959
fn from(other: &GridSize) -> GridSize {
60-
other.clone()
60+
*other
6161
}
6262
}
6363
#[cfg(feature = "vek")]
@@ -137,7 +137,7 @@ impl From<(u32, u32, u32)> for BlockSize {
137137
}
138138
impl<'a> From<&'a BlockSize> for BlockSize {
139139
fn from(other: &BlockSize) -> BlockSize {
140-
other.clone()
140+
*other
141141
}
142142
}
143143
#[cfg(feature = "vek")]

crates/cust/src/memory/device/device_buffer.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::{CudaResult, DropResult, ToResult};
2-
use crate::memory::device::{AsyncCopyDestination, CopyDestination, DSlice};
2+
use crate::memory::device::{AsyncCopyDestination, CopyDestination, DeviceSlice};
33
use crate::memory::malloc::{cuda_free, cuda_malloc};
44
use crate::memory::DeviceCopy;
55
use crate::memory::DevicePointer;
@@ -227,22 +227,22 @@ impl<T: DeviceCopy> DeviceBuffer<T> {
227227
}
228228
}
229229
impl<T> Deref for DeviceBuffer<T> {
230-
type Target = DSlice<T>;
230+
type Target = DeviceSlice<T>;
231231

232-
fn deref(&self) -> &DSlice<T> {
232+
fn deref(&self) -> &DeviceSlice<T> {
233233
unsafe {
234-
DSlice::from_slice(::std::slice::from_raw_parts(
234+
DeviceSlice::from_slice(::std::slice::from_raw_parts(
235235
self.buf.as_raw(),
236236
self.capacity,
237237
))
238238
}
239239
}
240240
}
241241
impl<T> DerefMut for DeviceBuffer<T> {
242-
fn deref_mut(&mut self) -> &mut DSlice<T> {
242+
fn deref_mut(&mut self) -> &mut DeviceSlice<T> {
243243
unsafe {
244244
&mut *(::std::slice::from_raw_parts_mut(self.buf.as_raw_mut(), self.capacity)
245-
as *mut [T] as *mut DSlice<T>)
245+
as *mut [T] as *mut DeviceSlice<T>)
246246
}
247247
}
248248
}

0 commit comments

Comments
 (0)