Go to file
Julius Koskela 668293d956
🔧 Implement as a library
- Make the crate a lib
- Move main to examples as mat_mul_4x4.rs
- Correctly track elapsed time of compute task

Signed-off-by: Julius Koskela <julius.koskela@unikie.com>
2023-12-23 04:00:45 +02:00
examples 🔧 Implement as a library 2023-12-23 04:00:45 +02:00
src 🔧 Implement as a library 2023-12-23 04:00:45 +02:00
.gitignore 🚀 Builds and runs on Linux and MacOS, result still wrong 2023-12-22 10:51:26 +02:00
Cargo.lock 🔧 Implement as a library 2023-12-23 04:00:45 +02:00
Cargo.toml 🔧 Implement as a library 2023-12-23 04:00:45 +02:00
default.nix 🔧 Make nix develop work 2023-12-23 02:41:35 +02:00
flake.lock 🚀 Initial wgpu matrix multiplication test, fails to build on Linux 2023-12-21 21:00:20 +02:00
flake.nix 🔧 Make nix develop work 2023-12-23 02:41:35 +02:00
LICENSE 📝 Add LICENSE and README.md 2023-12-23 02:48:40 +02:00
README.md 📝 Add LICENSE and README.md 2023-12-23 02:48:40 +02:00

Rust wGPU Matrix Multiplication Shader Test

Overview

This project demonstrates a matrix multiplication operation using compute shaders in Rust with the wGPU library. The primary goal is to showcase how to perform a simple matrix multiplication on the GPU, leveraging the power of parallel computation provided by shaders.

Features

  • Matrix multiplication using a compute shader.
  • Implementation using Rust and the wGPU library.
  • Efficient GPU-based computation for matrix operations.

Prerequisites

  • Rust programming language.
  • wGPU library for Rust.
  • GPU that supports WebGPU.

Getting Started

Installation

  1. Clone the repository:

    git clone https://github.com/your-repository/rust-wgpu-matrix-multiplication.git
    cd rust-wgpu-matrix-multiplication
    
  2. Ensure you have the latest version of Rust installed:

    rustup update
    

Build and Run

  1. Build the project using Cargo, Rust's package manager and build system:

    cargo build --release
    
  2. Run the compiled binary:

    cargo run --release
    

Project Structure

  • src/main.rs: The main entry point for the application.
  • src/ppu.rs: Contains the PPU struct for handling GPU tasks.
  • shaders/: Folder containing WGSL shader files.

Shader

The matrix multiplication logic is implemented in a WGSL shader. The shader takes two input matrices (matrixA and matrixB) and outputs the product (matrixC).

How It Works

  • The compute shader (main) is dispatched with a workgroup size of 4x4.
  • Each work item calculates one element of the product matrix.
  • The result is written back to a buffer that is read by the Rust application.

Contributing

Contributions to this project are welcome. Please open an issue or pull request on the GitHub repository.

License

This project is open-source and available under the MIT License.