-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from tracel-ai/perf/better-vectorization-cuda
Perf/better vectorization on cuda
- Loading branch information
Showing
15 changed files
with
539 additions
and
379 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use crate as cubecl; | ||
|
||
use cubecl::prelude::*; | ||
|
||
#[cube(launch)] | ||
pub fn kernel_assign(output: &mut Array<F32>, vectorization: Comptime<UInt>) { | ||
if UNIT_POS == UInt::new(0) { | ||
let item = F32::vectorized(5.0, Comptime::get(vectorization)); | ||
output[0] = item; | ||
} | ||
} | ||
|
||
pub fn test_kernel_assign_scalar<R: Runtime>(client: ComputeClient<R::Server, R::Channel>) { | ||
let handle = client.create(f32::as_bytes(&[0.0, 1.0])); | ||
|
||
let vectorization = 2; | ||
|
||
kernel_assign::launch::<R>( | ||
&client, | ||
CubeCount::Static(1, 1, 1), | ||
CubeDim::default(), | ||
ArrayArg::vectorized(vectorization, &handle, 2), | ||
UInt::new(vectorization as u32), | ||
); | ||
|
||
let actual = client.read(handle.binding()); | ||
let actual = f32::from_bytes(&actual); | ||
|
||
assert_eq!(actual[0], 5.0); | ||
} | ||
|
||
#[allow(missing_docs)] | ||
#[macro_export] | ||
macro_rules! testgen_assign { | ||
() => { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_assign_scalar() { | ||
let client = TestRuntime::client(&Default::default()); | ||
cubecl_core::runtime_tests::assign::test_kernel_assign_scalar::<TestRuntime>(client); | ||
} | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate as cubecl; | ||
|
||
use cubecl::prelude::*; | ||
|
||
#[cube(launch)] | ||
pub fn kernel_absolute_pos(output1: &mut Array<UInt>, output2: &mut Array<UInt>) { | ||
if ABSOLUTE_POS >= output1.len() { | ||
return; | ||
} | ||
|
||
output1[ABSOLUTE_POS] = ABSOLUTE_POS; | ||
output2[ABSOLUTE_POS] = ABSOLUTE_POS; | ||
} | ||
|
||
pub fn test_kernel_topology_absolute_pos<R: Runtime>(client: ComputeClient<R::Server, R::Channel>) { | ||
let cube_count = (3, 5, 7); | ||
let cube_dim = (16, 16, 1); | ||
let extra: u32 = 3u32; | ||
|
||
let length = | ||
(cube_count.0 * cube_count.1 * cube_count.2 * cube_dim.0 * cube_dim.1 * cube_dim.2) + extra; | ||
let handle1 = client.empty(length as usize * core::mem::size_of::<u32>()); | ||
let handle2 = client.empty(length as usize * core::mem::size_of::<u32>()); | ||
|
||
kernel_absolute_pos::launch::<R>( | ||
&client, | ||
CubeCount::Static(cube_count.0, cube_count.1, cube_count.2), | ||
CubeDim::new(cube_dim.0, cube_dim.1, cube_dim.2), | ||
ArrayArg::new(&handle1, length as usize), | ||
ArrayArg::new(&handle2, length as usize), | ||
); | ||
|
||
let actual = client.read(handle1.binding()); | ||
let actual = u32::from_bytes(&actual); | ||
let mut expect: Vec<u32> = (0..length - extra).collect(); | ||
expect.push(0); | ||
expect.push(0); | ||
expect.push(0); | ||
|
||
assert_eq!(actual, &expect); | ||
} | ||
|
||
#[allow(missing_docs)] | ||
#[macro_export] | ||
macro_rules! testgen_topology { | ||
() => { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_topology_scalar() { | ||
let client = TestRuntime::client(&Default::default()); | ||
cubecl_core::runtime_tests::topology::test_kernel_topology_absolute_pos::<TestRuntime>( | ||
client, | ||
); | ||
} | ||
}; | ||
} |
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
Oops, something went wrong.