Skip to content

Remove "simd" from tiling_2d_simd #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions blog/2024-11-21-optimizing-matrix-mul/code/Cargo.lock

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

5 changes: 3 additions & 2 deletions blog/2024-11-21-optimizing-matrix-mul/code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [
"crates/gpu/workgroup_2d",
"crates/gpu/tiling_1d",
"crates/gpu/tiling_1d_loop",
"crates/gpu/tiling_2d_simd",
"crates/gpu/tiling_2d",
#
# ---- The rust code that runs both on the GPU and the CPU. ----
# It "knows" what platform it is being compiled for and can conditionally change
Expand All @@ -31,7 +31,8 @@ members = [
"crates/cpu/compiled_for_gpu/workgroup_256",
"crates/cpu/compiled_for_gpu/workgroup_2d",
"crates/cpu/compiled_for_gpu/tiling_1d",
"crates/cpu/compiled_for_gpu/tiling_2d_simd",
"crates/cpu/compiled_for_gpu/tiling_1d_loop",
"crates/cpu/compiled_for_gpu/tiling_2d",
"crates/cpu/compiled_for_gpu/isomorphic",
# 3) A binary that runs on the CPU. It configures the `matmul` library on the CPU
# and then tells it to run the matrix multiplication.
Expand Down
12 changes: 3 additions & 9 deletions blog/2024-11-21-optimizing-matrix-mul/code/benches/gpu_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn bench_all_variants(c: &mut Criterion) {
let multiplier_workgroup_2d = matmul::workgroup_2d::wgpu();
let multiplier_tiling_1d = matmul::tiling_1d::wgpu();
let multiplier_tiling_1d_loop = matmul::tiling_1d_loop::wgpu();
let multiplier_tiling_2d_simd = matmul::tiling_2d_simd::wgpu();
let multiplier_tiling_2d = matmul::tiling_2d::wgpu();
let multiplier_isomorphic_gpu = matmul::isomorphic::wgpu();

for &(m, k, n) in SIZES {
Expand Down Expand Up @@ -126,17 +126,11 @@ fn bench_all_variants(c: &mut Criterion) {
);

group.bench_with_input(
BenchmarkId::new("tiling_2d_simd:wgpu", format!("{}x{}x{}", m, k, n)),
BenchmarkId::new("tiling_2d:wgpu", format!("{}x{}x{}", m, k, n)),
&(m, k, n),
|bench, &(m, k, n)| {
bench.iter(|| {
black_box(multiplier_tiling_2d_simd.multiply(
black_box(&a),
black_box(&b),
m,
k,
n,
))
black_box(multiplier_tiling_2d.multiply(black_box(&a), black_box(&b), m, k, n))
});
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {
run_tests(matmul::workgroup_2d::wgpu(), &sizes);
run_tests(matmul::tiling_1d::wgpu(), &sizes);
run_tests(matmul::tiling_1d_loop::wgpu(), &sizes);
run_tests(matmul::tiling_2d_simd::wgpu(), &sizes);
run_tests(matmul::tiling_2d::wgpu(), &sizes);

run_tests(matmul::isomorphic::wgpu(), &sizes);
run_tests(matmul::isomorphic::cpu::single_threaded(), &sizes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs;
use std::path::{Path, PathBuf};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let gpu_crate_path = Path::new("../../../gpu/tiling_2d_simd");
let gpu_crate_path = Path::new("../../../gpu/tiling_2d");

// Compile the shader crate with SpirvBuilder.
let result = SpirvBuilder::new(gpu_crate_path, "spirv-unknown-vulkan1.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "compiled_tiling_2d_simd"
name = "compiled_tiling_2d"
version = "0.1.0"
edition = "2021"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::fs;
use std::path::{Path, PathBuf};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let gpu_crate_path = Path::new("../../../gpu/tiling_2d_simd");
let gpu_crate_path = Path::new("../../../gpu/tiling_2d");

// Compile the shader crate with SpirvBuilder.
let result = SpirvBuilder::new(gpu_crate_path, "spirv-unknown-vulkan1.2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ compiled_workgroup_256 = { path = "../compiled_for_gpu/workgroup_256" }
compiled_workgroup_2d = { path = "../compiled_for_gpu/workgroup_2d" }
compiled_tiling_1d = { path = "../compiled_for_gpu/tiling_1d" }
compiled_tiling_1d_loop = { path = "../compiled_for_gpu/tiling_1d_loop" }
compiled_tiling_2d_simd = { path = "../compiled_for_gpu/tiling_2d_simd" }
compiled_tiling_2d = { path = "../compiled_for_gpu/tiling_2d" }
compiled_isomorphic = { path = "../compiled_for_gpu/isomorphic" }
# The CPU side of the isomophic implementation.
isomorphic = { path = "../../shared/isomorphic" }
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub mod tiling_1d_loop {
}
}

pub mod tiling_2d_simd {
pub mod tiling_2d {
use super::*;
use crate::backends::wgpu::MatrixMultiplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ pub struct Tiling2dSimd;

impl Display for Tiling2dSimd {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "tiling_2d_simd")
write!(f, "tiling_2d")
}
}

impl Gpu for Tiling2dSimd {
fn compiled_shader(&self) -> &[u8] {
compiled_tiling_2d_simd::SHADER_BINARY
compiled_tiling_2d::SHADER_BINARY
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "tiling_2d_simd"
name = "tiling_2d"
version = "0.1.0"
edition = "2021"

Expand Down
2 changes: 1 addition & 1 deletion blog/2024-11-21-optimizing-matrix-mul/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ We can take this a step further and calculate 2D results per thread! Instead of
calculating 4 elements per single row, we can calculate 4 elements for 4 rows (e.g. a 2D
tile).

import { RustTiling2dSimd } from './snippets/tiling_2d_simd.tsx';
import { RustTiling2d } from './snippets/tiling_2d.tsx';

<RustTiling2dSimd />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import Snippet from "@site/src/components/Snippet";
import RustKernelSource from "!!raw-loader!../code/crates/gpu/tiling_2d_simd/src/lib.rs";
import RustKernelSource from "!!raw-loader!../code/crates/gpu/tiling_2d/src/lib.rs";

export const RustTiling2dSimd: React.FC = () => (
<Snippet language="rust" className="text-xs" title="2D tiling kernel with Rust GPU">
Expand Down