NVIDIA announced the development of the CUDA Rust toolkit, which enables the Rust language to develop kernels running on the GPU. The toolkit ensures memory safety at compile time and prevents race conditions. Next year, CUDA Rust is planned to be developed to a level suitable for production projects, similar to the CUDA C++ and CUDA Python toolkit.
The CUDA Rust toolchain supports two models for developing parallel kernels: SIMT (Single Instruction, Multiple Threads) and Tile. The SIMT model allows for the low-level definition of a single thread, the launching and management of thousands of such threads. The Tile model offers a higher level of abstraction, where instead of explicitly managing individual threads, algorithms for operating on data blocks (tiles) are defined, and the Tile IR compiler handles all thread manipulation, access synchronization, memory management, and data distribution across tensor cores.
For development in the Rust language using the SIMT model, the cuda-oxide compiler is being developed, which allows compiling code in the Rust language, using the standard type system and the Rust ownership model, directly into instructions for execution in virtual machine CUDA PTX (Parallel Thread Execution). GPU kernels are written in regular Rust, but run in a no_std environment and can only use functions from the libcore library and specialized Rust abstractions, without access to the standard Rust library (libstd).
CUDA kernels written in Rust allow the use of type protection (safe), the use of unsafe blocks, and access to low-level hardware instructions. To ensure safety, the DisjointSlice type is proposed, ensuring that each thread has exclusive access to only its own data. The cuda-oxide code is licensed under the Apache 2.0 license.
To implement the Tail model, the cutile-rs library is proposed. It enables the use of the Rust idiomatic language to create code that compiles directly to CUDA kernels. Cutile-rs applies Rust's strict ownership and borrowing rules to code running on the GPU. The kernel is implemented as a single-threaded program operating on a data block, and the compiler automatically splits the computation into threads and ensures their synchronization. The threads are granted shared access to immutable tensors, and mutable tensors are partitioned into disjoint blocks to ensure safe access. The cutile-rs code is distributed under the Apache 2.0 license.
Source: opennet.ru
