Skip to content

Commit 58d2d10

Browse files
committed
Replace vek with glam.
This fixes #179.
1 parent 7eb199c commit 58d2d10

File tree

18 files changed

+65
-55
lines changed

18 files changed

+65
-55
lines changed

crates/cuda_std/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository = "https://github.com/Rust-GPU/Rust-CUDA"
88
readme = "../../README.md"
99

1010
[dependencies]
11+
glam = { version = ">=0.22", default-features = false, features = ["libm", "cuda", "bytemuck"] }
1112
vek = { version = "0.17.1", default-features = false, features = ["libm"] }
1213
cuda_std_macros = { version = "0.2", path = "../cuda_std_macros" }
1314
half = "2.4.1"

crates/cuda_std/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ mod float_ext;
4949
pub use cuda_std_macros::*;
5050
pub use float::GpuFloat;
5151
pub use float_ext::*;
52+
pub use glam;
5253
pub use half;
54+
#[deprecated(
55+
note = "The `vek` module is deprecated, use `glam` instead."
56+
)]
5357
pub use vek;
5458

5559
pub use half::{bf16, f16};

crates/cuda_std/src/rt/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,23 +152,23 @@ impl<'a> From<&'a GridSize> for GridSize {
152152
other.clone()
153153
}
154154
}
155-
impl From<vek::Vec2<u32>> for GridSize {
156-
fn from(vec: vek::Vec2<u32>) -> Self {
155+
impl From<glam::UVec2> for GridSize {
156+
fn from(vec: glam::UVec2) -> Self {
157157
GridSize::xy(vec.x, vec.y)
158158
}
159159
}
160-
impl From<vek::Vec3<u32>> for GridSize {
161-
fn from(vec: vek::Vec3<u32>) -> Self {
160+
impl From<glam::UVec3> for GridSize {
161+
fn from(vec: glam::UVec3) -> Self {
162162
GridSize::xyz(vec.x, vec.y, vec.z)
163163
}
164164
}
165-
impl From<vek::Vec2<usize>> for GridSize {
166-
fn from(vec: vek::Vec2<usize>) -> Self {
165+
impl From<glam::USizeVec2> for GridSize {
166+
fn from(vec: glam::USizeVec2) -> Self {
167167
GridSize::xy(vec.x as u32, vec.y as u32)
168168
}
169169
}
170-
impl From<vek::Vec3<usize>> for GridSize {
171-
fn from(vec: vek::Vec3<usize>) -> Self {
170+
impl From<glam::USizeVec3> for GridSize {
171+
fn from(vec: glam::USizeVec3) -> Self {
172172
GridSize::xyz(vec.x as u32, vec.y as u32, vec.z as u32)
173173
}
174174
}
@@ -228,23 +228,23 @@ impl<'a> From<&'a BlockSize> for BlockSize {
228228
other.clone()
229229
}
230230
}
231-
impl From<vek::Vec2<u32>> for BlockSize {
232-
fn from(vec: vek::Vec2<u32>) -> Self {
231+
impl From<glam::UVec2> for BlockSize {
232+
fn from(vec: glam::UVec2) -> Self {
233233
BlockSize::xy(vec.x, vec.y)
234234
}
235235
}
236-
impl From<vek::Vec3<u32>> for BlockSize {
237-
fn from(vec: vek::Vec3<u32>) -> Self {
236+
impl From<glam::UVec3> for BlockSize {
237+
fn from(vec: glam::UVec3) -> Self {
238238
BlockSize::xyz(vec.x, vec.y, vec.z)
239239
}
240240
}
241-
impl From<vek::Vec2<usize>> for BlockSize {
242-
fn from(vec: vek::Vec2<usize>) -> Self {
241+
impl From<glam::USizeVec2> for BlockSize {
242+
fn from(vec: glam::USizeVec2) -> Self {
243243
BlockSize::xy(vec.x as u32, vec.y as u32)
244244
}
245245
}
246-
impl From<vek::Vec3<usize>> for BlockSize {
247-
fn from(vec: vek::Vec3<usize>) -> Self {
246+
impl From<glam::USizeVec3> for BlockSize {
247+
fn from(vec: glam::USizeVec3) -> Self {
248248
BlockSize::xyz(vec.x as u32, vec.y as u32, vec.z as u32)
249249
}
250250
}

crates/cuda_std/src/thread.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// TODO: write some docs about the terms used in this module.
2020

2121
use cuda_std_macros::gpu_only;
22-
use vek::{Vec2, Vec3};
22+
use glam::{UVec2, UVec3};
2323

2424
// different calling conventions dont exist in nvptx, so we just use C as a placeholder.
2525
extern "C" {
@@ -152,7 +152,7 @@ pub fn grid_dim_z() -> u32 {
152152
/// Gets the 3d index of the thread currently executing the kernel.
153153
#[gpu_only]
154154
#[inline(always)]
155-
pub fn thread_idx() -> Vec3<u32> {
155+
pub fn thread_idx() -> UVec3 {
156156
unsafe {
157157
Vec3::new(
158158
__nvvm_thread_idx_x(),
@@ -165,7 +165,7 @@ pub fn thread_idx() -> Vec3<u32> {
165165
/// Gets the 3d index of the block that the thread currently executing the kernel is located in.
166166
#[gpu_only]
167167
#[inline(always)]
168-
pub fn block_idx() -> Vec3<u32> {
168+
pub fn block_idx() -> UVec3 {
169169
unsafe {
170170
Vec3::new(
171171
__nvvm_block_idx_x(),
@@ -179,7 +179,7 @@ pub fn block_idx() -> Vec3<u32> {
179179
/// how many threads exist in each thread block in every direction.
180180
#[gpu_only]
181181
#[inline(always)]
182-
pub fn block_dim() -> Vec3<u32> {
182+
pub fn block_dim() -> UVec3 {
183183
unsafe {
184184
Vec3::new(
185185
__nvvm_block_dim_x(),
@@ -193,7 +193,7 @@ pub fn block_dim() -> Vec3<u32> {
193193
/// how many thread blocks exist in each grid in every direction.
194194
#[gpu_only]
195195
#[inline(always)]
196-
pub fn grid_dim() -> Vec3<u32> {
196+
pub fn grid_dim() -> UVec3 {
197197
unsafe {
198198
Vec3::new(
199199
__nvvm_grid_dim_x(),
@@ -232,26 +232,26 @@ pub fn index_1d() -> u32 {
232232
}
233233

234234
#[inline(always)]
235-
pub fn index_2d() -> Vec2<u32> {
235+
pub fn index_2d() -> UVec2 {
236236
let i = thread_idx_x() + block_idx_x() * block_dim_x();
237237
let j = thread_idx_y() + block_idx_y() * block_dim_y();
238-
Vec2::new(i, j)
238+
UVec2::new(i, j)
239239
}
240240

241241
#[inline(always)]
242-
pub fn index_3d() -> Vec3<u32> {
242+
pub fn index_3d() -> UVec3 {
243243
let i = thread_idx_x() + block_idx_x() * block_dim_x();
244244
let j = thread_idx_y() + block_idx_y() * block_dim_y();
245245
let k = thread_idx_z() + block_idx_z() * block_dim_z();
246-
Vec3::new(i, j, k)
246+
UVec3::new(i, j, k)
247247
}
248248

249249
/// Whether this is the first thread (not the first thread to be executing). This function is guaranteed
250250
/// to only return true in a single thread that is invoking it. This is useful for only doing something
251251
/// once.
252252
#[inline(always)]
253253
pub fn first() -> bool {
254-
block_idx() == Vec3::zero() && thread_idx() == Vec3::zero()
254+
block_idx() == UVec3::ZERO && thread_idx() == UVec3::ZERO
255255
}
256256

257257
/// Gets the number of threads inside of a warp. Currently 32 threads on every GPU architecture.

crates/cust/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
- `cuda_std::vek` is now deprecated. Use `cuda_std::glam`.
78
- Add `memory::memcpy_dtoh` to allow copying from device to host.
89
- `DeviceSlice` is represented as a slice again, but as `[()]` instead of `[T]`.
910
- Reimplemented `Index` and `IndexMut` for `DeviceSlice` and removed `DeviceSlice::index`.

crates/optix_device/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
name = "optix_device"
33
version = "0.1.0"
44
edition = "2021"
5-
authors = ["Anders Langlands <[email protected]>", "Riccardo D'Ambrosio <[email protected]>"]
5+
authors = [
6+
"Anders Langlands <[email protected]>",
7+
"Riccardo D'Ambrosio <[email protected]>"
8+
]
69

710
[dependencies]
811
bitflags = "2.8"
912
cuda_std = { version = "0.2", path = "../cuda_std" }
10-
glam = { version = "0.29", features=["cuda", "libm"], default-features=false }
1113
paste = "1.0.15"
1214
seq-macro = "0.3.5"
1315
cust_core = { version = "0.1", path = "../cust_core" }
16+
17+
[target.'cfg(not(target_os = "cuda"))'.dependencies]
18+
glam = { version = "0.29", features = ["cuda"], default-features = false }

crates/optix_device/src/hit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(target_os = "cuda")]
22
use core::arch::asm;
3-
use cuda_std::gpu_only;
3+
use cuda_std::{gpu_only, glam};
44
use glam::Vec3;
55
/// The type of primitive that a ray hit.
66
#[repr(u32)]

crates/optix_device/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ pub mod trace;
1414
pub mod transform;
1515
pub mod util;
1616

17-
use cuda_std::*;
18-
pub use glam;
17+
use cuda_std::{glam, *};
1918
use glam::UVec3;
2019
pub use misc::*;
2120

crates/optix_device/src/ray.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::trace::*;
22
#[cfg(target_os = "cuda")]
33
use core::arch::asm;
4-
use cuda_std::gpu_only;
4+
use cuda_std::{glam, gpu_only};
55
use glam::Vec3;
66

77
/// Returns the ray origin that was passed into [`trace`] in world-space.

crates/optix_device/src/sys.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::trace::{RayFlags, TraversableHandle};
44
#[cfg(target_os = "cuda")]
55
use core::arch::asm;
6-
use cuda_std::gpu_only;
6+
use cuda_std::{glam, gpu_only};
77
use glam::Vec3;
88
use paste::paste;
99

0 commit comments

Comments
 (0)