-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add gpu-to-vector and nvvm lowering and handle dynamic shared memory
- Loading branch information
yangxinyu
committed
Jun 23, 2024
1 parent
59c2bbb
commit 0c7ed3e
Showing
29 changed files
with
1,768 additions
and
30 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
36 changes: 36 additions & 0 deletions
36
compiler/include/byteir/Dialect/GPU/Transforms/GPUPipelining.h
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,36 @@ | ||
//===- GPUPipelining.h ---------------------------------------*--- C++-*-===// | ||
// | ||
// Copyright 2024 ByteDance Ltd. and/or its affiliates. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef BYTEIR_DIALECT_GPU_TRANSFORMS_GPUPIPELINING_H | ||
#define BYTEIR_DIALECT_GPU_TRANSFORMS_GPUPIPELINING_H | ||
|
||
#include "mlir/Pass/Pass.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include <memory> | ||
|
||
namespace mlir { | ||
namespace func { | ||
class FuncOp; | ||
} // namespace func | ||
|
||
/// Pipelining async copy and mma oprations to improve performance. | ||
std::unique_ptr<OperationPass<func::FuncOp>> | ||
createGPUPipeliningPass(int64_t stages = 0); | ||
|
||
} // namespace mlir | ||
|
||
#endif // BYTEIR_DIALECT_GPU_TRANSFORMS_GPUPIPELINING_H |
35 changes: 35 additions & 0 deletions
35
compiler/include/byteir/Dialect/GPU/Transforms/GPUVectorToGPU.h
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,35 @@ | ||
//===- GPUVectorToGPU.h --------------------------------------*--- C++ -*-===// | ||
// | ||
// Copyright 2024 ByteDance Ltd. and/or its affiliates. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef BYTEIR_DIALECT_GPU_TRANSFORMS_GPUVECTORTOGPU_H | ||
#define BYTEIR_DIALECT_GPU_TRANSFORMS_GPUVECTORTOGPU_H | ||
|
||
#include "mlir/Pass/Pass.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include <memory> | ||
|
||
namespace mlir { | ||
namespace func { | ||
class FuncOp; | ||
} // namespace func | ||
|
||
std::unique_ptr<OperationPass<func::FuncOp>> | ||
createGPUVectorToGPUPass(); | ||
|
||
} // namespace mlir | ||
|
||
#endif // BYTEIR_DIALECT_GPU_TRANSFORMS_GPUVECTORTOGPU_H |
34 changes: 34 additions & 0 deletions
34
compiler/include/byteir/Dialect/GPU/Transforms/LegalizeGPULaunch.h
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,34 @@ | ||
//===- LegalizeGPULaunch.h ---------------------------------*--- C++ -*-===// | ||
// | ||
// Copyright 2024 ByteDance Ltd. and/or its affiliates. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef BYTEIR_DIALECT_GPU_TRANSFORMS_LEGALIZEGPULAUNCH_H | ||
#define BYTEIR_DIALECT_GPU_TRANSFORMS_LEGALIZEGPULAUNCH_H | ||
|
||
#include "mlir/Pass/Pass.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include <memory> | ||
|
||
namespace mlir { | ||
namespace func { | ||
class FuncOp; | ||
} // namespace func | ||
|
||
std::unique_ptr<OperationPass<func::FuncOp>> createLegalizeGPULaunchPass(); | ||
|
||
} // namespace mlir | ||
|
||
#endif // BYTEIR_DIALECT_GPU_TRANSFORMS_LEGALIZEGPULAUNCH_H |
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
81 changes: 81 additions & 0 deletions
81
compiler/include/byteir/Dialect/MemRef/Transforms/MultiBufferExt.h
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,81 @@ | ||
//===- RemoveCopy.h -------------------------------------------*--- C++ -*-===// | ||
// | ||
// Copyright 2022 ByteDance Ltd. and/or its affiliates. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef BYTEIR_DIALECT_MEMREF_TRANSFORMS_MULTIBUFFEREXT_H | ||
#define BYTEIR_DIALECT_MEMREF_TRANSFORMS_MULTIBUFFEREXT_H | ||
|
||
#include "mlir/Support/LogicalResult.h" | ||
#include "llvm/ADT/STLFunctionalExtras.h" | ||
|
||
namespace mlir { | ||
class OpBuilder; | ||
class RewritePatternSet; | ||
class RewriterBase; | ||
class Value; | ||
class ValueRange; | ||
|
||
namespace arith { | ||
class WideIntEmulationConverter; | ||
class NarrowTypeEmulationConverter; | ||
} // namespace arith | ||
|
||
namespace memref { | ||
class AllocOp; | ||
class AllocaOp; | ||
class DeallocOp; | ||
|
||
/// Transformation to do multi-buffering/array expansion to remove dependencies | ||
/// on the temporary allocation between consecutive loop iterations. | ||
/// It returns the new allocation if the original allocation was multi-buffered | ||
/// and returns failure() otherwise. | ||
/// When `skipOverrideAnalysis`, the pass will apply the transformation | ||
/// without checking thwt the buffer is overrided at the beginning of each | ||
/// iteration. This implies that user knows that there is no data carried across | ||
/// loop iterations. Example: | ||
/// ``` | ||
/// %0 = memref.alloc() : memref<4x128xf32> | ||
/// scf.for %iv = %c1 to %c1024 step %c3 { | ||
/// memref.copy %1, %0 : memref<4x128xf32> to memref<4x128xf32> | ||
/// "some_use"(%0) : (memref<4x128xf32>) -> () | ||
/// } | ||
/// ``` | ||
/// into: | ||
/// ``` | ||
/// %0 = memref.alloc() : memref<5x4x128xf32> | ||
/// scf.for %iv = %c1 to %c1024 step %c3 { | ||
/// %s = arith.subi %iv, %c1 : index | ||
/// %d = arith.divsi %s, %c3 : index | ||
/// %i = arith.remsi %d, %c5 : index | ||
/// %sv = memref.subview %0[%i, 0, 0] [1, 4, 128] [1, 1, 1] : | ||
/// memref<5x4x128xf32> to memref<4x128xf32, strided<[128, 1], offset: ?>> | ||
/// memref.copy %1, %sv : memref<4x128xf32> to memref<4x128xf32, strided<...>> | ||
/// "some_use"(%sv) : (memref<4x128xf32, strided<...>) -> () | ||
/// } | ||
/// ``` | ||
template <typename AllocOpType> | ||
FailureOr<AllocOpType> multiBufferExt(RewriterBase &rewriter, | ||
AllocOpType allocOp, unsigned multiplier, | ||
bool skipOverrideAnalysis = false); | ||
/// Call into `multiBuffer` with locally constructed IRRewriter. | ||
template <typename AllocOpType> | ||
FailureOr<AllocOpType> multiBufferExt(AllocOpType allocOp, unsigned multiplier, | ||
bool skipOverrideAnalysis = false); | ||
|
||
} // namespace memref | ||
} // namespace mlir | ||
|
||
#endif // BYTEIR_DIALECT_MEMREF_TRANSFORMS_MULTIBUFFEREXT_H |
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,88 @@ | ||
//===- GemmCodegen.h -----------------------------------------*--- C++ -*-===// | ||
// | ||
// Copyright 2022 ByteDance Ltd. and/or its affiliates. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef BYTEIR_PIPELINES_GPU_GEMM_CODEGEN_H | ||
#define BYTEIR_PIPELINES_GPU_GEMM_CODEGEN_H | ||
|
||
#include "mlir/Pass/PassManager.h" | ||
#include "mlir/Pass/PassOptions.h" | ||
#include "mlir/Pass/PassRegistry.h" | ||
|
||
namespace mlir { | ||
|
||
struct GPUGemmCodegenConfigOptions | ||
: public PassPipelineOptions<GPUGemmCodegenConfigOptions> { | ||
Option<std::string> funcAnchor{ | ||
*this, "func-anchor", | ||
llvm::cl::desc( | ||
"An optional Unit attribute anchoring on target functions."), | ||
llvm::cl::init("")}; | ||
Option<std::string> annotatePrefix{ | ||
*this, "annotate-prefix", | ||
llvm::cl::desc("An optional annotate prefix attribute on target ops."), | ||
llvm::cl::init("__byteir_gpu_tile_gemm")}; | ||
ListOption<int64_t> tileSizeConfig{ | ||
*this, "tile-size-config", | ||
llvm::cl::desc("An optional tile size config for tile matmul op.")}; | ||
ListOption<int64_t> workgroupSize{ | ||
*this, "workgroup-size", | ||
llvm::cl::desc("An optional workgroup size config for tile matmul op.")}; | ||
Option<int64_t> stages{ | ||
*this, "stages", llvm::cl::desc("An optional stages for tile matmul op."), | ||
llvm::cl::init(3)}; | ||
}; | ||
|
||
struct GPUGemmGeneralOptions | ||
: public PassPipelineOptions<GPUGemmGeneralOptions> { | ||
Option<std::string> funcAnchor{ | ||
*this, "func-anchor", | ||
llvm::cl::desc( | ||
"An optional Unit attribute anchoring on target functions."), | ||
llvm::cl::init("")}; | ||
Option<std::string> annotatePrefix{ | ||
*this, "annotate-prefix", | ||
llvm::cl::desc("An optional annotate prefix attribute on target ops."), | ||
llvm::cl::init("__byteir_gpu_tile_gemm")}; | ||
}; | ||
|
||
void createGPUTileGemmTransform(OpPassManager &pm, | ||
const GPUGemmGeneralOptions &options); | ||
|
||
void createGPUAddGemmCodegenLoweringConfigTransform( | ||
OpPassManager &pm, const GPUGemmCodegenConfigOptions &options); | ||
|
||
void createGPUPipeliningTransform(OpPassManager &pm, | ||
const GPUGemmGeneralOptions &options); | ||
|
||
inline void registerGPUGemmCodegenPipelines() { | ||
PassPipelineRegistration<GPUGemmGeneralOptions>( | ||
"insert-gpu-tile-gemm-transform", | ||
"Insert transformation IR to tile linalg matmul op", | ||
createGPUTileGemmTransform); | ||
PassPipelineRegistration<GPUGemmCodegenConfigOptions>( | ||
"insert-gpu-gemm-codegen-transform", | ||
"Insert transformation IR to tile linalg matmul op", | ||
createGPUAddGemmCodegenLoweringConfigTransform); | ||
PassPipelineRegistration<GPUGemmGeneralOptions>( | ||
"insert-gpu-pipelining-transform", | ||
"Insert transformation IR to tile linalg matmul op", | ||
createGPUPipeliningTransform); | ||
} | ||
|
||
} // namespace mlir | ||
|
||
#endif // BYTEIR_PIPELINES_GPU_GEMM_CODEGEN_H |
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.