Skip to content

Try switching from rustacuda to cust #23

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

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/rustdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
--enable-index-page \
--extern-html-root-url const_type_layout=https://docs.rs/const-type-layout/0.3.2/ \
--extern-html-root-url final=https://docs.rs/final/0.1.1/ \
--extern-html-root-url rustacuda=https://docs.rs/rustacuda/0.1.3/ \
--extern-html-root-url rustacuda_core=https://docs.rs/rustacuda_core/0.1.2/ \
--extern-html-root-url cust=https://docs.rs/cust/0.3.2/ \
--extern-html-root-url cust_core=https://docs.rs/cust_core/0.1/ \
-Zunstable-options \
" cargo doc \
--all-features \
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ edition = "2021"
authors = ["Juniper Tyree <[email protected]>"]
repository = "https://github.com/juntyr/rust-cuda"
license = "MIT OR Apache-2.0"
rust-version = "1.81" # nightly
rust-version = "1.84" # nightly

[workspace.dependencies]
# workspace-internal crates
Expand All @@ -24,12 +24,12 @@ rust-cuda-derive = { version = "0.1", path = "rust-cuda-derive", default-feature
rust-cuda-kernel = { version = "0.1", path = "rust-cuda-kernel", default-features = false }

# third-party dependencies with unpublished patches
rustacuda = { git = "https://github.com/juntyr/RustaCUDA", rev = "c6ea7cc", default-features = false }
rustacuda_core = { git = "https://github.com/juntyr/RustaCUDA", rev = "c6ea7cc", default-features = false }
cust = { git = "https://github.com/juntyr/Rust-GPU-CUDA.git", rev = "5365c14", version = "0.3.2", default-features = false }
cust_core = { git = "https://github.com/juntyr/Rust-GPU-CUDA.git", rev = "5365c14", version = "0.1", default-features = false }

# crates.io third-party dependencies
cargo_metadata = { version = "0.19", default-features = false }
cargo-util = { version = "=0.2.16", default-features = false } # TODO: keep in sync with toolchain
cargo-util = { version = "=0.2.17", default-features = false } # TODO: keep in sync with toolchain
colored = { version = "3.0", default-features = false }
const-type-layout = { version = "0.3.2", default-features = false }
final = { version = "0.1.1", default-features = false }
Expand Down Expand Up @@ -92,16 +92,16 @@ default = []
derive = ["dep:rust-cuda-derive"]
device = []
final = ["dep:final"]
host = ["dep:rustacuda", "dep:regex", "dep:oneshot", "dep:safer_owning_ref"]
host = ["dep:cust", "dep:regex", "dep:oneshot", "dep:safer_owning_ref"]
kernel = ["dep:rust-cuda-kernel"]

[dependencies]
const-type-layout = { workspace = true, features = ["derive"] }
cust = { workspace = true, optional = true }
cust_core = { workspace = true }
final = { workspace = true, optional = true }
oneshot = { workspace = true, features = ["std", "async"], optional = true }
regex = { workspace = true, optional = true }
rustacuda = { workspace = true, optional = true }
rustacuda_core = { workspace = true }
rust-cuda-derive = { workspace = true, optional = true }
rust-cuda-kernel = { workspace = true, optional = true }
safer_owning_ref = { workspace = true, optional = true }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[CI Status]: https://img.shields.io/github/actions/workflow/status/juntyr/rust-cuda/ci.yml?branch=main
[workflow]: https://github.com/juntyr/rust-cuda/actions/workflows/ci.yml?query=branch%3Amain

[MSRV]: https://img.shields.io/badge/MSRV-1.81.0--nightly-orange
[MSRV]: https://img.shields.io/badge/MSRV-1.84.0--nightly-orange
[repo]: https://github.com/juntyr/rust-cuda

[Rust Doc]: https://img.shields.io/badge/docs-main-blue
Expand Down
20 changes: 10 additions & 10 deletions examples/lifetime/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

use lifetime::{kernel, link};

fn main() -> rust_cuda::deps::rustacuda::error::CudaResult<()> {
fn main() -> rust_cuda::deps::cust::error::CudaResult<()> {
// Link the lifetime-only-generic CUDA kernel
struct KernelPtx<'a, 'b>(core::marker::PhantomData<(&'a (), &'b ())>);
link! { impl kernel<'a, 'b> for KernelPtx }

// Initialize the CUDA API
rust_cuda::deps::rustacuda::init(rust_cuda::deps::rustacuda::CudaFlags::empty())?;
rust_cuda::deps::cust::init(rust_cuda::deps::cust::CudaFlags::empty())?;

// Get the first CUDA GPU device
let device = rust_cuda::deps::rustacuda::device::Device::get_device(0)?;
let device = rust_cuda::deps::cust::device::Device::get_device(0)?;

// Create a CUDA context associated to this device
let _context = rust_cuda::host::CudaDropWrapper::from(
rust_cuda::deps::rustacuda::context::Context::create_and_push(
rust_cuda::deps::rustacuda::context::ContextFlags::MAP_HOST
| rust_cuda::deps::rustacuda::context::ContextFlags::SCHED_AUTO,
rust_cuda::deps::cust::context::legacy::Context::create_and_push(
rust_cuda::deps::cust::context::legacy::ContextFlags::MAP_HOST
| rust_cuda::deps::cust::context::legacy::ContextFlags::SCHED_AUTO,
device,
)?,
);

// Create a new CUDA stream to submit kernels to
let mut stream =
rust_cuda::host::CudaDropWrapper::from(rust_cuda::deps::rustacuda::stream::Stream::new(
rust_cuda::deps::rustacuda::stream::StreamFlags::NON_BLOCKING,
rust_cuda::host::CudaDropWrapper::from(rust_cuda::deps::cust::stream::Stream::new(
rust_cuda::deps::cust::stream::StreamFlags::NON_BLOCKING,
None,
)?);

Expand All @@ -34,8 +34,8 @@ fn main() -> rust_cuda::deps::rustacuda::error::CudaResult<()> {
// Create a new instance of the CUDA kernel and prepare the launch config
let mut kernel = rust_cuda::kernel::TypedPtxKernel::<kernel>::new::<KernelPtx>(None);
let config = rust_cuda::kernel::LaunchConfig {
grid: rust_cuda::deps::rustacuda::function::GridSize::x(1),
block: rust_cuda::deps::rustacuda::function::BlockSize::x(4),
grid: rust_cuda::deps::cust::function::GridSize::x(1),
block: rust_cuda::deps::cust::function::BlockSize::x(4),
ptx_jit: false,
};

Expand Down
20 changes: 10 additions & 10 deletions examples/print/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@

use print::{kernel, link, Action};

fn main() -> rust_cuda::deps::rustacuda::error::CudaResult<()> {
fn main() -> rust_cuda::deps::cust::error::CudaResult<()> {
// Link the non-generic CUDA kernel
struct KernelPtx;
link! { impl kernel for KernelPtx }

// Initialize the CUDA API
rust_cuda::deps::rustacuda::init(rust_cuda::deps::rustacuda::CudaFlags::empty())?;
rust_cuda::deps::cust::init(rust_cuda::deps::cust::CudaFlags::empty())?;

// Get the first CUDA GPU device
let device = rust_cuda::deps::rustacuda::device::Device::get_device(0)?;
let device = rust_cuda::deps::cust::device::Device::get_device(0)?;

// Create a CUDA context associated to this device
let _context = rust_cuda::host::CudaDropWrapper::from(
rust_cuda::deps::rustacuda::context::Context::create_and_push(
rust_cuda::deps::rustacuda::context::ContextFlags::MAP_HOST
| rust_cuda::deps::rustacuda::context::ContextFlags::SCHED_AUTO,
rust_cuda::deps::cust::context::legacy::Context::create_and_push(
rust_cuda::deps::cust::context::legacy::ContextFlags::MAP_HOST
| rust_cuda::deps::cust::context::legacy::ContextFlags::SCHED_AUTO,
device,
)?,
);

// Create a new CUDA stream to submit kernels to
let mut stream =
rust_cuda::host::CudaDropWrapper::from(rust_cuda::deps::rustacuda::stream::Stream::new(
rust_cuda::deps::rustacuda::stream::StreamFlags::NON_BLOCKING,
rust_cuda::host::CudaDropWrapper::from(rust_cuda::deps::cust::stream::Stream::new(
rust_cuda::deps::cust::stream::StreamFlags::NON_BLOCKING,
None,
)?);

// Create a new instance of the CUDA kernel and prepare the launch config
let mut kernel = rust_cuda::kernel::TypedPtxKernel::<kernel>::new::<KernelPtx>(None);
let config = rust_cuda::kernel::LaunchConfig {
grid: rust_cuda::deps::rustacuda::function::GridSize::x(1),
block: rust_cuda::deps::rustacuda::function::BlockSize::x(4),
grid: rust_cuda::deps::cust::function::GridSize::x(1),
block: rust_cuda::deps::cust::function::BlockSize::x(4),
ptx_jit: false,
};

Expand Down
2 changes: 1 addition & 1 deletion rust-cuda-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! [CI Status]: https://img.shields.io/github/actions/workflow/status/juntyr/rust-cuda/ci.yml?branch=main
//! [workflow]: https://github.com/juntyr/rust-cuda/actions/workflows/ci.yml?query=branch%3Amain
//!
//! [MSRV]: https://img.shields.io/badge/MSRV-1.81.0--nightly-orange
//! [MSRV]: https://img.shields.io/badge/MSRV-1.84.0--nightly-orange
//! [repo]: https://github.com/juntyr/rust-cuda
//!
//! [Rust Doc]: https://img.shields.io/badge/docs-main-blue
Expand Down
1 change: 0 additions & 1 deletion rust-cuda-derive/src/rust_to_cuda/field_ty.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use syn::{parse_quote, spanned::Spanned};

#[expect(clippy::module_name_repetitions)]
pub enum CudaReprFieldTy {
SafeDeviceCopy,
RustToCuda {
Expand Down
8 changes: 4 additions & 4 deletions rust-cuda-derive/src/rust_to_cuda/impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn rust_to_cuda_trait(
unsafe fn borrow<CudaAllocType: #crate_path::alloc::CudaAlloc>(
&self,
alloc: CudaAllocType,
) -> #crate_path::deps::rustacuda::error::CudaResult<(
) -> #crate_path::deps::cust::error::CudaResult<(
#crate_path::utils::ffi::DeviceAccessible<Self::CudaRepresentation>,
#crate_path::alloc::CombinedCudaAlloc<Self::CudaAllocation, CudaAllocType>
)> {
Expand All @@ -107,7 +107,7 @@ pub fn rust_to_cuda_trait(
alloc: #crate_path::alloc::CombinedCudaAlloc<
Self::CudaAllocation, CudaAllocType
>,
) -> #crate_path::deps::rustacuda::error::CudaResult<CudaAllocType> {
) -> #crate_path::deps::cust::error::CudaResult<CudaAllocType> {
let (alloc_front, alloc_tail) = alloc.split();

#(#r2c_field_destructors)*
Expand Down Expand Up @@ -192,7 +192,7 @@ pub fn rust_to_cuda_async_trait(
&self,
alloc: CudaAllocType,
stream: #crate_path::host::Stream<'stream>,
) -> #crate_path::deps::rustacuda::error::CudaResult<(
) -> #crate_path::deps::cust::error::CudaResult<(
#crate_path::utils::r#async::Async<
'_, 'stream,
#crate_path::utils::ffi::DeviceAccessible<Self::CudaRepresentation>,
Expand Down Expand Up @@ -220,7 +220,7 @@ pub fn rust_to_cuda_async_trait(
Self::CudaAllocationAsync, CudaAllocType
>,
stream: #crate_path::host::Stream<'stream>,
) -> #crate_path::deps::rustacuda::error::CudaResult<(
) -> #crate_path::deps::cust::error::CudaResult<(
#crate_path::utils::r#async::Async<
'a, 'stream,
#crate_path::deps::owning_ref::BoxRefMut<'a, CudaRestoreOwner, Self>,
Expand Down
2 changes: 1 addition & 1 deletion rust-cuda-derive/src/rust_to_cuda/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn get_cuda_repr_ident(rust_repr_ident: &proc_macro2::Ident) -> proc_macro2::Ide
format_ident!("{}CudaRepresentation", rust_repr_ident)
}

#[expect(clippy::module_name_repetitions, clippy::too_many_lines)]
#[expect(clippy::too_many_lines)]
pub fn impl_rust_to_cuda(ast: &syn::DeriveInput) -> proc_macro::TokenStream {
let (mut struct_fields_cuda, struct_semi_cuda) = if let syn::Data::Struct(s) = &ast.data {
(s.fields.clone(), s.semi_token)
Expand Down
2 changes: 1 addition & 1 deletion rust-cuda-kernel/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! [CI Status]: https://img.shields.io/github/actions/workflow/status/juntyr/rust-cuda/ci.yml?branch=main
//! [workflow]: https://github.com/juntyr/rust-cuda/actions/workflows/ci.yml?query=branch%3Amain
//!
//! [MSRV]: https://img.shields.io/badge/MSRV-1.81.0--nightly-orange
//! [MSRV]: https://img.shields.io/badge/MSRV-1.84.0--nightly-orange
//! [repo]: https://github.com/juntyr/rust-cuda
//!
//! [Rust Doc]: https://img.shields.io/badge/docs-main-blue
Expand Down
24 changes: 12 additions & 12 deletions rust-cuda-kernel/src/kernel/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fn check_kernel_ptx_and_report(
Ok(Some(binary)) => {
if ptx_lint_levels
.get(&PtxLint::DumpAssembly)
.map_or(false, |level| *level > LintLevel::Allow)
.is_some_and(|level| *level > LintLevel::Allow)
{
const HEX: [char; 16] = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f',
Expand All @@ -336,7 +336,7 @@ fn check_kernel_ptx_and_report(

if ptx_lint_levels
.get(&PtxLint::DumpAssembly)
.map_or(false, |level| *level > LintLevel::Warn)
.is_some_and(|level| *level > LintLevel::Warn)
{
emit_call_site_error!(
"{} compiled binary:\n{}\n\n{}",
Expand Down Expand Up @@ -459,31 +459,31 @@ fn check_kernel_ptx(

if ptx_lint_levels
.get(&PtxLint::Verbose)
.map_or(false, |level| *level > LintLevel::Warn)
.is_some_and(|level| *level > LintLevel::Warn)
{
options.push(c"--verbose");
}
if ptx_lint_levels
.get(&PtxLint::DoublePrecisionUse)
.map_or(false, |level| *level > LintLevel::Warn)
.is_some_and(|level| *level > LintLevel::Warn)
{
options.push(c"--warn-on-double-precision-use");
}
if ptx_lint_levels
.get(&PtxLint::LocalMemoryUse)
.map_or(false, |level| *level > LintLevel::Warn)
.is_some_and(|level| *level > LintLevel::Warn)
{
options.push(c"--warn-on-local-memory-usage");
}
if ptx_lint_levels
.get(&PtxLint::RegisterSpills)
.map_or(false, |level| *level > LintLevel::Warn)
.is_some_and(|level| *level > LintLevel::Warn)
{
options.push(c"--warn-on-spills");
}
if ptx_lint_levels
.get(&PtxLint::DynamicStackSize)
.map_or(true, |level| *level <= LintLevel::Warn)
.is_none_or(|level| *level <= LintLevel::Warn)
{
options.push(c"--suppress-stack-size-warning");
}
Expand All @@ -505,31 +505,31 @@ fn check_kernel_ptx(

if ptx_lint_levels
.get(&PtxLint::Verbose)
.map_or(false, |level| *level > LintLevel::Allow)
.is_some_and(|level| *level > LintLevel::Allow)
{
options.push(c"--verbose");
}
if ptx_lint_levels
.get(&PtxLint::DoublePrecisionUse)
.map_or(false, |level| *level > LintLevel::Allow)
.is_some_and(|level| *level > LintLevel::Allow)
{
options.push(c"--warn-on-double-precision-use");
}
if ptx_lint_levels
.get(&PtxLint::LocalMemoryUse)
.map_or(false, |level| *level > LintLevel::Allow)
.is_some_and(|level| *level > LintLevel::Allow)
{
options.push(c"--warn-on-local-memory-usage");
}
if ptx_lint_levels
.get(&PtxLint::RegisterSpills)
.map_or(false, |level| *level > LintLevel::Allow)
.is_some_and(|level| *level > LintLevel::Allow)
{
options.push(c"--warn-on-spills");
}
if ptx_lint_levels
.get(&PtxLint::DynamicStackSize)
.map_or(true, |level| *level < LintLevel::Warn)
.is_none_or(|level| *level < LintLevel::Warn)
{
options.push(c"--suppress-stack-size-warning");
}
Expand Down
2 changes: 1 addition & 1 deletion rust-cuda-kernel/src/kernel/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub trait NestedMetaParser {
) -> syn::Result<()>;
}

impl<'a> NestedMetaParser for syn::meta::ParseNestedMeta<'a> {
impl NestedMetaParser for syn::meta::ParseNestedMeta<'_> {
fn path(&self) -> &syn::Path {
&self.path
}
Expand Down
2 changes: 1 addition & 1 deletion rust-cuda-kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! [CI Status]: https://img.shields.io/github/actions/workflow/status/juntyr/rust-cuda/ci.yml?branch=main
//! [workflow]: https://github.com/juntyr/rust-cuda/actions/workflows/ci.yml?query=branch%3Amain
//!
//! [MSRV]: https://img.shields.io/badge/MSRV-1.81.0--nightly-orange
//! [MSRV]: https://img.shields.io/badge/MSRV-1.84.0--nightly-orange
//! [repo]: https://github.com/juntyr/rust-cuda
//!
//! [Rust Doc]: https://img.shields.io/badge/docs-main-blue
Expand Down
6 changes: 3 additions & 3 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
# Pin to final 1.81.0 nightly
channel = "nightly-2024-07-21"
# Pin to final 1.84.0 nightly
channel = "nightly-2024-11-22"
components = [ "cargo", "rustfmt", "clippy", "llvm-bitcode-linker", "llvm-tools" ]
targets = [ "x86_64-unknown-linux-gnu", "nvptx64-nvidia-cuda" ]
targets = [ "nvptx64-nvidia-cuda" ]
4 changes: 2 additions & 2 deletions src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ pub extern crate const_type_layout;
pub extern crate owning_ref;

#[cfg(feature = "host")]
pub extern crate rustacuda;
pub extern crate cust;

pub extern crate rustacuda_core;
pub extern crate cust_core;
Loading
Loading