Skip to content

Commit

Permalink
Integrate LLVM at llvm/llvm-project@e86910337f98
Browse files Browse the repository at this point in the history
  • Loading branch information
sdasgup3 committed Dec 18, 2024
1 parent 33f19a4 commit 59c744d
Show file tree
Hide file tree
Showing 12 changed files with 455 additions and 149 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/buildAndTestCMake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ jobs:
- name: Build and Test StableHLO (with Python bindings)
shell: bash
run: |
pip install tensorflow-cpu
pip install tensorflow-cpu nanobind==2.4
pip install -r "$LLVM_PROJECT_DIR/mlir/python/requirements.txt"
./build_tools/github_actions/ci_build_cmake.sh "$LLVM_BUILD_DIR" "$STABLEHLO_BUILD_DIR"
env:
CMAKE_BUILD_TYPE: Release
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/publishWheelRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ jobs:
- name: Build and Test StableHLO with Python
shell: bash
run: |
pip install tensorflow-cpu
pip install tensorflow-cpu nanobind==2.4
pip install -r "$LLVM_PROJECT_DIR/mlir/python/requirements.txt"
./build_tools/github_actions/ci_build_cmake.sh "$LLVM_BUILD_DIR" "$STABLEHLO_BUILD_DIR"
env:
CMAKE_BUILD_TYPE: Release
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ workspace(name = "stablehlo")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

LLVM_COMMIT = "af20aff35ec37ead88903bc3e44f6a81c5c9ca4e"
LLVM_COMMIT = "e86910337f98e57f5b9253f7d80d5b916eb1d97e"

LLVM_SHA256 = "6e31682011d8c483c6a41adf5389eb09ad7db84331ca985d33a5d59efd0388f6"
LLVM_SHA256 = "4ca0eff0ca86ed6f2fdb7682354fdf4c85151d90ac9fb6e55a868e4191359e9f"

http_archive(
name = "llvm-raw",
Expand Down
2 changes: 1 addition & 1 deletion build_tools/llvm_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
af20aff35ec37ead88903bc3e44f6a81c5c9ca4e
e86910337f98e57f5b9253f7d80d5b916eb1d97e
23 changes: 23 additions & 0 deletions stablehlo/integrations/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,18 @@ declare_mlir_dialect_python_bindings(
# Extensions
################################################################################

add_compile_options(-Wno-error=cast-qual -Wno-error=nested-anon-types
-Wno-error=extra-semi -Wno-error=zero-length-array
-Wno-error=covered-switch-default)
# Print the flags to verify
message(STATUS "HI::CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")


declare_mlir_python_sources(CheckPythonExtensions)
declare_mlir_python_extension(CheckPythonExtensions.Main
MODULE_NAME _check
ADD_TO_PARENT CheckPythonExtensions
PYTHON_BINDINGS_LIBRARY nanobind
SOURCES
CheckModule.cpp
EMBED_CAPI_LINK_LIBS
Expand All @@ -102,10 +110,14 @@ declare_mlir_python_extension(CheckPythonExtensions.Main
LLVMSupport
)

#target_compile_options(CheckPythonExtensions.Main INTERFACE
# ${NANOBIND_COMPILE_FLAGS})
#
declare_mlir_python_sources(ChloPythonExtensions)
declare_mlir_python_extension(ChloPythonExtensions.Main
MODULE_NAME _chlo
ADD_TO_PARENT ChloPythonExtensions
PYTHON_BINDINGS_LIBRARY nanobind
SOURCES
ChloModule.cpp
EMBED_CAPI_LINK_LIBS
Expand All @@ -114,10 +126,14 @@ declare_mlir_python_extension(ChloPythonExtensions.Main
LLVMSupport
)

#target_compile_options(ChloPythonExtensions.Main INTERFACE
# ${NANOBIND_COMPILE_FLAGS})
#
declare_mlir_python_sources(StablehloPythonExtensions)
declare_mlir_python_extension(StablehloPythonExtensions.Main
MODULE_NAME _stablehlo
ADD_TO_PARENT StablehloPythonExtensions
PYTHON_BINDINGS_LIBRARY nanobind
SOURCES
StablehloApi.cpp
StablehloModule.cpp
Expand All @@ -128,10 +144,14 @@ declare_mlir_python_extension(StablehloPythonExtensions.Main
LLVMSupport
)

#target_compile_options(StablehloPythonExtensions.Main INTERFACE
# ${NANOBIND_COMPILE_FLAGS})
#
declare_mlir_python_sources(VhloPythonExtensions)
declare_mlir_python_extension(VhloPythonExtensions.Main
MODULE_NAME _vhlo
ADD_TO_PARENT VhloPythonExtensions
PYTHON_BINDINGS_LIBRARY nanobind
SOURCES
VhloModule.cpp
EMBED_CAPI_LINK_LIBS
Expand All @@ -140,6 +160,9 @@ declare_mlir_python_extension(VhloPythonExtensions.Main
LLVMSupport
)

#target_compile_options(VhloPythonExtensions.Main INTERFACE
# ${NANOBIND_COMPILE_FLAGS})
#
################################################################################
# Generate packages and shared libraries
################################################################################
Expand Down
9 changes: 5 additions & 4 deletions stablehlo/integrations/python/CheckModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ limitations under the License.
==============================================================================*/

#include "mlir-c/IR.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"
#include "nanobind/nanobind.h"
#include "stablehlo/integrations/c/CheckDialect.h"

namespace py = pybind11;
namespace nb = nanobind;

PYBIND11_MODULE(_check, m) {
NB_MODULE(_check, m) {
m.doc() = "check main python extension";

//
Expand All @@ -32,5 +33,5 @@ PYBIND11_MODULE(_check, m) {
mlirDialectHandleLoadDialect(dialect, context);
}
},
py::arg("context"), py::arg("load") = true);
nb::arg("context"), nb::arg("load") = true);
}
30 changes: 17 additions & 13 deletions stablehlo/integrations/python/ChloModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ limitations under the License.
==============================================================================*/

#include "mlir-c/IR.h"
#include "mlir/Bindings/Python/PybindAdaptors.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"
#include "nanobind/nanobind.h"
#include "nanobind/stl/string_view.h"
#include "stablehlo/integrations/c/ChloAttributes.h"
#include "stablehlo/integrations/c/ChloDialect.h"

namespace py = pybind11;
namespace nb = nanobind;

namespace {

auto toPyString(MlirStringRef mlirStringRef) {
return py::str(mlirStringRef.data, mlirStringRef.length);
return nb::str(mlirStringRef.data, mlirStringRef.length);
}

} // namespace

PYBIND11_MODULE(_chlo, m) {
NB_MODULE(_chlo, m) {
m.doc() = "chlo main python extension";

//
Expand All @@ -42,35 +44,37 @@ PYBIND11_MODULE(_chlo, m) {
mlirDialectHandleLoadDialect(dialect, context);
}
},
py::arg("context"), py::arg("load") = true);
nb::arg("context"), nb::arg("load") = true);

//
// Attributes.
//

mlir::python::adaptors::mlir_attribute_subclass(
mlir::python::nanobind_adaptors::mlir_attribute_subclass(
m, "ComparisonDirectionAttr", chloAttributeIsAComparisonDirectionAttr)
.def_classmethod(
"get",
[](py::object cls, const std::string &value, MlirContext ctx) {
[](nb::object cls, std::string_view value, MlirContext ctx) {
return cls(chloComparisonDirectionAttrGet(
ctx, mlirStringRefCreate(value.c_str(), value.size())));
ctx, mlirStringRefCreate(value.data(), value.size())));
},
py::arg("cls"), py::arg("value"), py::arg("context") = py::none(),
nb::arg("cls"), nb::arg("value"),
nb::arg("context").none() = nb::none(),
"Creates a ComparisonDirection attribute with the given value.")
.def_property_readonly("value", [](MlirAttribute self) {
return toPyString(chloComparisonDirectionAttrGetValue(self));
});

mlir::python::adaptors::mlir_attribute_subclass(
mlir::python::nanobind_adaptors::mlir_attribute_subclass(
m, "ComparisonTypeAttr", chloAttributeIsAComparisonTypeAttr)
.def_classmethod(
"get",
[](py::object cls, const std::string &value, MlirContext ctx) {
[](nb::object cls, std::string_view value, MlirContext ctx) {
return cls(chloComparisonTypeAttrGet(
ctx, mlirStringRefCreate(value.c_str(), value.size())));
ctx, mlirStringRefCreate(value.data(), value.size())));
},
py::arg("cls"), py::arg("value"), py::arg("context") = py::none(),
nb::arg("cls"), nb::arg("value"),
nb::arg("context").none() = nb::none(),
"Creates a ComparisonType attribute with the given value.")
.def_property_readonly("value", [](MlirAttribute self) {
return toPyString(chloComparisonTypeAttrGetValue(self));
Expand Down
Loading

0 comments on commit 59c744d

Please sign in to comment.