Skip to content

Commit

Permalink
fix symbol problem on windows
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Levental <maksim.levental@gmail.com>
  • Loading branch information
makslevental committed Oct 19, 2024
1 parent 868bc4c commit a60fd6c
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 110 deletions.
1 change: 1 addition & 0 deletions compiler/src/iree/compiler/API/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set(_EXPORT_OBJECT_LIBS
obj.MLIRCAPITransformDialectTransforms
iree_compiler_API_Internal_CompilerDriver.objects
iree_compiler_API_Internal_IREECompileToolEntryPoint.objects
iree_compiler_API_Internal_IREEGPUDialectCAPI.objects
iree_compiler_API_Internal_IREEMLIRLSPServerToolEntryPoint.objects
iree_compiler_API_Internal_IREEOptToolEntryPoint.objects
iree_compiler_API_Internal_IREEReduceToolEntryPoint.objects
Expand Down
13 changes: 13 additions & 0 deletions compiler/src/iree/compiler/API/Internal/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,16 @@ iree_compiler_cc_library(
"@llvm-project//mlir:Support",
],
)

iree_compiler_cc_library(
name = "IREEGPUDialectCAPI",
srcs = [
"IREEGPUDialectCAPI.cpp",
],
deps = [
"//compiler/bindings/c:headers",
"//compiler/src/iree/compiler/Codegen/Dialect/GPU/IR:IREEGPUDialect",
"@llvm-project//mlir:CAPIIR",
"@llvm-project//mlir:CAPIIRHeaders",
],
)
13 changes: 13 additions & 0 deletions compiler/src/iree/compiler/API/Internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ iree_cc_library(
PUBLIC
)

iree_cc_library(
NAME
IREEGPUDialectCAPI
SRCS
"IREEGPUDialectCAPI.cpp"
DEPS
IREELLVMIncludeSetup
MLIRCAPIIR
iree::compiler::Codegen::Dialect::GPU::IR::IREEGPUDialect
iree::compiler::bindings::c::headers
PUBLIC
)

### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###

set(_lld_copts)
Expand Down
120 changes: 120 additions & 0 deletions compiler/src/iree/compiler/API/Internal/IREEGPUDialectCAPI.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// 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/Codegen/Dialect/GPU/IR/IREEGPUAttrs.h"
#include "iree/compiler/dialects/iree_gpu.h"
#include "mlir-c/IR.h"
#include "mlir/CAPI/IR.h"
#include "mlir/CAPI/Support.h"

bool ireeAttributeIsAGPUPipelineOptionsAttr(MlirAttribute attr) {
return llvm::isa<mlir::iree_compiler::IREE::GPU::GPUPipelineOptionsAttr>(
unwrap(attr));
}

MlirAttribute
ireeGPUPipelineOptionsAttrGet(MlirContext mlirCtx, bool *prefetchSharedMemory,
bool *noReduceSharedMemoryBankConflicts,
MlirAttribute *reorderWorkgroupsStrategy) {
mlir::MLIRContext *ctx = unwrap(mlirCtx);
mlir::Builder b(ctx);
auto prefetchSharedMemoryAttr = mlir::BoolAttr();
if (prefetchSharedMemory) {
prefetchSharedMemoryAttr = b.getBoolAttr(*prefetchSharedMemory);
}
auto noReduceSharedMemoryBankConflictsAttr = mlir::BoolAttr();
if (noReduceSharedMemoryBankConflicts) {
noReduceSharedMemoryBankConflictsAttr =
b.getBoolAttr(*noReduceSharedMemoryBankConflicts);
}
auto strategyAttr =
mlir::iree_compiler::IREE::GPU::ReorderWorkgroupsStrategyAttr();
if (reorderWorkgroupsStrategy) {
strategyAttr = llvm::dyn_cast<
mlir::iree_compiler::IREE::GPU::ReorderWorkgroupsStrategyAttr>(
unwrap(*reorderWorkgroupsStrategy));
}
return wrap(mlir::iree_compiler::IREE::GPU::GPUPipelineOptionsAttr::get(
ctx, prefetchSharedMemoryAttr, noReduceSharedMemoryBankConflictsAttr,
strategyAttr));
}

MlirAttribute
ireeGPUPipelineOptionsAttrGetPrefetchSharedMemory(MlirAttribute attr) {
auto gpuAttr =
llvm::cast<mlir::iree_compiler::IREE::GPU::GPUPipelineOptionsAttr>(
unwrap(attr));
return wrap(gpuAttr.getPrefetchSharedMemory());
}

MlirAttribute ireeGPUPipelineOptionsAttrGetNoReduceSharedMemoryBankConflicts(
MlirAttribute attr) {
auto gpuAttr =
llvm::cast<mlir::iree_compiler::IREE::GPU::GPUPipelineOptionsAttr>(
unwrap(attr));
return wrap(gpuAttr.getNoReduceSharedMemoryBankConflicts());
}

MlirAttribute
ireeGPUPipelineOptionsAttrGetReorderWorkgroupsStrategy(MlirAttribute attr) {
auto gpuAttr =
llvm::cast<mlir::iree_compiler::IREE::GPU::GPUPipelineOptionsAttr>(
unwrap(attr));
return wrap(gpuAttr.getReorderWorkgroupsStrategy());
}

MlirTypeID ireeGPUPipelineOptionsAttrGetTypeID() {
return wrap(
mlir::iree_compiler::IREE::GPU::GPUPipelineOptionsAttr::getTypeID());
}

static_assert(
static_cast<uint32_t>(ireeGPUReorderWorkgroupsStrategyEnumNone) ==
static_cast<uint32_t>(mlir::iree_compiler::IREE::GPU::
ReorderWorkgroupsStrategy::None) &&
static_cast<uint32_t>(ireeGPUReorderWorkgroupsStrategyEnumSwizzle) ==
static_cast<uint32_t>(mlir::iree_compiler::IREE::GPU::
ReorderWorkgroupsStrategy::Swizzle) &&
static_cast<uint32_t>(ireeGPUReorderWorkgroupsStrategyEnumTranspose) ==
static_cast<uint32_t>(mlir::iree_compiler::IREE::GPU::
ReorderWorkgroupsStrategy::Transpose) &&
static_cast<uint32_t>(ireeGPUReorderWorkgroupsStrategyEnumTranspose) ==
mlir::iree_compiler::IREE::GPU::
getMaxEnumValForReorderWorkgroupsStrategy(),
"ireeGPUReorderWorkgroupsStrategyEnum and "
"mlir::iree_compiler::IREE::GPU::ReorderWorkgroupsStrategy definitions "
"have diverged");

bool ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr(MlirAttribute attr) {
return llvm::isa<
mlir::iree_compiler::IREE::GPU::ReorderWorkgroupsStrategyAttr>(
unwrap(attr));
}

MlirTypeID ireeGPUReorderWorkgroupsStrategyAttrGetTypeID() {
return wrap(mlir::iree_compiler::IREE::GPU::ReorderWorkgroupsStrategyAttr::
getTypeID());
}

MlirAttribute ireeGPUReorderWorkgroupsStrategyAttrGet(
MlirContext mlirCtx, ireeGPUReorderWorkgroupsStrategyEnum value) {
mlir::MLIRContext *ctx = unwrap(mlirCtx);
return wrap(
mlir::iree_compiler::IREE::GPU::ReorderWorkgroupsStrategyAttr::get(
ctx, static_cast<
mlir::iree_compiler::IREE::GPU::ReorderWorkgroupsStrategy>(
value)));
}

ireeGPUReorderWorkgroupsStrategyEnum
ireeGPUReorderWorkgroupsStrategyAttrGetValue(MlirAttribute attr) {
assert(ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr(attr) &&
"attr is not a GPUReorderWorkgroupsStrategyAttr");
return static_cast<ireeGPUReorderWorkgroupsStrategyEnum>(
llvm::cast<mlir::iree_compiler::IREE::GPU::ReorderWorkgroupsStrategyAttr>(
unwrap(attr))
.getValue());
}
24 changes: 24 additions & 0 deletions compiler/src/iree/compiler/API/api_exports.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

// Generated by generate_exports.py: Do not edit.

// clang-format off

#include <stdint.h>

extern void ireeAttributeIsAGPUPipelineOptionsAttr();
extern void ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr();
extern void ireeCompilerEnumeratePlugins();
extern void ireeCompilerEnumerateRegisteredHALTargetBackends();
extern void ireeCompilerErrorDestroy();
Expand Down Expand Up @@ -59,6 +63,14 @@ extern void ireeCompilerSourceDestroy();
extern void ireeCompilerSourceOpenFile();
extern void ireeCompilerSourceSplit();
extern void ireeCompilerSourceWrapBuffer();
extern void ireeGPUPipelineOptionsAttrGet();
extern void ireeGPUPipelineOptionsAttrGetNoReduceSharedMemoryBankConflicts();
extern void ireeGPUPipelineOptionsAttrGetPrefetchSharedMemory();
extern void ireeGPUPipelineOptionsAttrGetReorderWorkgroupsStrategy();
extern void ireeGPUPipelineOptionsAttrGetTypeID();
extern void ireeGPUReorderWorkgroupsStrategyAttrGet();
extern void ireeGPUReorderWorkgroupsStrategyAttrGetTypeID();
extern void ireeGPUReorderWorkgroupsStrategyAttrGetValue();
extern void ireeMlirLspServerRunMain();
extern void ireeOptRunMain();
extern void ireeReduceRunMain();
Expand Down Expand Up @@ -835,6 +847,8 @@ extern void mlirVectorTypeIsScalable();

uintptr_t __iree_compiler_hidden_force_extern() {
uintptr_t x = 0;
x += (uintptr_t)&ireeAttributeIsAGPUPipelineOptionsAttr;
x += (uintptr_t)&ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr;
x += (uintptr_t)&ireeCompilerEnumeratePlugins;
x += (uintptr_t)&ireeCompilerEnumerateRegisteredHALTargetBackends;
x += (uintptr_t)&ireeCompilerErrorDestroy;
Expand Down Expand Up @@ -886,6 +900,14 @@ uintptr_t __iree_compiler_hidden_force_extern() {
x += (uintptr_t)&ireeCompilerSourceOpenFile;
x += (uintptr_t)&ireeCompilerSourceSplit;
x += (uintptr_t)&ireeCompilerSourceWrapBuffer;
x += (uintptr_t)&ireeGPUPipelineOptionsAttrGet;
x += (uintptr_t)&ireeGPUPipelineOptionsAttrGetNoReduceSharedMemoryBankConflicts;
x += (uintptr_t)&ireeGPUPipelineOptionsAttrGetPrefetchSharedMemory;
x += (uintptr_t)&ireeGPUPipelineOptionsAttrGetReorderWorkgroupsStrategy;
x += (uintptr_t)&ireeGPUPipelineOptionsAttrGetTypeID;
x += (uintptr_t)&ireeGPUReorderWorkgroupsStrategyAttrGet;
x += (uintptr_t)&ireeGPUReorderWorkgroupsStrategyAttrGetTypeID;
x += (uintptr_t)&ireeGPUReorderWorkgroupsStrategyAttrGetValue;
x += (uintptr_t)&ireeMlirLspServerRunMain;
x += (uintptr_t)&ireeOptRunMain;
x += (uintptr_t)&ireeReduceRunMain;
Expand Down Expand Up @@ -1661,3 +1683,5 @@ uintptr_t __iree_compiler_hidden_force_extern() {
x += (uintptr_t)&mlirVectorTypeIsScalable;
return x;
}

// clang-format off
10 changes: 10 additions & 0 deletions compiler/src/iree/compiler/API/api_exports.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
; Generated by generate_exports.py: Do not edit.
EXPORTS
ireeAttributeIsAGPUPipelineOptionsAttr
ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr
ireeCompilerEnumeratePlugins
ireeCompilerEnumerateRegisteredHALTargetBackends
ireeCompilerErrorDestroy
Expand Down Expand Up @@ -51,6 +53,14 @@ EXPORTS
ireeCompilerSourceOpenFile
ireeCompilerSourceSplit
ireeCompilerSourceWrapBuffer
ireeGPUPipelineOptionsAttrGet
ireeGPUPipelineOptionsAttrGetNoReduceSharedMemoryBankConflicts
ireeGPUPipelineOptionsAttrGetPrefetchSharedMemory
ireeGPUPipelineOptionsAttrGetReorderWorkgroupsStrategy
ireeGPUPipelineOptionsAttrGetTypeID
ireeGPUReorderWorkgroupsStrategyAttrGet
ireeGPUReorderWorkgroupsStrategyAttrGetTypeID
ireeGPUReorderWorkgroupsStrategyAttrGetValue
ireeMlirLspServerRunMain
ireeOptRunMain
ireeReduceRunMain
Expand Down
10 changes: 10 additions & 0 deletions compiler/src/iree/compiler/API/api_exports.ld
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by generate_exports.py: Do not edit.
VER_0 {
global:
ireeAttributeIsAGPUPipelineOptionsAttr;
ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr;
ireeCompilerEnumeratePlugins;
ireeCompilerEnumerateRegisteredHALTargetBackends;
ireeCompilerErrorDestroy;
Expand Down Expand Up @@ -52,6 +54,14 @@ VER_0 {
ireeCompilerSourceOpenFile;
ireeCompilerSourceSplit;
ireeCompilerSourceWrapBuffer;
ireeGPUPipelineOptionsAttrGet;
ireeGPUPipelineOptionsAttrGetNoReduceSharedMemoryBankConflicts;
ireeGPUPipelineOptionsAttrGetPrefetchSharedMemory;
ireeGPUPipelineOptionsAttrGetReorderWorkgroupsStrategy;
ireeGPUPipelineOptionsAttrGetTypeID;
ireeGPUReorderWorkgroupsStrategyAttrGet;
ireeGPUReorderWorkgroupsStrategyAttrGetTypeID;
ireeGPUReorderWorkgroupsStrategyAttrGetValue;
ireeMlirLspServerRunMain;
ireeOptRunMain;
ireeReduceRunMain;
Expand Down
10 changes: 10 additions & 0 deletions compiler/src/iree/compiler/API/api_exports.macos.lst
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Generated by generate_exports.py: Do not edit.
_ireeAttributeIsAGPUPipelineOptionsAttr
_ireeAttributeIsAGPUReorderWorkgroupsStrategyAttr
_ireeCompilerEnumeratePlugins
_ireeCompilerEnumerateRegisteredHALTargetBackends
_ireeCompilerErrorDestroy
Expand Down Expand Up @@ -50,6 +52,14 @@ _ireeCompilerSourceDestroy
_ireeCompilerSourceOpenFile
_ireeCompilerSourceSplit
_ireeCompilerSourceWrapBuffer
_ireeGPUPipelineOptionsAttrGet
_ireeGPUPipelineOptionsAttrGetNoReduceSharedMemoryBankConflicts
_ireeGPUPipelineOptionsAttrGetPrefetchSharedMemory
_ireeGPUPipelineOptionsAttrGetReorderWorkgroupsStrategy
_ireeGPUPipelineOptionsAttrGetTypeID
_ireeGPUReorderWorkgroupsStrategyAttrGet
_ireeGPUReorderWorkgroupsStrategyAttrGetTypeID
_ireeGPUReorderWorkgroupsStrategyAttrGetValue
_ireeMlirLspServerRunMain
_ireeOptRunMain
_ireeReduceRunMain
Expand Down
16 changes: 16 additions & 0 deletions compiler/src/iree/compiler/API/generate_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
"Dialects.h",
]

IREE_COMPILER_DIALECTS_HEADER_FILES = [
"iree_gpu.h",
]

EXPLICIT_EXPORTS = [
# MLIR registration functions that are part of generated code.
"mlirRegisterGPUPasses",
Expand Down Expand Up @@ -107,6 +111,14 @@ def main(repo_root: Path, api_root: Path):
)
)

# Collect symbols from iree compiler dialect header files.
for local_name in IREE_COMPILER_DIALECTS_HEADER_FILES:
export_symbols.extend(
collect_header_exports(
repo_root / "compiler/bindings/c/iree/compiler/dialects" / local_name
)
)

# Collect symbols from mlir-c header files.
mlir_c_dir = repo_root / "third_party/llvm-project/mlir/include/mlir-c"
for local_name in MLIR_C_HEADER_FILES:
Expand Down Expand Up @@ -179,6 +191,8 @@ def generate_force_extern(symbols: List[str], file: Path):
f.write("\n")
f.write("// Generated by generate_exports.py: Do not edit.\n")
f.write("\n")
f.write("// clang-format off\n")
f.write("\n")
f.write("#include <stdint.h>\n")
f.write("\n")
for symbol in symbols:
Expand All @@ -190,6 +204,8 @@ def generate_force_extern(symbols: List[str], file: Path):
f.write(f" x += (uintptr_t)&{symbol};\n")
f.write(" return x;\n")
f.write("}\n")
f.write("\n")
f.write("// clang-format off\n")


if __name__ == "__main__":
Expand Down
Loading

0 comments on commit a60fd6c

Please sign in to comment.