Skip to content
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

Added result and safe functionality to support the cuFuncSetAttribute function. #199

Merged
merged 2 commits into from
Jan 31, 2024
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
22 changes: 22 additions & 0 deletions src/driver/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,28 @@ pub mod device {
}
}

pub mod function {
use super::sys::{self, CUfunction_attribute_enum};

/// Sets the specific attribute of a cuda function.
///
/// See [cuda docs](https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__EXECUTION.html#group__CUDART__EXECUTION_1g317e77d2657abf915fd9ed03e75f3eb0)
///
/// # Safety
/// Function must exist.
pub unsafe fn set_function_attribute(
f: sys::CUfunction,
attribute: CUfunction_attribute_enum,
value: i32,
) -> Result<(), super::DriverError> {
unsafe {
sys::cuFuncSetAttribute(f, attribute, value).result()?;
}

Ok(())
}
}

pub mod occupancy {

use core::{
Expand Down
18 changes: 17 additions & 1 deletion src/driver/safe/core.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::driver::{result, sys};
use crate::driver::{
result,
sys::{self, CUfunction_attribute_enum},
};

use super::{alloc::DeviceRepr, device_ptr::DeviceSlice};

Expand Down Expand Up @@ -387,6 +390,19 @@ impl CudaFunction {

Ok(cluster_size as u32)
}

/// Set the value of a specific attribute of this [CudaFunction].
pub fn set_attribute(
&self,
attribute: CUfunction_attribute_enum,
value: i32,
) -> Result<(), result::DriverError> {
unsafe {
result::function::set_function_attribute(self.cu_function, attribute, value)?;
}

Ok(())
}
}

unsafe impl Send for CudaFunction {}
Expand Down
Loading