#github.com/xulang-org/packages/cuda_native
Xu 0.16.0 API
import: cuda_native #github.com/xulang-org/packages/cuda_native
counts: 7 functions, 36 methods, 4 types, 0 constants, 0 method sets
Pure-Xu dlopen backend for CUDA Driver API + NVRTC + cuBLAS. No C wrapper or compile-time link flags required: loads libcuda / libnvrtc / libcublas dynamically at runtime on Linux/Windows and allows XU_CUDA_LIBRARY / XU_NVRTC_LIBRARY XU_CUBLAS_LIBRARY overrides for custom driver paths or test mocks.
github.com/xulang-org/packages · 1.17.2 · Install and use
struct CudaDevice
pub struct CudaDevice {
pub ordinal int
pub handle int
pub ctx c_ptr
pub stream c_ptr
pub cublas c_ptr
pub llm_mod c_ptr
pub fn_add_f32 c_ptr
pub fn_mul_f32 c_ptr
pub fn_scale_f32 c_ptr
pub fn_rmsnorm_f32 c_ptr
pub fn_softmax_f32 c_ptr
pub fn_swiglu_f32 c_ptr
pub fn_rope_f32 c_ptr
pub fn_gemm_f32 c_ptr
pub fn_gemm_f32_nt c_ptr
pub fn_gemm_f32_tn c_ptr
pub fn_gemv_q4_0_f32 c_ptr
pub fn_gemv_q8_0_f32 c_ptr
pub fn_gemv_q4_k_f32 c_ptr
pub fn_gemv_q5_k_f32 c_ptr
pub fn_gemv_q6_k_f32 c_ptr
pub closed bool
}
Purpose
Structure encapsulating ordinal, handle, ctx, stream, cublas.
Public fields
ordinal int- field (int)
handle int- field (int)
ctx c_ptr- field (c_ptr)
stream c_ptr- field (c_ptr)
cublas c_ptr- field (c_ptr)
llm_mod c_ptr- field (c_ptr)
fn_add_f32 c_ptr- field (c_ptr)
fn_mul_f32 c_ptr- field (c_ptr)
fn_scale_f32 c_ptr- field (c_ptr)
fn_rmsnorm_f32 c_ptr- field (c_ptr)
fn_softmax_f32 c_ptr- field (c_ptr)
fn_swiglu_f32 c_ptr- field (c_ptr)
fn_rope_f32 c_ptr- field (c_ptr)
fn_gemm_f32 c_ptr- field (c_ptr)
fn_gemm_f32_nt c_ptr- field (c_ptr)
fn_gemm_f32_tn c_ptr- field (c_ptr)
fn_gemv_q4_0_f32 c_ptr- field (c_ptr)
fn_gemv_q8_0_f32 c_ptr- field (c_ptr)
fn_gemv_q4_k_f32 c_ptr- field (c_ptr)
fn_gemv_q5_k_f32 c_ptr- field (c_ptr)
fn_gemv_q6_k_f32 c_ptr- field (c_ptr)
closed bool- field (bool)
struct CudaBuffer
pub struct CudaBuffer {
pub dptr u64
pub byte_len int
pub ctx c_ptr
pub closed bool
}
Purpose
Structure encapsulating dptr, byte_len, ctx, closed.
Public fields
dptr u64- field (u64)
byte_len int- field (int)
ctx c_ptr- field (c_ptr)
closed bool- field (bool)
struct CudaModule
pub struct CudaModule {
pub handle c_ptr
pub closed bool
}
Purpose
Structure encapsulating handle, closed.
Public fields
handle c_ptr- field (c_ptr)
closed bool- field (bool)
struct CudaFunction
pub struct CudaFunction {
pub handle c_ptr
}
Purpose
Structure encapsulating handle.
Public fields
handle c_ptr- field (c_ptr)
available
Purpose
Execute available.
Parameters
No arguments are required.
Returns
bool — true or false
has_nvrtc
Purpose
Whether it has nvrtc.
Parameters
No arguments are required.
Returns
bool — true or false
has_cublas
Purpose
Whether it has cublas.
Parameters
No arguments are required.
Returns
bool — true or false
device_count
pub fn device_count() int
Purpose
Device count.
Parameters
No arguments are required.
Returns
int — a value of this type
open
pub fn open(ordinal int) CudaDevice
Purpose
Open resource or establish connection. Throws on failure; handle the error or propagate it to the caller.
Parameters
ordinal int- ordinal (int)
Returns
CudaDevice — a value of this type
(&CudaDevice) make_current
pub fn (d &CudaDevice) make_current() int
Purpose
Operation on &CudaDevice: make current. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
Returns
int — a value of this type
(&CudaDevice) name
pub fn (d &CudaDevice) name() string
Purpose
Execute name on &CudaDevice. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
Returns
string — result string
(&CudaDevice) total_mem
pub fn (d &CudaDevice) total_mem() int
Purpose
Operation on &CudaDevice: total mem. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
Returns
int — a value of this type
(&CudaDevice) sm_count
pub fn (d &CudaDevice) sm_count() int
Purpose
Operation on &CudaDevice: sm count. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
Returns
int — a value of this type
(&CudaDevice) cc_major
pub fn (d &CudaDevice) cc_major() int
Purpose
Operation on &CudaDevice: cc major. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
Returns
int — a value of this type
(&CudaDevice) cc_minor
pub fn (d &CudaDevice) cc_minor() int
Purpose
Operation on &CudaDevice: cc minor. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
Returns
int — a value of this type
(&CudaDevice) sync
pub fn (d &CudaDevice) sync() int
Purpose
Execute sync on &CudaDevice. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
Returns
int — a value of this type
($&CudaDevice) close
pub fn (d $&CudaDevice) close() int
Purpose
Operation on $&CudaDevice: close the resource.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
Returns
int — a value of this type
(&CudaDevice) alloc_bytes
pub fn (d &CudaDevice) alloc_bytes(byte_len int) CudaBuffer
Purpose
Operation on &CudaDevice: alloc bytes. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
byte_len int- byte_len (int)
Returns
CudaBuffer — a value of this type
(&CudaDevice) alloc_f32
pub fn (d &CudaDevice) alloc_f32(elements int) CudaBuffer
Purpose
Operation on &CudaDevice: alloc f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
elements int- elements (int)
Returns
CudaBuffer — a value of this type
($&CudaBuffer) write_bytes
pub fn (b $&CudaBuffer) write_bytes(data &string) int
Purpose
Operation on $&CudaBuffer: write bytes. Throws on failure; handle the error or propagate it to the caller.
Parameters
b $&CudaBuffer- The
CudaBuffer instance used by this call (exclusive borrow).
data &string- data (read-only borrow; caller keeps the original; type &string)
Returns
int — a value of this type
($&CudaBuffer) write_f32_bits
pub fn (b $&CudaBuffer) write_f32_bits(bits &[]int) int
Purpose
Operation on $&CudaBuffer: write f32 bits. Throws on failure; handle the error or propagate it to the caller.
Parameters
b $&CudaBuffer- The
CudaBuffer instance used by this call (exclusive borrow).
bits &[]int- bit count (read-only borrow; caller keeps the original; type &[]int)
Returns
int — a value of this type
(&CudaBuffer) copy_f32_bits
pub fn (b &CudaBuffer) copy_f32_bits(out $&[]int) int
Purpose
Operation on &CudaBuffer: copy f32 bits. Throws on failure; handle the error or propagate it to the caller.
Parameters
b &CudaBuffer- The
CudaBuffer instance used by this call (borrow).
out $&[]int- out (exclusive borrow; may modify the original; type $&[]int)
Returns
int — a value of this type
(&CudaBuffer) read_f32_bits
pub fn (b &CudaBuffer) read_f32_bits() []int
Purpose
Operation on &CudaBuffer: read f32 bits. Throws on failure; handle the error or propagate it to the caller.
Parameters
b &CudaBuffer- The
CudaBuffer instance used by this call (borrow).
Returns
[]int — slice result
($&CudaBuffer) copy_from
pub fn (b $&CudaBuffer) copy_from(src &CudaBuffer) int
Purpose
Operation on $&CudaBuffer: copy from. Throws on failure; handle the error or propagate it to the caller.
Parameters
b $&CudaBuffer- The
CudaBuffer instance used by this call (exclusive borrow).
src &CudaBuffer- source (read-only borrow; caller keeps the original; type &CudaBuffer)
Returns
int — a value of this type
($&CudaBuffer) zero
pub fn (b $&CudaBuffer) zero() int
Purpose
Operation on $&CudaBuffer: zero. Throws on failure; handle the error or propagate it to the caller.
Parameters
b $&CudaBuffer- The
CudaBuffer instance used by this call (exclusive borrow).
Returns
int — a value of this type
($&CudaBuffer) close
pub fn (b $&CudaBuffer) close() int
Purpose
Operation on $&CudaBuffer: close the resource.
Parameters
b $&CudaBuffer- The
CudaBuffer instance used by this call (exclusive borrow).
Returns
int — a value of this type
compile_ptx
pub fn compile_ptx(src string, name string, arch_opt string) string
Purpose
Compile ptx. Throws on failure; handle the error or propagate it to the caller.
Parameters
src string- source (string)
name string- name (string)
arch_opt string- arch_opt (string)
Returns
string — result string
(&CudaDevice) load_module_ptx
pub fn (d &CudaDevice) load_module_ptx(ptx string) CudaModule
Purpose
Operation on &CudaDevice: load module ptx. Throws on failure; handle the error or propagate it to the caller.
Parameters
d &CudaDevice- The
CudaDevice instance used by this call (borrow).
ptx string- ptx (string)
Returns
CudaModule — a value of this type
(&CudaModule) get_function
pub fn (m &CudaModule) get_function(name string) CudaFunction
Purpose
Operation on &CudaModule: read function. Throws on failure; handle the error or propagate it to the caller.
Parameters
m &CudaModule- The
CudaModule instance used by this call (borrow).
name string- name (string)
Returns
CudaFunction — a value of this type
($&CudaModule) close
pub fn (m $&CudaModule) close() int
Purpose
Operation on $&CudaModule: close the resource.
Parameters
m $&CudaModule- The
CudaModule instance used by this call (exclusive borrow).
Returns
int — a value of this type
($&CudaDevice) ensure_llm_kernels
pub fn (d $&CudaDevice) ensure_llm_kernels() int
Purpose
Operation on $&CudaDevice: ensure llm kernels. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
Returns
int — a value of this type
($&CudaDevice) add_f32
pub fn (d $&CudaDevice) add_f32(dst $&CudaBuffer, a &CudaBuffer, b &CudaBuffer, n int) int
Purpose
Operation on $&CudaDevice: add f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
a &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
b &CudaBuffer- b (read-only borrow; caller keeps the original; type &CudaBuffer)
n int- count, length, or limit (int)
Returns
int — a value of this type
($&CudaDevice) mul_f32
pub fn (d $&CudaDevice) mul_f32(dst $&CudaBuffer, a &CudaBuffer, b &CudaBuffer, n int) int
Purpose
Operation on $&CudaDevice: mul f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
a &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
b &CudaBuffer- b (read-only borrow; caller keeps the original; type &CudaBuffer)
n int- count, length, or limit (int)
Returns
int — a value of this type
($&CudaDevice) scale_f32
pub fn (d $&CudaDevice) scale_f32(dst $&CudaBuffer, x &CudaBuffer, n int, alpha f64) int
Purpose
Operation on $&CudaDevice: scale f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
n int- count, length, or limit (int)
alpha f64- alpha (f64)
Returns
int — a value of this type
($&CudaDevice) rmsnorm_f32
pub fn (d $&CudaDevice) rmsnorm_f32(dst $&CudaBuffer, x &CudaBuffer, weight &CudaBuffer, rows int, cols int, eps f64) int
Purpose
Operation on $&CudaDevice: rmsnorm f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
weight &CudaBuffer- weight (read-only borrow; caller keeps the original; type &CudaBuffer)
rows int- rows (int)
cols int- cols (int)
eps f64- eps (f64)
Returns
int — a value of this type
($&CudaDevice) softmax_f32
pub fn (d $&CudaDevice) softmax_f32(dst $&CudaBuffer, x &CudaBuffer, rows int, cols int) int
Purpose
Operation on $&CudaDevice: softmax f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
rows int- rows (int)
cols int- cols (int)
Returns
int — a value of this type
($&CudaDevice) swiglu_f32
pub fn (d $&CudaDevice) swiglu_f32(dst $&CudaBuffer, gate &CudaBuffer, up &CudaBuffer, n int) int
Purpose
Operation on $&CudaDevice: swiglu f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
gate &CudaBuffer- gate (read-only borrow; caller keeps the original; type &CudaBuffer)
up &CudaBuffer- up (read-only borrow; caller keeps the original; type &CudaBuffer)
n int- count, length, or limit (int)
Returns
int — a value of this type
($&CudaDevice) rope_f32
pub fn (d $&CudaDevice) rope_f32(dst $&CudaBuffer, x &CudaBuffer, seq_len int, n_heads int, head_dim int, pos_off int, theta f64) int
Purpose
Operation on $&CudaDevice: rope f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
seq_len int- seq_len (int)
n_heads int- n_heads (int)
head_dim int- head_dim (int)
pos_off int- pos_off (int)
theta f64- theta (f64)
Returns
int — a value of this type
($&CudaDevice) gemm_f32
pub fn (d $&CudaDevice) gemm_f32(dst $&CudaBuffer, a &CudaBuffer, b &CudaBuffer, m int, n int, k int) int
Purpose
Operation on $&CudaDevice: gemm f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
a &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
b &CudaBuffer- b (read-only borrow; caller keeps the original; type &CudaBuffer)
m int- m (int)
n int- count, length, or limit (int)
k int- key or index (int)
Returns
int — a value of this type
($&CudaDevice) gemm_f32_nt
pub fn (d $&CudaDevice) gemm_f32_nt(dst $&CudaBuffer, a &CudaBuffer, b &CudaBuffer, m int, n int, k int) int
Purpose
Operation on $&CudaDevice: gemm f32 nt. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
a &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
b &CudaBuffer- b (read-only borrow; caller keeps the original; type &CudaBuffer)
m int- m (int)
n int- count, length, or limit (int)
k int- key or index (int)
Returns
int — a value of this type
($&CudaDevice) gemm_f32_tn
pub fn (d $&CudaDevice) gemm_f32_tn(dst $&CudaBuffer, a &CudaBuffer, b &CudaBuffer, m int, n int, k int) int
Purpose
Operation on $&CudaDevice: gemm f32 tn. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
a &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
b &CudaBuffer- b (read-only borrow; caller keeps the original; type &CudaBuffer)
m int- m (int)
n int- count, length, or limit (int)
k int- key or index (int)
Returns
int — a value of this type
($&CudaDevice) gemv_q4_0_f32
pub fn (d $&CudaDevice) gemv_q4_0_f32(dst $&CudaBuffer, x &CudaBuffer, w &CudaBuffer, rows int, cols int, m_cnt int) int
Purpose
Operation on $&CudaDevice: gemv q4 0 f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
w &CudaBuffer- writer or width (read-only borrow; caller keeps the original; type &CudaBuffer)
rows int- rows (int)
cols int- cols (int)
m_cnt int- m_cnt (int)
Returns
int — a value of this type
($&CudaDevice) gemv_q8_0_f32
pub fn (d $&CudaDevice) gemv_q8_0_f32(dst $&CudaBuffer, x &CudaBuffer, w &CudaBuffer, rows int, cols int, m_cnt int) int
Purpose
Operation on $&CudaDevice: gemv q8 0 f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
w &CudaBuffer- writer or width (read-only borrow; caller keeps the original; type &CudaBuffer)
rows int- rows (int)
cols int- cols (int)
m_cnt int- m_cnt (int)
Returns
int — a value of this type
($&CudaDevice) gemv_q4_k_f32
pub fn (d $&CudaDevice) gemv_q4_k_f32(dst $&CudaBuffer, x &CudaBuffer, w &CudaBuffer, rows int, cols int, m_cnt int) int
Purpose
Operation on $&CudaDevice: gemv q4 k f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
w &CudaBuffer- writer or width (read-only borrow; caller keeps the original; type &CudaBuffer)
rows int- rows (int)
cols int- cols (int)
m_cnt int- m_cnt (int)
Returns
int — a value of this type
($&CudaDevice) gemv_q5_k_f32
pub fn (d $&CudaDevice) gemv_q5_k_f32(dst $&CudaBuffer, x &CudaBuffer, w &CudaBuffer, rows int, cols int, m_cnt int) int
Purpose
Operation on $&CudaDevice: gemv q5 k f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
w &CudaBuffer- writer or width (read-only borrow; caller keeps the original; type &CudaBuffer)
rows int- rows (int)
cols int- cols (int)
m_cnt int- m_cnt (int)
Returns
int — a value of this type
($&CudaDevice) gemv_q6_k_f32
pub fn (d $&CudaDevice) gemv_q6_k_f32(dst $&CudaBuffer, x &CudaBuffer, w &CudaBuffer, rows int, cols int, m_cnt int) int
Purpose
Operation on $&CudaDevice: gemv q6 k f32. Throws on failure; handle the error or propagate it to the caller.
Parameters
d $&CudaDevice- The
CudaDevice instance used by this call (exclusive borrow).
dst $&CudaBuffer- destination (exclusive borrow; may modify the original; type $&CudaBuffer)
x &CudaBuffer- value (read-only borrow; caller keeps the original; type &CudaBuffer)
w &CudaBuffer- writer or width (read-only borrow; caller keeps the original; type &CudaBuffer)
rows int- rows (int)
cols int- cols (int)
m_cnt int- m_cnt (int)
Returns
int — a value of this type
llm_kernels_source
pub fn llm_kernels_source() string
Purpose
Embedded pure CUDA C kernels (header-free so NVRTC compiles without toolkit headers).
Parameters
No arguments are required.
Returns
string — result string