-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is tiling_1d but with loops.
- Loading branch information
Showing
15 changed files
with
352 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...24-11-21-optimizing-matrix-mul/code/crates/cpu/compiled_for_gpu/tiling_1d_loop/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "compiled_tiling_1d_loop" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["lib", "cdylib"] | ||
|
||
[build-dependencies] | ||
spirv-builder = { git = "https://github.com/rust-gpu/rust-gpu", rev = "0da80f8a61867590a0824873fa45dc8983e49da8" } |
37 changes: 37 additions & 0 deletions
37
...2024-11-21-optimizing-matrix-mul/code/crates/cpu/compiled_for_gpu/tiling_1d_loop/build.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use spirv_builder::{MetadataPrintout, SpirvBuilder}; | ||
use std::env; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let gpu_crate_path = Path::new("../../../gpu/tiling_1d_loop"); | ||
|
||
// Compile the shader crate with SpirvBuilder. | ||
let result = SpirvBuilder::new(gpu_crate_path, "spirv-unknown-vulkan1.2") | ||
.print_metadata(MetadataPrintout::Full) | ||
.build()?; | ||
|
||
// Get the compiled shader as a PathBuf and read its binary content. | ||
let shader_path = result.module.unwrap_single(); | ||
let shader_binary = fs::read(&shader_path)?; | ||
|
||
// Generate Rust code with a constant holding the shader binary content. | ||
let shader_binary_literal = shader_binary | ||
.iter() | ||
.map(|byte| format!("0x{:02X}", byte)) | ||
.collect::<Vec<_>>() | ||
.join(", "); | ||
let generated_code = format!( | ||
"/// Compiled SPIR-V shader binary\n\ | ||
pub const SHADER_BINARY: &[u8] = &[{}];", | ||
shader_binary_literal | ||
); | ||
|
||
// Write this generated code to `OUT_DIR` as `shader_binary.rs`. | ||
let out_dir = PathBuf::from(env::var("OUT_DIR")?); | ||
let shader_binary_rs = out_dir.join("shader_binary.rs"); | ||
fs::write(&shader_binary_rs, generated_code)?; | ||
|
||
println!("Generated shader binary constant at {:?}", shader_binary_rs); | ||
Ok(()) | ||
} |
4 changes: 4 additions & 0 deletions
4
...24-11-21-optimizing-matrix-mul/code/crates/cpu/compiled_for_gpu/tiling_1d_loop/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Including the raw bytes generated shader binary in our rust code. This "bloats" the | ||
// binary, but it also means you don't have to worry about the shader file being | ||
// misplaced or deleted. | ||
include!(concat!(env!("OUT_DIR"), "/shader_binary.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
blog/2024-11-21-optimizing-matrix-mul/code/crates/gpu/tiling_1d_loop/Cargo.lock
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
blog/2024-11-21-optimizing-matrix-mul/code/crates/gpu/tiling_1d_loop/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "tiling_1d_loop" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["dylib", "lib"] | ||
|
||
[dependencies] | ||
settings = { path = "../../shared/settings"} | ||
spirv-std.workspace = true |
Oops, something went wrong.