-
Notifications
You must be signed in to change notification settings - Fork 16
Initial GPU pipeline #202
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
Open
kurapov-peter
wants to merge
19
commits into
main
Choose a base branch
from
pakurapo/gpu-module-legalize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Initial GPU pipeline #202
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
492d525
Add gc-gpu-legalize-module pass
kurapov-peter f8b665e
Add gc-gpu-signatures-to-llvm pass
kurapov-peter 7f8c611
Add gen dialect to hold the gen target
kurapov-peter fa3ba4b
Add gen target and a lowering pipeline through gpu-module-to-binary
kurapov-peter 59d586b
Add ocloc integration
kurapov-peter dbeb704
Add gpu pipeline registration
kurapov-peter 6ee3d0b
Fix typo
kurapov-peter 9291855
Fix static gc-opt build & add comments for components registration
kurapov-peter 3cbebc1
Fix warnings
kurapov-peter 8193d65
Disable clang-tidy on the attribute definition
kurapov-peter 643f363
Fix licences
kurapov-peter 2013270
Move xegpu pass to imex-only build
kurapov-peter 3f7a71a
Fix python CAPI linkage
kurapov-peter ec17d13
fixup! Fix python CAPI linkage
kurapov-peter ce9e66f
Fix merge issues
kurapov-peter 09e8321
Fix GCExecutionEngineTests linkage
kurapov-peter c51053c
Add SPIRVCodeGen dependency to the gen target
kurapov-peter eefddb6
Revert "Add SPIRVCodeGen dependency to the gen target"
kurapov-peter c2b485e
Add LLVMSPIRVCodeGen dependency
kurapov-peter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,6 @@ | ||
add_mlir_dialect(GenOps gen) | ||
add_mlir_doc(GenOps GENDialect Dialects/ -gen-dialect-doc -dialect=gen) | ||
set(LLVM_TARGET_DEFINITIONS GenOps.td) | ||
mlir_tablegen(GenOpsAttributes.h.inc -gen-attrdef-decls -attrdefs-dialect=gen) | ||
mlir_tablegen(GenOpsAttributes.cpp.inc -gen-attrdef-defs -attrdefs-dialect=gen) | ||
add_public_tablegen_target(MLIRGENConversionsIncGen) |
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,22 @@ | ||
//===-- GENDialect.h - MLIR GEN target definitions --------------*- C++ -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_LLVMIR_GENDIALECT_H_ | ||
#define MLIR_DIALECT_LLVMIR_GENDIALECT_H_ | ||
|
||
#include "mlir/Bytecode/BytecodeOpInterface.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
#include "mlir/IR/Dialect.h" | ||
#include "mlir/IR/OpDefinition.h" | ||
|
||
#define GET_ATTRDEF_CLASSES | ||
#include "gc/Dialect/LLVMIR/GenOpsAttributes.h.inc" | ||
|
||
#include "gc/Dialect/LLVMIR/GenOpsDialect.h.inc" | ||
|
||
#endif /* MLIR_DIALECT_LLVMIR_XEDEFS_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,75 @@ | ||
//===-- GenOps.td - Gen dialect definition -----------------*- tablegen -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#ifndef GENIR_OPS | ||
#define GENIR_OPS | ||
|
||
include "mlir/Dialect/GPU/IR/CompilationAttrInterfaces.td" | ||
include "mlir/Dialect/LLVMIR/LLVMOpBase.td" | ||
include "mlir/Dialect/SPIRV/IR/SPIRVBase.td" | ||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||
|
||
def GEN_Dialect : Dialect { | ||
let name = "gen"; | ||
let cppNamespace = "::mlir::gen"; | ||
let dependentDialects = ["LLVM::LLVMDialect"]; | ||
let hasOperationAttrVerify = 1; | ||
|
||
let extraClassDeclaration = [{ | ||
/// Get the name of the attribute used to annotate external kernel | ||
/// functions. | ||
static StringRef getKernelFuncAttrName() { return "gen.kernel"; } | ||
/// The address space value that represents global memory. | ||
static constexpr unsigned kGlobalMemoryAddressSpace = 1; | ||
/// The address space value that represents shared memory. | ||
static constexpr unsigned kSharedMemoryAddressSpace = 3; | ||
/// The address space value that represents private memory. | ||
static constexpr unsigned kPrivateMemoryAddressSpace = 0; | ||
}]; | ||
|
||
let useDefaultAttributePrinterParser = 1; | ||
} | ||
|
||
class GEN_Attr<string attrName, string attrMnemonic, list<Trait> traits = []> | ||
: AttrDef<GEN_Dialect, attrName, traits> { | ||
let mnemonic = attrMnemonic; | ||
} | ||
|
||
def GEN_TargettAttr : GEN_Attr<"GenTarget", "target"> { | ||
let description = [{ | ||
GPU target attribute for controlling compilation of targets. All | ||
parameters decay into default values if not present. | ||
|
||
Examples: | ||
|
||
1. Target with default values. | ||
``` | ||
gpu.module @mymodule [#gen.target] attributes {...} { | ||
... | ||
} | ||
``` | ||
}]; | ||
let parameters = (ins | ||
DefaultValuedParameter<"int", "2", "Optimization level to apply.">:$O, | ||
StringRefParameter<"Target triple.", "\"spirv64-unknown-unknown\"">:$triple, | ||
StringRefParameter<"Target chip.", "\"pvc\"">:$chip | ||
); | ||
let assemblyFormat = [{ | ||
(`<` struct($O, $triple, $chip)^ `>`)? | ||
}]; | ||
let builders = [ | ||
AttrBuilder<(ins CArg<"int", "2">:$optLevel, | ||
CArg<"StringRef", "\"spirv64-unknown-unknown\"">:$triple, | ||
CArg<"StringRef", "\"pvc\"">:$chip), [{ | ||
return Base::get($_ctxt, optLevel, triple, chip); | ||
}]> | ||
]; | ||
let skipDefaultBuilders = 1; | ||
let genVerifyDecl = 1; | ||
} | ||
|
||
#endif // GENIR_OPS |
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,30 @@ | ||
//===-- Target.h - MLIR GEN target registration -----------------*- C++ -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This provides registration calls for attaching the Gen target interface. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_TARGET_GEN_TARGET_H | ||
#define MLIR_TARGET_GEN_TARGET_H | ||
|
||
namespace mlir { | ||
class DialectRegistry; | ||
class MLIRContext; | ||
namespace gen { | ||
/// Registers the `TargetAttrInterface` for the `#gen.target` attribute in | ||
/// the given registry. | ||
void registerGenTargetInterfaceExternalModels(DialectRegistry ®istry); | ||
|
||
/// Registers the `TargetAttrInterface` for the `#gen.target` attribute in | ||
/// the registry associated with the given context. | ||
void registerGenTargetInterfaceExternalModels(MLIRContext &context); | ||
} // namespace gen | ||
} // namespace mlir | ||
|
||
#endif // MLIR_TARGET_GEN_TARGET_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,53 @@ | ||
//===-- Utils.h - MLIR GEN target utils -------------------------*- C++ -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This files declares GEN target related utility classes and functions. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_TARGET_LLVM_GEN_UTILS_H | ||
#define MLIR_TARGET_LLVM_GEN_UTILS_H | ||
|
||
#include "gc/Dialect/LLVMIR/GENDialect.h" | ||
#include "mlir/Dialect/GPU/IR/CompilationInterfaces.h" | ||
#include "mlir/Target/LLVM/ModuleToObject.h" | ||
|
||
namespace mlir { | ||
namespace gen { | ||
|
||
StringRef getONEAPIToolkitPath(); | ||
|
||
/// Base class for all GEN serializations from GPU modules into binary strings. | ||
/// By default this class serializes into LLVM bitcode. | ||
class SerializeGPUModuleBase : public LLVM::ModuleToObject { | ||
public: | ||
/// Initializes the `toolkitPath` with the path in `targetOptions` or if empty | ||
/// with the path in `getONEAPIToolkitPath`. | ||
SerializeGPUModuleBase(Operation &module, GenTargetAttr target, | ||
const gpu::TargetOptions &targetOptions = {}); | ||
|
||
// Initialize intermediate spirv target llvm backend | ||
static void init(); | ||
|
||
/// Returns the target attribute. | ||
GenTargetAttr getTarget() const; | ||
|
||
/// Returns the ONEAPI toolkit path. | ||
StringRef getToolkitPath() const; | ||
|
||
protected: | ||
/// GEN target attribute. | ||
GenTargetAttr target; | ||
|
||
/// ONEAPI toolkit path. | ||
std::string toolkitPath; | ||
}; | ||
} // namespace gen | ||
} // namespace mlir | ||
|
||
#endif // MLIR_TARGET_LLVM_GEN_UTILS_H |
31 changes: 31 additions & 0 deletions
31
include/gc/Target/LLVMIR/Dialect/GEN/GENToLLVMIRTranslation.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,31 @@ | ||
//===-- GENToLLVMIRTranslation.h - GEN to LLVM IR ---------------*- C++ -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This provides registration calls for GEN dialect to LLVM IR translation. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_TARGET_LLVMIR_DIALECT_GEN_GENTOLLVMIRTRANSLATION_H | ||
#define MLIR_TARGET_LLVMIR_DIALECT_GEN_GENTOLLVMIRTRANSLATION_H | ||
|
||
namespace mlir { | ||
|
||
class DialectRegistry; | ||
class MLIRContext; | ||
|
||
/// Register the GEN dialect and the translation from it to the LLVM IR in the | ||
/// given registry; | ||
void registerGENDialectTranslation(DialectRegistry ®istry); | ||
|
||
/// Register the GEN dialect and the translation from it in the registry | ||
/// associated with the given context. | ||
void registerGENDialectTranslation(MLIRContext &context); | ||
|
||
} // namespace mlir | ||
|
||
#endif // MLIR_TARGET_LLVMIR_DIALECT_GEN_GENTOLLVMIRTRANSLATION_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
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 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -18,6 +18,7 @@ using namespace mlir::cpuruntime; | |||||||||
|
||||||||||
namespace mlir::gc { | ||||||||||
void registerCPUPipeline(); | ||||||||||
void registerGPUPipeline(); | ||||||||||
} // namespace mlir::gc | ||||||||||
|
||||||||||
#ifdef __cplusplus | ||||||||||
|
@@ -29,6 +30,7 @@ extern "C" { | |||||||||
|
||||||||||
MLIR_CAPI_EXPORTED void mlirRegisterAllGCPassesAndPipelines() { | ||||||||||
registerCPUPipeline(); | ||||||||||
registerGPUPipeline(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
mlirRegisterCPURuntimePasses(); | ||||||||||
mlirRegisterGraphCompilerPasses(); | ||||||||||
} | ||||||||||
|
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
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,20 @@ | ||
gc_add_mlir_dialect_library(MLIRGENDialect | ||
IR/GENDialect.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR | ||
${PROJECT_SOURCE_DIR}/include/gc/Dialect/LLVMIR | ||
|
||
DEPENDS | ||
MLIRGENConversionsIncGen | ||
|
||
LINK_COMPONENTS | ||
AsmParser | ||
Core | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRIR | ||
MLIRLLVMDialect | ||
MLIRSideEffectInterfaces | ||
GcInterface | ||
) |
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 @@ | ||
//===-- GENDialect.cpp - GEN Attrs and dialect registration -----*- C++ -*-===// | ||
// | ||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
#include "gc/Dialect/LLVMIR/GENDialect.h" | ||
|
||
#include "mlir/Dialect/GPU/IR/CompilationInterfaces.h" | ||
#include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
#include "mlir/IR/DialectImplementation.h" | ||
#include "llvm/ADT/TypeSwitch.h" | ||
|
||
using namespace mlir; | ||
using namespace gen; | ||
|
||
#include "gc/Dialect/LLVMIR/GenOpsDialect.cpp.inc" | ||
|
||
LogicalResult | ||
GenTargetAttr::verify(function_ref<InFlightDiagnostic()> emitError, int O, | ||
StringRef triple, StringRef chip) { | ||
if (O < 0 || O > 3) { | ||
emitError() << "The optimization level must be a number between 0 and 3."; | ||
return failure(); | ||
} | ||
if (triple.empty()) { | ||
emitError() << "The target triple cannot be empty."; | ||
return failure(); | ||
} | ||
if (chip.empty()) { | ||
emitError() << "The target chip cannot be empty."; | ||
return failure(); | ||
} | ||
return success(); | ||
} | ||
|
||
LogicalResult GENDialect::verifyOperationAttribute(Operation *op, | ||
NamedAttribute attr) { | ||
return success(); | ||
} | ||
|
||
void GENDialect::initialize() { | ||
// clang-tidy is confused by the registration mechanism | ||
// NOLINTBEGIN | ||
addAttributes< | ||
#define GET_ATTRDEF_LIST | ||
#include "gc/Dialect/LLVMIR/GenOpsAttributes.cpp.inc" | ||
>(); | ||
// NOLINTEND | ||
|
||
allowUnknownOperations(); | ||
declarePromisedInterface<gpu::TargetAttrInterface, GenTargetAttr>(); | ||
} | ||
|
||
#define GET_ATTRDEF_CLASSES | ||
#include "gc/Dialect/LLVMIR/GenOpsAttributes.cpp.inc" |
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,2 @@ | ||
add_subdirectory(LLVMIR) | ||
add_subdirectory(LLVM) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.