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

Outline to GPU launch before further lowering #971

Merged
merged 2 commits into from
Oct 3, 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
10 changes: 5 additions & 5 deletions lib/TPP/GPU/GpuConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ struct GpuConversion : public tpp::impl::GpuConversionBase<GpuConversion>,

private:
void constructPipeline() override {
// Map loops into GPU kernels.
pm.addNestedPass<func::FuncOp>(createGpuMapParallelLoopsPass());
pm.addNestedPass<func::FuncOp>(createParallelLoopToGpuPass());
pm.addPass(createCleanup());

// First lower linalg using custom patterns then fall back to
// the default lowering for any remaining ops.
pm.addNestedPass<func::FuncOp>(createLinalgDeGeneralize());
Expand All @@ -64,11 +69,6 @@ struct GpuConversion : public tpp::impl::GpuConversionBase<GpuConversion>,
createLinalgToXeGPU(LinalgToXeGPUOptions{kTile, stages, dpasTile}));
}
pm.addNestedPass<func::FuncOp>(createConvertLinalgToLoopsPass());

// Map loops into GPU kernels.
pm.addNestedPass<func::FuncOp>(createGpuMapParallelLoopsPass());
pm.addNestedPass<func::FuncOp>(createParallelLoopToGpuPass());

pm.addPass(createCleanup());

// Create GPU kernels.
Expand Down
7 changes: 3 additions & 4 deletions lib/TPP/GPU/LinalgToXeGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ static FailureOr<SmallVector<int64_t>> getStaticBlockSizes(Operation *op) {
return std::nullopt;
};

if (auto launchOp = dyn_cast<gpu::LaunchOp>(op)) {
if (auto launchOp = op->getParentOfType<gpu::LaunchOp>()) {
auto sizeX = getConstVal(launchOp.getBlockSizeX());
auto sizeY = getConstVal(launchOp.getBlockSizeY());
auto sizeZ = getConstVal(launchOp.getBlockSizeZ());
Expand All @@ -398,7 +398,7 @@ static FailureOr<SmallVector<int64_t>> getStaticBlockSizes(Operation *op) {
// TODO: Remove when the lowering only occurs within a gpu.launch op.
// Manually computing this is brittle and duplicated parallel
// loops to gpu conversion.
if (auto blockLoop = dyn_cast<scf::ParallelOp>(op)) {
if (auto blockLoop = op->getParentOfType<scf::ParallelOp>()) {
auto gridLoop = blockLoop->getParentOfType<scf::ParallelOp>();

// Blocks or number of threads are represented by the first parallel loop
Expand Down Expand Up @@ -934,8 +934,7 @@ static LogicalResult createDPASKernel(linalg::LinalgOp linalgOp,

// Create input prefetch tiles.
int64_t numThreads = 1;
auto blockDims =
getStaticBlockSizes(linalgOp->getParentOfType<scf::ParallelOp>());
auto blockDims = getStaticBlockSizes(linalgOp);
if (succeeded(blockDims)) {
numThreads = std::accumulate(blockDims->begin(), blockDims->end(), 1,
std::multiplies<int64_t>());
Expand Down