-
Notifications
You must be signed in to change notification settings - Fork 146
[CIR][Dialect] Emit OpenCL kernel metadata #705
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,95 @@ | ||
//===- CIROpenCLAttrs.td - CIR dialect attrs for OpenCL ----*- tablegen -*-===// | ||
// | ||
// Part of the LLVM Project, 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 file declares the CIR dialect attributes for OpenCL. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_CIR_DIALECT_CIR_OPENCL_ATTRS | ||
#define MLIR_CIR_DIALECT_CIR_OPENCL_ATTRS | ||
|
||
//===----------------------------------------------------------------------===// | ||
// OpenCLKernelMetadataAttr | ||
//===----------------------------------------------------------------------===// | ||
|
||
def OpenCLKernelMetadataAttr | ||
: CIR_Attr<"OpenCLKernelMetadata", "cl.kernel_metadata"> { | ||
|
||
let summary = "OpenCL kernel metadata"; | ||
let description = [{ | ||
Provide the required information of an OpenCL kernel for the SPIR-V backend. | ||
|
||
The `work_group_size_hint` and `reqd_work_group_size` parameter are integer | ||
arrays with 3 elements that provide hints for the work-group size and the | ||
required work-group size, respectively. | ||
|
||
The `vec_type_hint` parameter is a type attribute that provides a hint for | ||
the vectorization. It can be a CIR or LLVM type, depending on the lowering | ||
stage. | ||
|
||
The `vec_type_hint_signedness` parameter is a boolean that indicates the | ||
signedness of the vector type hint. It's useful when LLVM type is set in | ||
`vec_type_hint`, which is signless by design. It should be set if and only | ||
if the `vec_type_hint` is present. | ||
|
||
The `intel_reqd_sub_group_size` parameter is an integer that restricts the | ||
sub-group size to the specified value. | ||
|
||
Example: | ||
``` | ||
#fn_attr = #cir<extra({cl.kernel_metadata = #cir.cl.kernel_metadata< | ||
work_group_size_hint = [8 : i32, 16 : i32, 32 : i32], | ||
reqd_work_group_size = [1 : i32, 2 : i32, 4 : i32], | ||
vec_type_hint = !s32i, | ||
vec_type_hint_signedness = 1, | ||
intel_reqd_sub_group_size = 8 : i32 | ||
>})> | ||
|
||
cir.func @kernel(%arg0: !s32i) extra(#fn_attr) { | ||
cir.return | ||
} | ||
``` | ||
}]; | ||
|
||
let parameters = (ins | ||
OptionalParameter<"ArrayAttr">:$work_group_size_hint, | ||
OptionalParameter<"ArrayAttr">:$reqd_work_group_size, | ||
OptionalParameter<"TypeAttr">:$vec_type_hint, | ||
OptionalParameter<"std::optional<bool>">:$vec_type_hint_signedness, | ||
OptionalParameter<"IntegerAttr">:$intel_reqd_sub_group_size | ||
); | ||
|
||
let assemblyFormat = "`<` struct(params) `>`"; | ||
|
||
let genVerifyDecl = 1; | ||
|
||
let extraClassDeclaration = [{ | ||
/// Extract the signedness from int or int vector types. | ||
static std::optional<bool> isSignedHint(mlir::Type vecTypeHint); | ||
}]; | ||
|
||
let extraClassDefinition = [{ | ||
std::optional<bool> $cppClass::isSignedHint(mlir::Type hintQTy) { | ||
// Only types in CIR carry signedness | ||
if (!mlir::isa<mlir::cir::CIRDialect>(hintQTy.getDialect())) | ||
return std::nullopt; | ||
|
||
// See also clang::CodeGen::CodeGenFunction::EmitKernelMetadata | ||
auto hintEltQTy = mlir::dyn_cast<mlir::cir::VectorType>(hintQTy); | ||
auto isCIRSignedIntType = [](mlir::Type t) { | ||
return mlir::isa<mlir::cir::IntType>(t) && | ||
mlir::cast<mlir::cir::IntType>(t).isSigned(); | ||
}; | ||
return isCIRSignedIntType(hintQTy) || | ||
(hintEltQTy && isCIRSignedIntType(hintEltQTy.getEltType())); | ||
} | ||
}]; | ||
|
||
} | ||
|
||
#endif // MLIR_CIR_DIALECT_CIR_OPENCL_ATTRS |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.