From 8f1b09f37573b91ef91583b164837cb48c942b3c Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Mon, 12 Aug 2024 15:59:23 +0200 Subject: [PATCH 1/2] Add CAPI and python module This allows to use the xten_nn dialect from python --- include/xten-c/Dialects.h | 16 ++++++++++++++++ lib/CAPI/CMakeLists.txt | 10 ++++++++++ lib/CAPI/Dialects.cpp | 16 ++++++++++++++++ lib/CMakeLists.txt | 1 + python/CMakeLists.txt | 12 +++++++++++- 5 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 include/xten-c/Dialects.h create mode 100644 lib/CAPI/CMakeLists.txt create mode 100644 lib/CAPI/Dialects.cpp diff --git a/include/xten-c/Dialects.h b/include/xten-c/Dialects.h new file mode 100644 index 00000000..81c00560 --- /dev/null +++ b/include/xten-c/Dialects.h @@ -0,0 +1,16 @@ +#ifndef XTEN_C_DIALECTS_H +#define XTEN_C_DIALECTS_H + +#include "mlir-c/IR.h" + +#ifdef __cplusplus +extern "C" { +#endif + +MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(XTenNN, xten_nn); + +#ifdef __cplusplus +} +#endif + +#endif // XTEN_C_DIALECTS_H diff --git a/lib/CAPI/CMakeLists.txt b/lib/CAPI/CMakeLists.txt new file mode 100644 index 00000000..7a64f575 --- /dev/null +++ b/lib/CAPI/CMakeLists.txt @@ -0,0 +1,10 @@ +add_mlir_public_c_api_library( + XTenCAPI + Dialects.cpp + ADDITIONAL_HEADER_DIRS + ${XTEN_SOURCE_DIR}/include/pl-c/ + ENABLE_AGGREGATION + LINK_LIBS + PUBLIC + XTenNNDialect +) diff --git a/lib/CAPI/Dialects.cpp b/lib/CAPI/Dialects.cpp new file mode 100644 index 00000000..dc926cd3 --- /dev/null +++ b/lib/CAPI/Dialects.cpp @@ -0,0 +1,16 @@ +//===- Dialects.cpp - C Interface for Dialects ----------------------------===// +// +// 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 +// Also available under a BSD-style license. See LICENSE. +// +//===----------------------------------------------------------------------===// + +#include "xten-c/Dialects.h" + +#include "xten/Dialect/XTenNN/IR/XTenNNBase.h" + +#include "mlir/CAPI/Registration.h" + +MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(XTenNN, xten_nn, amd::xten_nn::XTenNNDialect) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 029b8ae6..e8245426 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -7,6 +7,7 @@ # (c) Copyright 2021 Xilinx, Inc. All Rights reserved. # (c) Copyright 2022 - 2024 Advanced Micro Devices, Inc. All Rights reserved. +add_subdirectory(CAPI) add_subdirectory(Conversion) add_subdirectory(Dialect) add_subdirectory(Transform) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 8ba55d28..a8288813 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -54,4 +54,14 @@ RUNTIME DESTINATION bin COMPONENT python) install(DIRECTORY xten DESTINATION python COMPONENT python) -#add_subdirectory(test) +declare_mlir_python_sources(XTenPythonSources) +declare_mlir_python_sources(XTenPythonSources.Dialects + ADD_TO_PARENT XTenPythonSources) + +declare_mlir_dialect_python_bindings( + ADD_TO_PARENT XTenPythonSources.Dialects + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir" + TD_FILE dialects/XTenNNOps.td + SOURCES + dialects/xten_nn.py + DIALECT_NAME xten_nn) From 5ca5a6bbb504852d244559f202e6f0e123de9e9c Mon Sep 17 00:00:00 2001 From: Matthias Gehre Date: Tue, 13 Aug 2024 14:29:45 +0200 Subject: [PATCH 2/2] Update lib/CAPI/CMakeLists.txt Co-authored-by: Corentin Ferry --- lib/CAPI/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CAPI/CMakeLists.txt b/lib/CAPI/CMakeLists.txt index 7a64f575..4b39b246 100644 --- a/lib/CAPI/CMakeLists.txt +++ b/lib/CAPI/CMakeLists.txt @@ -2,7 +2,7 @@ add_mlir_public_c_api_library( XTenCAPI Dialects.cpp ADDITIONAL_HEADER_DIRS - ${XTEN_SOURCE_DIR}/include/pl-c/ + ${XTEN_SOURCE_DIR}/include/xten-c/ ENABLE_AGGREGATION LINK_LIBS PUBLIC