Skip to content

Fix optix examples #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 16, 2025
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
20 changes: 6 additions & 14 deletions crates/optix/examples/common/gdt/gdt/gdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
#define GDT_TERMINAL_RESET "\033[0m"
#define GDT_TERMINAL_DEFAULT GDT_TERMINAL_RESET
#define GDT_TERMINAL_BOLD "\033[1;1m"




Expand All @@ -118,15 +118,7 @@ namespace gdt {
#ifdef __CUDACC__
using ::min;
using ::max;
// inline __both__ float abs(float f) { return fabsf(f); }
// inline __both__ double abs(double f) { return fabs(f); }
using std::abs;
// inline __both__ float sin(float f) { return ::sinf(f); }
// inline __both__ double sin(double f) { return ::sin(f); }
// inline __both__ float cos(float f) { return ::cosf(f); }
// inline __both__ double cos(double f) { return ::cos(f); }

using ::saturate;
#else
using std::min;
using std::max;
Expand All @@ -139,12 +131,12 @@ namespace gdt {
// inline __both__ double abs(double f) { return fabs(f); }
inline __both__ float rcp(float f) { return 1.f/f; }
inline __both__ double rcp(double d) { return 1./d; }

inline __both__ int32_t divRoundUp(int32_t a, int32_t b) { return (a+b-1)/b; }
inline __both__ uint32_t divRoundUp(uint32_t a, uint32_t b) { return (a+b-1)/b; }
inline __both__ int64_t divRoundUp(int64_t a, int64_t b) { return (a+b-1)/b; }
inline __both__ uint64_t divRoundUp(uint64_t a, uint64_t b) { return (a+b-1)/b; }

#ifdef __CUDACC__
using ::sin; // this is the double version
// inline __both__ float sin(float f) { return ::sinf(f); }
Expand Down Expand Up @@ -174,7 +166,7 @@ namespace gdt {
#else
# define osp_snprintf snprintf
#endif

/*! added pretty-print function for large numbers, printing 10000000 as "10M" instead */
inline std::string prettyDouble(const double val) {
const double absVal = abs(val);
Expand All @@ -195,7 +187,7 @@ namespace gdt {

return result;
}



inline std::string prettyNumber(const size_t s)
Expand All @@ -214,7 +206,7 @@ namespace gdt {
}
return buf;
}

inline double getCurrentTime()
{
#ifdef _WIN32
Expand Down
11 changes: 2 additions & 9 deletions crates/optix/examples/ex02_pipeline/device/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#![cfg_attr(
target_os = "cuda",
no_std,
feature(register_attr),
register_attr(nvvm_internal)
)]
// #![deny(warnings)]
#![allow(clippy::missing_safety_doc)]

use cuda_std::*;
use cust_core::DeviceCopy;

use optix_device as optix;

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

#[repr(C)]
Expand All @@ -63,7 +56,7 @@ pub unsafe fn __raygen__renderFrame() {
vprintf(
c"frame id is %d\n".as_ptr().cast(),
&PrintArgs(core::ptr::read_volatile(&PARAMS.frame_id)) as *const PrintArgs
as *const std::ffi::c_void,
as *const core::ffi::c_void,
);
}
}
Expand Down
9 changes: 4 additions & 5 deletions crates/optix/examples/ex02_pipeline/src/renderer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{Context, Result};
use cust::context::{Context as CuContext, ContextFlags};
use cust::context::Context as CuContext;
use cust::device::{Device, DeviceAttribute};
use cust::memory::{CopyDestination, DeviceBox, DeviceBuffer, DevicePointer, DeviceVariable};
use cust::stream::{Stream, StreamFlags};
Expand Down Expand Up @@ -40,8 +40,7 @@ impl Renderer {
let srf_align = device.get_attribute(DeviceAttribute::SurfaceAlignment)?;
println!("tex align: {}\nsrf align: {}", tex_align, srf_align);

let cuda_context =
CuContext::create_and_push(ContextFlags::SCHED_AUTO | ContextFlags::MAP_HOST, device)?;
let cuda_context = CuContext::new(device)?;
let stream = Stream::new(StreamFlags::DEFAULT, None)?;

let mut ctx = DeviceContext::new(&cuda_context, false)?;
Expand Down Expand Up @@ -149,7 +148,7 @@ impl Renderer {
let launch_params = DeviceVariable::new(LaunchParams {
frame_id: 17,
fb_size: [width as u32, height as u32],
color_buffer: color_buffer.as_device_ptr(),
color_buffer: color_buffer.as_device_ptr().as_raw(),
})?;

Ok(Renderer {
Expand All @@ -174,7 +173,7 @@ impl Renderer {
self.color_buffer = unsafe { DeviceBuffer::uninitialized(width * height)? };
self.launch_params.fb_size[0] = width as u32;
self.launch_params.fb_size[1] = height as u32;
self.launch_params.color_buffer = self.color_buffer.as_device_ptr();
self.launch_params.color_buffer = self.color_buffer.as_device_ptr().as_raw();
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion crates/optix/examples/ex04_mesh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyhow = "1.0.44"
glfw = "0.42.0"
gl = "0.14.0"
num-traits = "0.2.14"
glam = { version = "0.20", features=["cuda"] }
glam = { version = "0.29.2", features=["cuda"] }

[build-dependencies]
find_cuda_helper = { version = "0.2", path = "../../../find_cuda_helper" }
Expand Down
3 changes: 1 addition & 2 deletions crates/optix/examples/rust/ex04_mesh_gpu/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![cfg_attr(target_os = "cuda", no_std, register_attr(nvvm_internal))]
#![allow(non_snake_case, clippy::missing_safety_doc)]

use cuda_std::kernel;
Expand Down Expand Up @@ -76,7 +75,7 @@ pub unsafe fn __miss__radiance() {
}

extern "C" {
#[cfg_attr(target_os = "cuda", nvvm_internal(addrspace(4)))]
#[cfg_attr(target_os = "cuda", nvvm_internal::addrspace(4))]
static PARAMS: LaunchParams;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/optix/src/acceleration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ pub struct InstancePointerArray<'i> {
}

impl<'i> InstancePointerArray<'i> {
pub fn new(instances: &'i DeviceSlice<CUdeviceptr>) -> InstancePointerArray {
pub fn new(instances: &'i DeviceSlice<CUdeviceptr>) -> InstancePointerArray<'i> {
InstancePointerArray { instances }
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/optix_device/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(target_os = "cuda", feature(asm_experimental_arch))]
#[cfg(target_os = "cuda")]
use core::arch::asm;

Expand Down
Loading