Skip to content

Commit 0da1a49

Browse files
authored
Merge branch 'Rust-GPU:main' into main
2 parents 28f7d7f + 450d16c commit 0da1a49

File tree

5 files changed

+22
-12
lines changed

5 files changed

+22
-12
lines changed

.github/workflows/rust.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ on:
77
push:
88
paths-ignore:
99
- '**.md'
10-
branches:
11-
- master
1210

1311
env:
1412
RUST_LOG: info
@@ -33,7 +31,7 @@ jobs:
3331
uses: actions/checkout@v2
3432

3533
- name: Install CUDA
36-
uses: Jimver/[email protected].4
34+
uses: Jimver/[email protected].21
3735
id: cuda-toolkit
3836
with:
3937
cuda: '11.2.2'
@@ -74,4 +72,4 @@ jobs:
7472
- name: Check documentation
7573
env:
7674
RUSTDOCFLAGS: -Dwarnings
77-
run: cargo doc --workspace --all-features --document-private-items --no-deps --exclude "optix" --exclude "path_tracer" --exclude "denoiser" --exclude "add" --exclude "ex*"
75+
run: cargo doc --workspace --all-features --document-private-items --no-deps --exclude "optix" --exclude "path_tracer" --exclude "denoiser" --exclude "add" --exclude "ex*"

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ Other projects related to using Rust on the GPU:
8282
- 2020: [rlsl](https://github.com/MaikKlein/rlsl) Experimental Rust -> SPIR-V compiler (predecessor to rust-gpu)
8383
- 2020: [rust-gpu](https://github.com/Rust-GPU/rust-gpu) `rustc` compiler backend to compile Rust to SPIR-V for use in shaders, similar mechanism as our project.
8484

85+
## Usage
86+
```bash
87+
## setup your environment like:
88+
### export OPTIX_ROOT=/opt/NVIDIA-OptiX-SDK-9.0.0-linux64-x86_64
89+
### export OPTIX_ROOT_DIR=/opt/NVIDIA-OptiX-SDK-9.0.0-linux64-x86_64
90+
91+
## build proj
92+
cargo build
93+
```
94+
8595
## License
8696

8797
Licensed under either of

crates/cuda_std/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ pub mod prelude {
7676
};
7777
}
7878

79-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
79+
#[cfg(target_arch = "nvptx64")]
8080
#[alloc_error_handler]
8181
fn alloc_handler(layout: core::alloc::Layout) -> ! {
8282
core::panic!("Memory allocation of {} bytes failed", layout.size());
8383
}
8484

8585
// FIXME(RDambrosio016): For some very odd reason, this function causes an InvalidAddress error when called,
8686
// despite it having no reason for doing that. It needs more debugging to see what is causing it exactly. For now we just trap.
87-
#[cfg(any(target_arch = "nvptx", target_arch = "nvptx64"))]
87+
#[cfg(target_arch = "nvptx64")]
8888
#[panic_handler]
8989
fn panic(_info: &core::panic::PanicInfo) -> ! {
9090
// use crate::prelude::*;

crates/cuda_std_macros/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn kernel(input: proc_macro::TokenStream, item: proc_macro::TokenStream) ->
2727
let mut item = parse_macro_input!(item as ItemFn);
2828
let no_mangle = parse_quote!(#[no_mangle]);
2929
item.attrs.push(no_mangle);
30-
let internal = parse_quote!(#[cfg_attr(any(target_arch="nvptx", target_arch="nvptx64"), nvvm_internal(kernel(#input)))]);
30+
let internal = parse_quote!(#[cfg_attr(target_arch="nvptx64", nvvm_internal(kernel(#input)))]);
3131
item.attrs.push(internal);
3232

3333
// used to guarantee some things about how params are passed in the codegen.
@@ -170,13 +170,13 @@ pub fn gpu_only(_attr: proc_macro::TokenStream, item: proc_macro::TokenStream) -
170170
};
171171

172172
let output = quote::quote! {
173-
#[cfg(not(any(target_arch="nvptx", target_arch="nvptx64")))]
173+
#[cfg(not(target_arch="nvptx64"))]
174174
#[allow(unused_variables)]
175175
#(#cloned_attrs)* #vis #sig_cpu {
176176
unimplemented!(concat!("`", stringify!(#fn_name), "` can only be used on the GPU with rustc_codegen_nvvm"))
177177
}
178178

179-
#[cfg(any(target_arch="nvptx", target_arch="nvptx64"))]
179+
#[cfg(target_arch="nvptx64")]
180180
#(#attrs)* #vis #sig {
181181
#block
182182
}

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl<A: DeviceCopy + Pod> DeviceBuffer<A> {
314314
/// whole number of elements. Such as `3` x [`u16`] -> `1.5` x [`u32`].
315315
/// - If either type is a ZST (but not both).
316316
#[cfg_attr(docsrs, doc(cfg(feature = "bytemuck")))]
317-
pub fn try_cast<B: Pod + DeviceCopy>(self) -> Result<DeviceBuffer<B>, PodCastError> {
317+
pub fn try_cast<B: Pod + DeviceCopy>(mut self) -> Result<DeviceBuffer<B>, PodCastError> {
318318
if align_of::<B>() > align_of::<A>() && (self.buf.as_raw() as usize) % align_of::<B>() != 0
319319
{
320320
Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned)
@@ -325,10 +325,12 @@ impl<A: DeviceCopy + Pod> DeviceBuffer<A> {
325325
Err(PodCastError::SizeMismatch)
326326
} else if (size_of::<A>() * self.len) % size_of::<B>() == 0 {
327327
let new_len = (size_of::<A>() * self.len) / size_of::<B>();
328-
Ok(DeviceBuffer {
328+
let ret = Ok(DeviceBuffer {
329329
buf: self.buf.cast(),
330330
len: new_len,
331-
})
331+
});
332+
unsafe{std::mem::forget(self);}
333+
ret
332334
} else {
333335
Err(PodCastError::OutputSliceWouldHaveSlop)
334336
}

0 commit comments

Comments
 (0)