Skip to content

Commit 1083480

Browse files
authored
Fix optix examples (#160)
* Remove missing and unused symbols when compiling cuda. See this [issue](ingowald/optix7course#35), from what I think is the source repo for this header.
1 parent 9b07099 commit 1083480

File tree

7 files changed

+16
-32
lines changed

7 files changed

+16
-32
lines changed

crates/optix/examples/common/gdt/gdt/gdt.h

+6-14
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
#define GDT_TERMINAL_RESET "\033[0m"
108108
#define GDT_TERMINAL_DEFAULT GDT_TERMINAL_RESET
109109
#define GDT_TERMINAL_BOLD "\033[1;1m"
110-
110+
111111

112112

113113

@@ -118,15 +118,7 @@ namespace gdt {
118118
#ifdef __CUDACC__
119119
using ::min;
120120
using ::max;
121-
// inline __both__ float abs(float f) { return fabsf(f); }
122-
// inline __both__ double abs(double f) { return fabs(f); }
123121
using std::abs;
124-
// inline __both__ float sin(float f) { return ::sinf(f); }
125-
// inline __both__ double sin(double f) { return ::sin(f); }
126-
// inline __both__ float cos(float f) { return ::cosf(f); }
127-
// inline __both__ double cos(double f) { return ::cos(f); }
128-
129-
using ::saturate;
130122
#else
131123
using std::min;
132124
using std::max;
@@ -139,12 +131,12 @@ namespace gdt {
139131
// inline __both__ double abs(double f) { return fabs(f); }
140132
inline __both__ float rcp(float f) { return 1.f/f; }
141133
inline __both__ double rcp(double d) { return 1./d; }
142-
134+
143135
inline __both__ int32_t divRoundUp(int32_t a, int32_t b) { return (a+b-1)/b; }
144136
inline __both__ uint32_t divRoundUp(uint32_t a, uint32_t b) { return (a+b-1)/b; }
145137
inline __both__ int64_t divRoundUp(int64_t a, int64_t b) { return (a+b-1)/b; }
146138
inline __both__ uint64_t divRoundUp(uint64_t a, uint64_t b) { return (a+b-1)/b; }
147-
139+
148140
#ifdef __CUDACC__
149141
using ::sin; // this is the double version
150142
// inline __both__ float sin(float f) { return ::sinf(f); }
@@ -174,7 +166,7 @@ namespace gdt {
174166
#else
175167
# define osp_snprintf snprintf
176168
#endif
177-
169+
178170
/*! added pretty-print function for large numbers, printing 10000000 as "10M" instead */
179171
inline std::string prettyDouble(const double val) {
180172
const double absVal = abs(val);
@@ -195,7 +187,7 @@ namespace gdt {
195187

196188
return result;
197189
}
198-
190+
199191

200192

201193
inline std::string prettyNumber(const size_t s)
@@ -214,7 +206,7 @@ namespace gdt {
214206
}
215207
return buf;
216208
}
217-
209+
218210
inline double getCurrentTime()
219211
{
220212
#ifdef _WIN32

crates/optix/examples/ex02_pipeline/device/src/lib.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
#![cfg_attr(
2-
target_os = "cuda",
3-
no_std,
4-
feature(register_attr),
5-
register_attr(nvvm_internal)
6-
)]
71
// #![deny(warnings)]
82
#![allow(clippy::missing_safety_doc)]
93

104
use cuda_std::*;
115
use cust_core::DeviceCopy;
12-
136
use optix_device as optix;
147

158
extern crate alloc;
@@ -54,7 +47,7 @@ pub unsafe fn __raygen__renderFrame() {
5447
if idx[0] == 3 && idx[1] == 4 {
5548
vprintf(
5649
c"Hello from Rust kernel!\n".as_ptr().cast(),
57-
std::ptr::null::<core::ffi::c_void>(),
50+
core::ptr::null::<core::ffi::c_void>(),
5851
);
5952

6053
#[repr(C)]
@@ -63,7 +56,7 @@ pub unsafe fn __raygen__renderFrame() {
6356
vprintf(
6457
c"frame id is %d\n".as_ptr().cast(),
6558
&PrintArgs(core::ptr::read_volatile(&PARAMS.frame_id)) as *const PrintArgs
66-
as *const std::ffi::c_void,
59+
as *const core::ffi::c_void,
6760
);
6861
}
6962
}

crates/optix/examples/ex02_pipeline/src/renderer.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use anyhow::{Context, Result};
2-
use cust::context::{Context as CuContext, ContextFlags};
2+
use cust::context::Context as CuContext;
33
use cust::device::{Device, DeviceAttribute};
44
use cust::memory::{CopyDestination, DeviceBox, DeviceBuffer, DevicePointer, DeviceVariable};
55
use cust::stream::{Stream, StreamFlags};
@@ -40,8 +40,7 @@ impl Renderer {
4040
let srf_align = device.get_attribute(DeviceAttribute::SurfaceAlignment)?;
4141
println!("tex align: {}\nsrf align: {}", tex_align, srf_align);
4242

43-
let cuda_context =
44-
CuContext::create_and_push(ContextFlags::SCHED_AUTO | ContextFlags::MAP_HOST, device)?;
43+
let cuda_context = CuContext::new(device)?;
4544
let stream = Stream::new(StreamFlags::DEFAULT, None)?;
4645

4746
let mut ctx = DeviceContext::new(&cuda_context, false)?;
@@ -149,7 +148,7 @@ impl Renderer {
149148
let launch_params = DeviceVariable::new(LaunchParams {
150149
frame_id: 17,
151150
fb_size: [width as u32, height as u32],
152-
color_buffer: color_buffer.as_device_ptr(),
151+
color_buffer: color_buffer.as_device_ptr().as_raw(),
153152
})?;
154153

155154
Ok(Renderer {
@@ -174,7 +173,7 @@ impl Renderer {
174173
self.color_buffer = unsafe { DeviceBuffer::uninitialized(width * height)? };
175174
self.launch_params.fb_size[0] = width as u32;
176175
self.launch_params.fb_size[1] = height as u32;
177-
self.launch_params.color_buffer = self.color_buffer.as_device_ptr();
176+
self.launch_params.color_buffer = self.color_buffer.as_device_ptr().as_raw();
178177
Ok(())
179178
}
180179

crates/optix/examples/ex04_mesh/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ anyhow = "1.0.44"
1212
glfw = "0.42.0"
1313
gl = "0.14.0"
1414
num-traits = "0.2.14"
15-
glam = { version = "0.20", features=["cuda"] }
15+
glam = { version = "0.29.2", features=["cuda"] }
1616

1717
[build-dependencies]
1818
find_cuda_helper = { version = "0.2", path = "../../../find_cuda_helper" }

crates/optix/examples/rust/ex04_mesh_gpu/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![cfg_attr(target_os = "cuda", no_std, register_attr(nvvm_internal))]
21
#![allow(non_snake_case, clippy::missing_safety_doc)]
32

43
use cuda_std::kernel;
@@ -76,7 +75,7 @@ pub unsafe fn __miss__radiance() {
7675
}
7776

7877
extern "C" {
79-
#[cfg_attr(target_os = "cuda", nvvm_internal(addrspace(4)))]
78+
#[cfg_attr(target_os = "cuda", nvvm_internal::addrspace(4))]
8079
static PARAMS: LaunchParams;
8180
}
8281

crates/optix/src/acceleration.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ pub struct InstancePointerArray<'i> {
16871687
}
16881688

16891689
impl<'i> InstancePointerArray<'i> {
1690-
pub fn new(instances: &'i DeviceSlice<CUdeviceptr>) -> InstancePointerArray {
1690+
pub fn new(instances: &'i DeviceSlice<CUdeviceptr>) -> InstancePointerArray<'i> {
16911691
InstancePointerArray { instances }
16921692
}
16931693
}

crates/optix_device/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg_attr(target_os = "cuda", feature(asm_experimental_arch))]
12
#[cfg(target_os = "cuda")]
23
use core::arch::asm;
34

0 commit comments

Comments
 (0)