singe-cupti 0.1.0-alpha.5

Safe Rust wrappers for NVIDIA CUPTI profiling and callback APIs.
Documentation
use singe_cuda::stream::Stream;
use singe_cupti_sys as sys;

use crate::{context::Context, error::Result, try_ffi, types::StreamId};

fn raw_get_stream_id(
    context: sys::CUcontext,
    stream: sys::CUstream,
    stream_id: *mut u32,
) -> Result<()> {
    unsafe {
        try_ffi!(sys::cuptiGetStreamId(context, stream, stream_id))?;
    }
    Ok(())
}

fn raw_get_stream_id_ex(
    context: sys::CUcontext,
    stream: sys::CUstream,
    per_thread_stream: u8,
    stream_id: *mut u32,
) -> Result<()> {
    unsafe {
        try_ffi!(sys::cuptiGetStreamIdEx(
            context,
            stream,
            per_thread_stream,
            stream_id,
        ))?;
    }
    Ok(())
}

pub fn stream_id(context: &Context, stream: &Stream) -> Result<StreamId> {
    let mut stream_id = 0;
    raw_get_stream_id(
        context.as_raw(),
        stream.as_raw() as sys::CUstream,
        &mut stream_id,
    )?;
    Ok(StreamId::from(u64::from(stream_id)))
}

pub fn stream_id_ex(
    context: &Context,
    stream: &Stream,
    per_thread_stream: bool,
) -> Result<StreamId> {
    let mut stream_id = 0;
    raw_get_stream_id_ex(
        context.as_raw(),
        stream.as_raw() as sys::CUstream,
        per_thread_stream as u8,
        &mut stream_id,
    )?;
    Ok(StreamId::from(u64::from(stream_id)))
}