-
Notifications
You must be signed in to change notification settings - Fork 641
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland #18804 including main...ScottTodd:iree:ireegpu-api-fixes but also with (currently) a hack for exposing symbols in `compiler/src/iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUAttrs.cpp`. TODO - [x] decide/find the right way to expose symbols in `IREEGPUAttrs.cpp` on windows (alternatively move those C APIs) EDIT: moved C wrappers to `compiler/src/iree/compiler/API/Internal/IREEGPUDialectCAPI.cpp`. win CI job: https://github.com/iree-org/iree/actions/runs/11411731188 --------- Signed-off-by: Maksim Levental <maksim.levental@gmail.com>
- Loading branch information
1 parent
556c945
commit 66342ab
Showing
22 changed files
with
524 additions
and
17 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
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,59 @@ | ||
// Copyright 2024 The IREE Authors | ||
// | ||
// 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 IREE_COMPILER_DIALECTS_IREE_GPU_H | ||
#define IREE_COMPILER_DIALECTS_IREE_GPU_H | ||
|
||
#include "mlir-c/IR.h" | ||
#include "mlir-c/Support.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
enum ireeGPUReorderWorkgroupsStrategyEnum { | ||
ireeGPUReorderWorkgroupsStrategyEnumNone = 0, | ||
ireeGPUReorderWorkgroupsStrategyEnumSwizzle = 1, | ||
ireeGPUReorderWorkgroupsStrategyEnumTranspose = 2, | ||
}; | ||
|
||
MLIR_CAPI_EXPORTED bool | ||
ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr(MlirAttribute attr); | ||
|
||
MLIR_CAPI_EXPORTED MlirTypeID | ||
ireeGPUReorderWorkgroupsStrategyAttrGetTypeID(void); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute ireeGPUReorderWorkgroupsStrategyAttrGet( | ||
MlirContext mlirCtx, ireeGPUReorderWorkgroupsStrategyEnum value); | ||
|
||
MLIR_CAPI_EXPORTED ireeGPUReorderWorkgroupsStrategyEnum | ||
ireeGPUReorderWorkgroupsStrategyAttrGetValue(MlirAttribute attr); | ||
|
||
MLIR_CAPI_EXPORTED | ||
bool ireeAttributeIsAGPUPipelineOptionsAttr(MlirAttribute attr); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute | ||
ireeGPUPipelineOptionsAttrGet(MlirContext mlirCtx, bool *prefetchSharedMemory, | ||
bool *noReduceSharedMemoryBankConflicts, | ||
MlirAttribute *reorderWorkgroupsStrategy); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute | ||
ireeGPUPipelineOptionsAttrGetPrefetchSharedMemory(MlirAttribute attr); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute | ||
ireeGPUPipelineOptionsAttrGetNoReduceSharedMemoryBankConflicts( | ||
MlirAttribute attr); | ||
|
||
MLIR_CAPI_EXPORTED MlirAttribute | ||
ireeGPUPipelineOptionsAttrGetReorderWorkgroupsStrategy(MlirAttribute attr); | ||
|
||
MLIR_CAPI_EXPORTED MlirTypeID ireeGPUPipelineOptionsAttrGetTypeID(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // IREE_COMPILER_DIALECTS_IREE_GPU_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
123 changes: 123 additions & 0 deletions
123
compiler/bindings/python/IREECompilerDialectsModule.cpp
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,123 @@ | ||
// Copyright 2024 The IREE Authors | ||
// | ||
// 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 "iree/compiler/dialects/iree_gpu.h" | ||
#include "mlir-c/BuiltinAttributes.h" | ||
#include "mlir-c/IR.h" | ||
#include "mlir/Bindings/Python/PybindAdaptors.h" | ||
|
||
namespace py = pybind11; | ||
using namespace mlir::python::adaptors; | ||
|
||
PYBIND11_MODULE(_ireeCompilerDialects, m) { | ||
m.doc() = "iree-compiler dialects python extension"; | ||
|
||
auto iree_gpu_module = | ||
m.def_submodule("iree_gpu", "iree_gpu dialect bindings"); | ||
|
||
//===-------------------------------------------------------------------===// | ||
// GPUReorderWorkgroupsStrategyAttr | ||
//===-------------------------------------------------------------------===// | ||
|
||
auto strategyEnum = | ||
py::enum_<ireeGPUReorderWorkgroupsStrategyEnum>( | ||
iree_gpu_module, "ReorderWorkgroupsStrategy", py::module_local()) | ||
.value("None_", ireeGPUReorderWorkgroupsStrategyEnumNone) | ||
.value("Swizzle", ireeGPUReorderWorkgroupsStrategyEnumSwizzle) | ||
.value("Transpose", ireeGPUReorderWorkgroupsStrategyEnumTranspose) | ||
.def( | ||
"__str__", | ||
[](ireeGPUReorderWorkgroupsStrategyEnum &self) { | ||
switch (self) { | ||
case ireeGPUReorderWorkgroupsStrategyEnumNone: | ||
return "None"; | ||
case ireeGPUReorderWorkgroupsStrategyEnumSwizzle: | ||
return "Swizzle"; | ||
case ireeGPUReorderWorkgroupsStrategyEnumTranspose: | ||
return "Transpose"; | ||
default: | ||
llvm::report_fatal_error( | ||
"unknown ReorderWorkgroupsStrategy variant"); | ||
} | ||
}, | ||
// pybind overloads are tried in the order they were registered. | ||
// As a result, enums used the default __str__ method instead of | ||
// the custom one. Adding py::prepend() fixes this issue. | ||
py::prepend()); | ||
|
||
mlir_attribute_subclass(iree_gpu_module, "ReorderWorkgroupsStrategyAttr", | ||
ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr, | ||
ireeGPUReorderWorkgroupsStrategyAttrGetTypeID) | ||
.def_classmethod( | ||
"get", | ||
[](const py::object &, ireeGPUReorderWorkgroupsStrategyEnum value, | ||
MlirContext ctx) { | ||
return ireeGPUReorderWorkgroupsStrategyAttrGet(ctx, value); | ||
}, | ||
"cls"_a, "value"_a, "ctx"_a = py::none(), | ||
"Gets a gpu.reorder_workgroups_strategy from parameters.") | ||
.def_property_readonly( | ||
"value", | ||
[](MlirAttribute self) -> ireeGPUReorderWorkgroupsStrategyEnum { | ||
return ireeGPUReorderWorkgroupsStrategyAttrGetValue(self); | ||
}); | ||
|
||
//===-------------------------------------------------------------------===// | ||
// GPUPipelineOptionsAttr | ||
//===-------------------------------------------------------------------===// | ||
|
||
mlir_attribute_subclass(iree_gpu_module, "PipelineOptionsAttr", | ||
ireeAttributeIsAGPUPipelineOptionsAttr, | ||
ireeGPUPipelineOptionsAttrGetTypeID) | ||
.def_classmethod( | ||
"get", | ||
[](const py::object &, std::optional<bool> prefetchSharedMemory, | ||
std::optional<bool> noReduceSharedMemoryBankConflicts, | ||
std::optional<MlirAttribute> reorderWorkgroupsStrategy, | ||
MlirContext ctx) { | ||
return ireeGPUPipelineOptionsAttrGet( | ||
ctx, | ||
prefetchSharedMemory.has_value() ? &*prefetchSharedMemory | ||
: nullptr, | ||
noReduceSharedMemoryBankConflicts.has_value() | ||
? &*noReduceSharedMemoryBankConflicts | ||
: nullptr, | ||
reorderWorkgroupsStrategy.has_value() | ||
? &*reorderWorkgroupsStrategy | ||
: nullptr); | ||
}, | ||
"cls"_a, "prefetch_shared_memory"_a = py::none(), | ||
"no_reduce_shared_memory_bank_conflicts"_a = py::none(), | ||
"reorder_workgroups_strategy"_a = py::none(), py::kw_only(), | ||
"ctx"_a = py::none(), "Gets a gpu.pipeline_options from parameters.") | ||
.def_property_readonly( | ||
"prefetch_shared_memory", | ||
[](MlirAttribute self) -> std::optional<bool> { | ||
auto attr = ireeGPUPipelineOptionsAttrGetPrefetchSharedMemory(self); | ||
if (!mlirAttributeIsNull(attr)) | ||
return mlirBoolAttrGetValue(attr); | ||
return std::nullopt; | ||
}) | ||
.def_property_readonly( | ||
"no_reduce_shared_memory_bank_conflicts", | ||
[](MlirAttribute self) -> std::optional<bool> { | ||
auto attr = | ||
ireeGPUPipelineOptionsAttrGetNoReduceSharedMemoryBankConflicts( | ||
self); | ||
if (!mlirAttributeIsNull(attr)) | ||
return mlirBoolAttrGetValue(attr); | ||
return std::nullopt; | ||
}) | ||
.def_property_readonly( | ||
"reorder_workgroups_strategy", | ||
[](MlirAttribute self) -> std::optional<MlirAttribute> { | ||
auto attr = | ||
ireeGPUPipelineOptionsAttrGetReorderWorkgroupsStrategy(self); | ||
if (!mlirAttributeIsNull(attr)) | ||
return attr; | ||
return std::nullopt; | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
compiler/bindings/python/iree/compiler/dialects/IREEGPUBinding.td
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,12 @@ | ||
// Copyright 2024 The IREE Authors | ||
// | ||
// 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 PYTHON_BINDINGS_IREEGPU_OPS | ||
#define PYTHON_BINDINGS_IREEGPU_OPS | ||
|
||
include "iree/compiler/Codegen/Dialect/GPU/IR/IREEGPUOps.td" | ||
|
||
#endif // PYTHON_BINDINGS_IREEGPU_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,9 @@ | ||
# Copyright 2024 The IREE Authors | ||
# | ||
# 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 | ||
|
||
from ._iree_gpu_ops_gen import * | ||
from ._iree_gpu_enum_gen import * | ||
from .._mlir_libs._ireeCompilerDialects.iree_gpu import * |
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
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.