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

Add NVIDIA Tools Extension wrapper #32

Open
wants to merge 1 commit into
base: master
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ members = [
"cuda-config",
"cuda-driver-sys",
"cuda-runtime-sys",
"nvtx-sys",
]
16 changes: 16 additions & 0 deletions bindgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -exu

bindgen \
--whitelist-type="^nvtx.*" \
--whitelist-var="^nvtx.*" \
--whitelist-function="^nvtx.*" \
--default-enum-style=rust \
--no-doc-comments \
--with-derive-default \
--with-derive-eq \
--with-derive-hash \
--with-derive-ord \
--size_t-is-usize \
"$CUDA_PATH/include/nvToolsExt.h" \
> src/nv_tools_ext.rs
20 changes: 20 additions & 0 deletions nvtx-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "nvtx-sys"
version = "0.3.0-alpha.0"
authors = ["Toshiki Teramura <[email protected]>", "Clemens Lutz <[email protected]>"]
edition = "2018"

build = "build.rs"
links = "nvToolsExt"

description = "Rust binding to NVIDIA Tools Extension Library"
documentation = "https://docs.rs/nvtx-sys/"
repository = "https://github.com/rust-cuda/cuda-sys"
keywords = ["GPGPU", "CUDA", "ffi"]
license = "MIT/Apache-2.0"
readme = "../README.md"
categories = []

[build-dependencies.cuda-config]
path = "../cuda-config"
version = "0.1.0"
16 changes: 16 additions & 0 deletions nvtx-sys/bindgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -exu

bindgen \
--whitelist-type="^nvtx.*" \
--whitelist-var="^nvtx.*" \
--whitelist-function="^nvtx.*" \
--default-enum-style=rust \
--no-doc-comments \
--with-derive-default \
--with-derive-eq \
--with-derive-hash \
--with-derive-ord \
--size_t-is-usize \
"$CUDA_PATH/include/nvToolsExt.h" \
> src/nv_tools_ext.rs
18 changes: 18 additions & 0 deletions nvtx-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use cuda_config::*;

fn main() {
if cfg!(target_os = "windows") {
println!(
"cargo:rustc-link-search=native={}",
find_cuda_windows().display()
);
} else {
for path in find_cuda() {
println!("cargo:rustc-link-search=native={}", path.display());
}
};

println!("cargo:rustc-link-lib=dylib=nvToolsExt");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=CUDA_LIBRARY_PATH");
}
18 changes: 18 additions & 0 deletions nvtx-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
#![allow(deref_nullptr)] // https://github.com/rust-lang/rust-bindgen/issues/1651
include!("nv_tools_ext.rs");

#[cfg(test)]
mod tests {
use super::*;
use std::ffi::CStr;

// not a test for cublas initialization, but a test for linking cublasCreate_v2
#[test]
fn link_test() {
unsafe {
let name = CStr::from_bytes_with_nul_unchecked(b"my mark\0");
nvtxMarkA(name.as_ptr());
}
}
}
Loading