cuda_rust_wasm/runtime/
mod.rs1pub mod device;
4pub mod memory;
5pub mod kernel;
6pub mod stream;
7pub mod event;
8pub mod grid;
9
10use crate::{Result, runtime_error};
11use std::sync::Arc;
12
13pub use grid::{Grid, Block, Dim3};
14pub use device::{Device, BackendType};
15pub use stream::Stream;
16pub use event::Event;
17pub use kernel::{launch_kernel, LaunchConfig, KernelFunction, ThreadContext};
18
19pub struct Runtime {
21 device: Arc<Device>,
23 default_stream: Stream,
25}
26
27impl Runtime {
28 pub fn new() -> Result<Self> {
30 let device = Device::get_default()?;
31 let default_stream = Stream::new(device.clone())?;
32
33 Ok(Self {
34 device,
35 default_stream,
36 })
37 }
38
39 pub fn device(&self) -> &Arc<Device> {
41 &self.device
42 }
43
44 pub fn default_stream(&self) -> &Stream {
46 &self.default_stream
47 }
48
49 pub fn create_stream(&self) -> Result<Stream> {
51 Stream::new(self.device.clone())
52 }
53
54 pub fn synchronize(&self) -> Result<()> {
56 self.default_stream.synchronize()
57 }
58}
59
60pub mod thread {
62 use super::grid::Dim3;
63
64 pub fn index() -> Dim3 {
66 Dim3 { x: 0, y: 0, z: 0 }
69 }
70}
71
72pub mod block {
74 use super::grid::Dim3;
75
76 pub fn index() -> Dim3 {
78 Dim3 { x: 0, y: 0, z: 0 }
80 }
81
82 pub fn dim() -> Dim3 {
84 Dim3 { x: 256, y: 1, z: 1 }
86 }
87}
88
89
90pub fn sync_threads() {
92 }