use crate::error::{CudaError, CudaResult};
use crate::loader::try_driver;
pub fn profiler_start() -> CudaResult<()> {
let api = try_driver()?;
let f = api.cu_profiler_start.ok_or(CudaError::NotSupported)?;
crate::cuda_call!(f())
}
pub fn profiler_stop() -> CudaResult<()> {
let api = try_driver()?;
let f = api.cu_profiler_stop.ok_or(CudaError::NotSupported)?;
crate::cuda_call!(f())
}
pub struct ProfilerGuard {
_private: (),
}
impl ProfilerGuard {
pub fn start() -> CudaResult<Self> {
profiler_start()?;
Ok(Self { _private: () })
}
}
impl Drop for ProfilerGuard {
fn drop(&mut self) {
let _ = profiler_stop();
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn profiler_start_returns_error_without_gpu() {
let result = profiler_start();
let _ = result;
}
#[test]
fn profiler_stop_returns_error_without_gpu() {
let result = profiler_stop();
let _ = result;
}
#[test]
fn profiler_guard_does_not_panic_without_gpu() {
let result = ProfilerGuard::start();
let _ = result;
}
}