Skip to content

Commit

Permalink
maybe
Browse files Browse the repository at this point in the history
  • Loading branch information
Qazalin committed Jun 18, 2024
1 parent c65a2ae commit 8d6b8ca
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 3 deletions.
235 changes: 235 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ version = "0.1.0"
edition = "2021"

[lib]
name = "remu"
crate-type = ["cdylib"]
path = "src/lib.rs"

[[bin]]
name = "remu-cli"
path = "src/main.rs"

[dependencies]
anyhow = "1.0.86"
clap = { version = "4.5.7", features = ["derive"] }
half = { version = "2.3.1", features = ["num-traits"] }
lazy_static = "1.4.0"
ndarray = "0.15.6"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ curl -s https://api.github.com/repos/Qazalin/remu/releases/latest | \

2. Run tinygrad with `MOCKGPU=1 AMD=1`.


## Build from source

`cargo build --release --lib ` creates the binary [used in tinygrad](https://github.com/tinygrad/tinygrad/tree/master/extra/mockgpu/amd). The tinygrad integration only works in linux.


`cargo build --release --bin remu-cli` builds a minimal version of remu you can run independent of tinygrad on any platform.

## Limitations

Does not implement all RDNA3 instructions.
78 changes: 78 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
use anyhow::{anyhow, Result};
use clap::Parser;
use std::fs;
use utils::GLOBAL_DEBUG;
use work_group::WorkGroup;
mod dtype;
mod memory;
mod state;
mod thread;
mod utils;
mod work_group;

#[derive(Parser, Debug)]
pub struct Cli {
#[arg(short, help = "path to the RDNA3 disassembly", long)]
fp: String,
#[arg(short, help = "global size in gx,gy,gz order", long)]
global_size: String,
#[arg(short, help = "local size in lx,ly,lz order", long)]
local_size: String,
#[arg(short, help = "comma seperated size of each buffer arg", long)]
bufs: String,
// TODO:
// #[arg(short, help = "kernels args", long)]
// args: String,
}

fn parse_size(sz: &String) -> [u32; 3] {
let vec_val = sz
.splitn(3, ",")
.map(|s| s.parse().unwrap())
.collect::<Vec<_>>();
[vec_val[0], vec_val[1], vec_val[2]]
}

fn main() -> Result<()> {
let args = Cli::parse();
let (asm, name) = utils::parse_rdna3(&fs::read_to_string(&args.fp)?);
if asm.len() == 0 {
return Err(anyhow!("file {} contains no assembly", args.fp));
}
let (global_size, local_size) = (parse_size(&args.global_size), parse_size(&args.local_size));
if *GLOBAL_DEBUG {
println!("[remu] launching kernel {name} with global_size {global_size:?} local_size {local_size:?}");
}

let dispatch_dim = match (global_size[1] != 1, global_size[2] != 1) {
(true, true) => 3,
(true, false) => 2,
_ => 1,
};

let mut kernel_args = vec![];
args.bufs.split(",").for_each(|s| {
let size = s.parse::<usize>().unwrap();
let val: Vec<u8> = vec![0; size];
kernel_args.extend(val);
});

println!("{:?}", kernel_args);

for gx in 0..global_size[0] {
for gy in 0..global_size[1] {
for gz in 0..global_size[2] {
WorkGroup::new(
dispatch_dim,
[gx, gy, gz],
local_size,
&asm,
kernel_args.as_ptr(),
)
.exec_waves();
}
}
}
println!("{:?}", local_size);
Ok(())
}
Loading

0 comments on commit 8d6b8ca

Please sign in to comment.