Skip to content
This repository was archived by the owner on Mar 29, 2025. It is now read-only.

Separate *-sys crates #19

Merged
merged 13 commits into from
Dec 30, 2019
25 changes: 7 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
[package]
name = "cuda-sys"
version = "0.2.1-alpha.0"
authors = ["Toshiki Teramura <[email protected]>"]

build = "build.rs"
links = "cuda"

description = "Rust binding to CUDA Driver/Runtime APIs"
documentation = "https://docs.rs/cuda-sys/"
repository = "https://github.com/termoshtt/accel"
keywords = ["GPGPU", "CUDA", "ffi"]
license = "MIT"
readme = "README.md"
categories = []

[build-dependencies]
glob = "*"
[workspace]
members = [
"cublas-sys",
"cuda-config",
"cuda-driver-sys",
"cuda-runtime-sys",
]
20 changes: 20 additions & 0 deletions cublas-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "cublas-sys"
version = "0.2.0"
authors = ["Toshiki Teramura <[email protected]>"]
edition = "2018"

build = "build.rs"
links = "cublas"

description = "Rust binding to CUDA BLAS API"
documentation = "https://docs.rs/cublas-sys/"
repository = "https://github.com/rust-cuda/cuda-sys"
keywords = ["GPGPU", "CUDA", "ffi"]
license = "MIT"
readme = "../README.md"
categories = []

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

bindgen \
--whitelist-type="^cublas.*" \
--whitelist-function="^cublas.*" \
--default-enum-style=rust \
--no-doc-comments \
--with-derive-default \
--with-derive-eq \
--with-derive-hash \
--with-derive-ord \
/opt/cuda/include/cublas.h \
-- -I/opt/cuda/include \
> src/cublas.rs
18 changes: 18 additions & 0 deletions cublas-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=cublas");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=CUDA_LIBRARY_PATH");
}
124 changes: 115 additions & 9 deletions src/cublas.rs → cublas-sys/src/cublas.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,113 @@
/* automatically generated by rust-bindgen */

#[repr(C)]
#[repr(align(8))]
#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)]
pub struct float2 {
pub x: f32,
pub y: f32,
}
#[test]
fn bindgen_test_layout_float2() {
assert_eq!(
::std::mem::size_of::<float2>(),
8usize,
concat!("Size of: ", stringify!(float2))
);
assert_eq!(
::std::mem::align_of::<float2>(),
8usize,
concat!("Alignment of ", stringify!(float2))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<float2>())).x as *const _ as usize },
0usize,
concat!("Offset of field: ", stringify!(float2), "::", stringify!(x))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<float2>())).y as *const _ as usize },
4usize,
concat!("Offset of field: ", stringify!(float2), "::", stringify!(y))
);
}
#[repr(C)]
#[repr(align(16))]
#[derive(Debug, Default, Copy, Clone, PartialOrd, PartialEq)]
pub struct double2 {
pub x: f64,
pub y: f64,
}
#[test]
fn bindgen_test_layout_double2() {
assert_eq!(
::std::mem::size_of::<double2>(),
16usize,
concat!("Size of: ", stringify!(double2))
);
assert_eq!(
::std::mem::align_of::<double2>(),
16usize,
concat!("Alignment of ", stringify!(double2))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<double2>())).x as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(double2),
"::",
stringify!(x)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<double2>())).y as *const _ as usize },
8usize,
concat!(
"Offset of field: ",
stringify!(double2),
"::",
stringify!(y)
)
);
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct CUstream_st {
_unused: [u8; 0],
}
pub type cudaStream_t = *mut CUstream_st;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cudaDataType_t {
CUDA_R_16F = 2,
CUDA_C_16F = 6,
CUDA_R_32F = 0,
CUDA_C_32F = 4,
CUDA_R_64F = 1,
CUDA_C_64F = 5,
CUDA_R_8I = 3,
CUDA_C_8I = 7,
CUDA_R_8U = 8,
CUDA_C_8U = 9,
CUDA_R_32I = 10,
CUDA_C_32I = 11,
CUDA_R_32U = 12,
CUDA_C_32U = 13,
}
pub use self::cudaDataType_t as cudaDataType;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum libraryPropertyType_t {
MAJOR_VERSION = 0,
MINOR_VERSION = 1,
PATCH_LEVEL = 2,
}
pub use self::libraryPropertyType_t as libraryPropertyType;
pub type cuFloatComplex = float2;
pub type cuDoubleComplex = double2;
pub type cuComplex = cuFloatComplex;
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasStatus_t {
CUBLAS_STATUS_SUCCESS = 0,
CUBLAS_STATUS_NOT_INITIALIZED = 1,
Expand All @@ -15,20 +121,20 @@ pub enum cublasStatus_t {
CUBLAS_STATUS_LICENSE_ERROR = 16,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasFillMode_t {
CUBLAS_FILL_MODE_LOWER = 0,
CUBLAS_FILL_MODE_UPPER = 1,
CUBLAS_FILL_MODE_FULL = 2,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasDiagType_t {
CUBLAS_DIAG_NON_UNIT = 0,
CUBLAS_DIAG_UNIT = 1,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasSideMode_t {
CUBLAS_SIDE_LEFT = 0,
CUBLAS_SIDE_RIGHT = 1,
Expand All @@ -37,21 +143,21 @@ impl cublasOperation_t {
pub const CUBLAS_OP_HERMITAN: cublasOperation_t = cublasOperation_t::CUBLAS_OP_C;
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasOperation_t {
CUBLAS_OP_N = 0,
CUBLAS_OP_T = 1,
CUBLAS_OP_C = 2,
CUBLAS_OP_CONJG = 3,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasPointerMode_t {
CUBLAS_POINTER_MODE_HOST = 0,
CUBLAS_POINTER_MODE_DEVICE = 1,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasAtomicsMode_t {
CUBLAS_ATOMICS_NOT_ALLOWED = 0,
CUBLAS_ATOMICS_ALLOWED = 1,
Expand All @@ -64,7 +170,7 @@ impl cublasGemmAlgo_t {
cublasGemmAlgo_t::CUBLAS_GEMM_DEFAULT_TENSOR_OP;
}
#[repr(i32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasGemmAlgo_t {
CUBLAS_GEMM_DFALT = -1,
CUBLAS_GEMM_ALGO0 = 0,
Expand Down Expand Up @@ -110,7 +216,7 @@ pub enum cublasGemmAlgo_t {
CUBLAS_GEMM_ALGO15_TENSOR_OP = 115,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum cublasMath_t {
CUBLAS_DEFAULT_MATH = 0,
CUBLAS_TENSOR_OP_MATH = 1,
Expand Down
25 changes: 25 additions & 0 deletions cublas-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#![allow(non_camel_case_types)]
include!("cublas.rs");

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

// not a test for cublas initialization, but a test for linking cublasCreate_v2
#[test]
fn link_test() {
let mut handle = std::ptr::null_mut();
let result = unsafe { cublasCreate_v2(&mut handle as *mut _) };
match result {
cublasStatus_t::CUBLAS_STATUS_SUCCESS => {
println!("Succeed to init CUBLAS");
}
cublasStatus_t::CUBLAS_STATUS_NOT_INITIALIZED => {
println!("GPU not found");
}
_ => {
panic!("Failed to init CUBLAS");
}
}
}
}
10 changes: 0 additions & 10 deletions cuda-bindgen/Cargo.toml

This file was deleted.

Loading