Skip to content
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

Matmul: kernel select heuristic #312

Merged
merged 3 commits into from
Nov 27, 2024
Merged

Matmul: kernel select heuristic #312

merged 3 commits into from
Nov 27, 2024

Conversation

louisfd
Copy link
Member

@louisfd louisfd commented Nov 27, 2024

I added heuristics to determine which kernel to launch.

  • Choose between 16x16x16, 32x8x16 and 8x32x16 tile instructions
  • Choose stage dims as a function of input size vs tile size, number of tensor cores expected and number of SM (streaming multiprocessor) expected on the device. Last two are hardcoded to something average for now. The heuristic tries to have around as many cubes as SMs, then the largest amount of tensor cores. For large inputs, it will fix the number of tensor cores to its max and potentially way more cubes than SMs. But for smaller inputs it may choose to use less tensor cores to maximize SM occupancy.

There are also some refactors around launching and advanced configs.

Comment on lines +50 to +122
(16, 16) => match stage_size_m_n {
1 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S1x1x2, Accelerated16x16x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
2 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S2x2x2, Accelerated16x16x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
4 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S4x4x2, Accelerated16x16x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
8 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S8x8x2, Accelerated16x16x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
_ => panic!("No configuration found for this stage size. "),
},
(32, 8) => match stage_size_m_n {
1 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S1x1x2, Accelerated32x8x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
2 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S2x2x2, Accelerated32x8x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
4 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S4x4x2, Accelerated32x8x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
8 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S8x8x2, Accelerated32x8x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
_ => panic!("No configuration found for this stage size. "),
},
(8, 32) => match stage_size_m_n {
1 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S1x1x2, Accelerated8x32x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
2 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S2x2x2, Accelerated8x32x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
4 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S4x4x2, Accelerated8x32x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
8 => matmul_cube_preparation::<
R,
EG,
StandardAlgorithm<EG, ES, EA, S8x8x2, Accelerated8x32x16<ES, EA>>,
>(client, lhs, rhs, out, problem),
_ => panic!("No configuration found for this stage size. "),
},
_ => panic!("No configuration found for instruction shapes."),
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this can be macros, it's pattern matching so that might be cleaner in a way, very optional.

@nathanielsimard nathanielsimard merged commit 630f1e7 into main Nov 27, 2024
5 checks passed
@nathanielsimard nathanielsimard deleted the matmul/selector branch November 27, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants