mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-10-02 14:19:27 +00:00
Add a handful of missing functions
This commit is contained in:
parent
afb184e10e
commit
f3775ea857
6 changed files with 39 additions and 29 deletions
|
@ -494,6 +494,10 @@ pub(crate) fn primary_context_release(hip_dev: hipDevice_t) -> CUresult {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn primary_context_release_v2(hip_dev: hipDevice_t) -> CUresult {
|
||||
primary_context_release(hip_dev)
|
||||
}
|
||||
|
||||
pub(crate) fn primary_context_reset(hip_dev: hipDevice_t) -> CUresult {
|
||||
let (ctx, _) = get_primary_context(hip_dev)?;
|
||||
ctx.with_state_mut(|state| state.reset())?;
|
||||
|
|
|
@ -527,6 +527,14 @@ pub(crate) unsafe fn launch_kernel_ex(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) unsafe fn get_error_string(
|
||||
_error: cuda_types::cuda::CUresult,
|
||||
error_string: &mut *const ::core::ffi::c_char,
|
||||
) -> CUresult {
|
||||
*error_string = "\0".as_ptr().cast();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::i32;
|
||||
|
|
|
@ -55,12 +55,11 @@ pub(crate) unsafe fn load_data(
|
|||
_jit_options_values: Option<&mut *mut ::core::ffi::c_void>,
|
||||
_num_jit_options: ::core::ffi::c_uint,
|
||||
library_options: Option<&mut CUlibraryOption>,
|
||||
library_option_values: Option<&mut *mut ::core::ffi::c_void>,
|
||||
_library_option_values: Option<&mut *mut ::core::ffi::c_void>,
|
||||
num_library_options: ::core::ffi::c_uint,
|
||||
) -> CUresult {
|
||||
let global_state = driver::global_state()?;
|
||||
let options =
|
||||
LibraryOptions::load(library_options, library_option_values, num_library_options)?;
|
||||
let options = LibraryOptions::load(library_options, num_library_options)?;
|
||||
let library = Library {
|
||||
data: LibraryData::new(code as *mut c_void, options.preserve_binary)?,
|
||||
modules: vec![OnceLock::new(); global_state.devices.len()],
|
||||
|
@ -76,7 +75,6 @@ struct LibraryOptions {
|
|||
impl LibraryOptions {
|
||||
unsafe fn load(
|
||||
library_options: Option<&mut CUlibraryOption>,
|
||||
library_option_values: Option<&mut *mut ::core::ffi::c_void>,
|
||||
num_library_options: ::core::ffi::c_uint,
|
||||
) -> Result<Self, CUerror> {
|
||||
if num_library_options == 0 {
|
||||
|
@ -84,28 +82,17 @@ impl LibraryOptions {
|
|||
preserve_binary: false,
|
||||
});
|
||||
}
|
||||
let (library_options, library_option_values) =
|
||||
match (library_options, library_option_values) {
|
||||
(Some(library_options), Some(library_option_values)) => {
|
||||
let library_options =
|
||||
std::slice::from_raw_parts(library_options, num_library_options as usize);
|
||||
let library_option_values = std::slice::from_raw_parts(
|
||||
library_option_values,
|
||||
num_library_options as usize,
|
||||
);
|
||||
(library_options, library_option_values)
|
||||
}
|
||||
_ => return Err(CUerror::INVALID_VALUE),
|
||||
};
|
||||
let library_options = match library_options {
|
||||
Some(library_options) => {
|
||||
std::slice::from_raw_parts(library_options, num_library_options as usize)
|
||||
}
|
||||
_ => return Err(CUerror::INVALID_VALUE),
|
||||
};
|
||||
let mut preserve_binary = false;
|
||||
for (option, value) in library_options
|
||||
.iter()
|
||||
.copied()
|
||||
.zip(library_option_values.iter())
|
||||
{
|
||||
for option in library_options.iter().copied() {
|
||||
match option {
|
||||
CUlibraryOption::CU_LIBRARY_BINARY_IS_PRESERVED => {
|
||||
preserve_binary = *(value.cast::<bool>());
|
||||
preserve_binary = true;
|
||||
}
|
||||
_ => return Err(CUerror::NOT_SUPPORTED),
|
||||
}
|
||||
|
@ -156,10 +143,7 @@ mod tests {
|
|||
use crate::tests::CudaApi;
|
||||
use cuda_macros::test_cuda;
|
||||
use cuda_types::cuda::{CUlibraryOption, CUresult, CUresultConsts};
|
||||
use std::{
|
||||
ffi::{c_void, CStr},
|
||||
mem, ptr,
|
||||
};
|
||||
use std::{ffi::CStr, mem, ptr};
|
||||
|
||||
#[test_cuda]
|
||||
unsafe fn library_loads_without_context(api: impl CudaApi) {
|
||||
|
@ -191,7 +175,7 @@ mod tests {
|
|||
ptr::null_mut(),
|
||||
0,
|
||||
[CUlibraryOption::CU_LIBRARY_BINARY_IS_PRESERVED].as_mut_ptr(),
|
||||
[(&true as *const bool) as *mut c_void].as_mut_ptr(),
|
||||
ptr::null_mut(),
|
||||
1,
|
||||
);
|
||||
assert_eq!(
|
||||
|
|
|
@ -153,3 +153,11 @@ pub(crate) unsafe fn set_d8_async(
|
|||
) -> hipError_t {
|
||||
hipMemsetD8Async(dst_device, uc, n, stream)
|
||||
}
|
||||
|
||||
pub(crate) fn get_allocation_granularity(
|
||||
_granularity: &mut usize,
|
||||
_property: &cuda_types::cuda::CUmemAllocationProp,
|
||||
_option: cuda_types::cuda::CUmemAllocationGranularity_flags,
|
||||
) -> CUresult {
|
||||
CUresult::ERROR_NOT_SUPPORTED
|
||||
}
|
||||
|
|
|
@ -93,6 +93,7 @@ cuda_macros::cuda_function_declarations!(
|
|||
cuDeviceGetUuid_v2,
|
||||
cuDevicePrimaryCtxGetState,
|
||||
cuDevicePrimaryCtxRelease,
|
||||
cuDevicePrimaryCtxRelease_v2,
|
||||
cuDevicePrimaryCtxReset,
|
||||
cuDevicePrimaryCtxRetain,
|
||||
cuDeviceTotalMem_v2,
|
||||
|
@ -104,6 +105,7 @@ cuda_macros::cuda_function_declarations!(
|
|||
cuEventSynchronize,
|
||||
cuFuncGetAttribute,
|
||||
cuFuncSetAttribute,
|
||||
cuGetErrorString,
|
||||
cuGetExportTable,
|
||||
cuGetProcAddress,
|
||||
cuGetProcAddress_v2,
|
||||
|
@ -126,6 +128,7 @@ cuda_macros::cuda_function_declarations!(
|
|||
cuMemFreeHost,
|
||||
cuMemFree_v2,
|
||||
cuMemGetAddressRange_v2,
|
||||
cuMemGetAllocationGranularity,
|
||||
cuMemGetInfo_v2,
|
||||
cuMemHostAlloc,
|
||||
cuMemRetainAllocationHandle,
|
||||
|
|
|
@ -165,7 +165,10 @@ from_cuda_nop!(
|
|||
nvmlDevice_t,
|
||||
nvmlFieldValue_t,
|
||||
nvmlGpuFabricInfo_t,
|
||||
cublasLtHandle_t
|
||||
cublasLtHandle_t,
|
||||
CUmemAllocationGranularity_flags,
|
||||
CUmemAllocationProp,
|
||||
CUresult
|
||||
);
|
||||
from_cuda_transmute!(
|
||||
CUuuid => hipUUID,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue