Skip to content
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

Update openvino-mlir-gc integration #167

Open
wants to merge 22 commits into
base: mlir
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmake/graph-compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ if (NOT DEFINED GRAPH_COMPILER_LIBS)
FetchContent_Declare(
GC
GIT_REPOSITORY https://github.com/intel/graph-compiler.git
GIT_TAG main
GIT_TAG xgniu/constant_weights_folding # zhicong/perf_test2 # yifei/mlp_benching_new
FIND_PACKAGE_ARGS NAMES GraphCompiler
)

set(GC_ENABLE_OPT OFF)
set(GC_ENABLE_TEST OFF)
set(GC_ENABLE_DNNL OFF)
set(GC_ENABLE_DNNL_API OFF)
set(GC_ENABLE_LEGACY OFF)
set(GC_ENABLE_BINDINGS_PYTHON OFF)
set(OV_BUILD_SHARED_LIBS_TMP ${BUILD_SHARED_LIBS})
Expand All @@ -31,6 +31,9 @@ if (NOT DEFINED GRAPH_COMPILER_LIBS)
GcInterface
GcJitWrapper
GcCpuRuntime
# For some branches:
# MLIRCPURuntimeTransforms
# MLIRMicrokernelTransforms
)
set_property(GLOBAL PROPERTY GRAPH_COMPILER_LIBS ${GRAPH_COMPILER_LIBS})
endif ()
Expand Down
66 changes: 63 additions & 3 deletions src/common/transformations/src/transformations/mlir/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,73 @@ mlir::OwningOpRef<mlir::ModuleOp> ngraph_to_mlir(MLIRContext* context,
// Affix target information attribute to the module to be used, at its discretion,
// by the MLIR-compiler that consumes this module.
auto tileSize = IntegerAttr::get(IntegerType::get(context, 32), 32);
auto key = StringAttr::get(context, "tile_size");
DataLayoutEntryInterface entry = DataLayoutEntryAttr::get(context, key, tileSize);
TargetDeviceSpecInterface deviceSpec = TargetDeviceSpecAttr::get(context, ArrayRef(entry));
auto tileSizeKey = StringAttr::get(context, "tile_size");
DataLayoutEntryInterface tileSizeEntry = DataLayoutEntryAttr::get(context, tileSizeKey, tileSize);

int numThreadsInt = 1;
if (char* numThreadsEnv = std::getenv("OMP_NUM_THREADS")) {
numThreadsInt = std::atoi(numThreadsEnv);
}
auto numThreads = IntegerAttr::get(IntegerType::get(context, 32), numThreadsInt);
auto numThreadsKey = StringAttr::get(context, "num_threads");
DataLayoutEntryInterface numThreadsEntry = DataLayoutEntryAttr::get(context, numThreadsKey, numThreads);

int L1CacheSizeInt = 49152;
if (char* L1CacheSizeEnv = std::getenv("L1_CACHE_SIZE")) {
L1CacheSizeInt = std::atoi(L1CacheSizeEnv);
}
auto L1CacheSize = IntegerAttr::get(IntegerType::get(context, 32), L1CacheSizeInt);
auto L1CacheSizeKey = StringAttr::get(context, "L1_cache_size_in_bytes");
DataLayoutEntryInterface L1CacheSizeEntry = DataLayoutEntryAttr::get(context, L1CacheSizeKey, L1CacheSize);

int L2CacheSizeInt = 2097152;
if (char* L2CacheSizeEnv = std::getenv("L2_CACHE_SIZE")) {
L2CacheSizeInt = std::atoi(L2CacheSizeEnv);
}
auto L2CacheSize = IntegerAttr::get(IntegerType::get(context, 32), L2CacheSizeInt);
auto L2CacheSizeKey = StringAttr::get(context, "L2_cache_size_in_bytes");
DataLayoutEntryInterface L2CacheSizeEntry = DataLayoutEntryAttr::get(context, L2CacheSizeKey, L2CacheSize);

int L3CacheSizeInt = 1966080;
if (char* L3CacheSizeEnv = std::getenv("L3_CACHE_SIZE")) {
L3CacheSizeInt = std::atoi(L3CacheSizeEnv);
}
auto L3CacheSize = IntegerAttr::get(IntegerType::get(context, 32), L3CacheSizeInt);
auto L3CacheSizeKey = StringAttr::get(context, "L3_cache_size_in_bytes");
DataLayoutEntryInterface L3CacheSizeEntry = DataLayoutEntryAttr::get(context, L3CacheSizeKey, L3CacheSize);

int maxVectorWidthInt = 512;
if (char* maxVectorWidthEnv = std::getenv("MAX_VECTOR_WIDTH")) {
maxVectorWidthInt = std::atoi(maxVectorWidthEnv);
}
auto maxVectorWidth = IntegerAttr::get(IntegerType::get(context, 32), maxVectorWidthInt);
auto maxVectorWidthKey = StringAttr::get(context, "max_vector_width");
DataLayoutEntryInterface maxVectorWidthEntry = DataLayoutEntryAttr::get(context, maxVectorWidthKey, maxVectorWidth);

TargetDeviceSpecInterface deviceSpec = TargetDeviceSpecAttr::get(context,
ArrayRef({tileSizeEntry,
numThreadsEntry,
L1CacheSizeEntry,
L2CacheSizeEntry,
L3CacheSizeEntry,
maxVectorWidthEntry}));
auto deviceStr = StringAttr::get(context, "CPU");
auto sysSpec = TargetSystemSpecAttr::get(context, ArrayRef(std::pair(deviceStr, deviceSpec)));
module.getOperation()->setAttr("#dlti.sys_spec", sysSpec);

std::vector<int> compiletime_const_args_index;
for (size_t i = 0; i < inputs.size(); ++i) {
auto parent = inputs[i].get_node_shared_ptr();
if (auto data_const = std::dynamic_pointer_cast<ov::op::v0::Constant>(parent)) {
OPENVINO_MLIR_DEBUG_PRINT("Mark #" << i << " input as Constant tensor\n");
compiletime_const_args_index.push_back(i);
}
}
func.getOperation()->setAttr("compiletime_const_args_index",
moduleBuilder.getI32ArrayAttr(compiletime_const_args_index));

func.getOperation()->setAttr(LLVM::LLVMDialect::getEmitCWrapperAttrName(), UnitAttr::get(context));

ConversionContext conversion_context(context, &block_builder);

for (size_t i = 0; i < inputs.size(); ++i) {
Expand Down
Loading
Loading