Commit Graph

2442 Commits

Author SHA1 Message Date
Mikhail Goncharov
10d84a86e5 [bazel] port 79e859e049 2024-12-19 10:45:20 +01:00
Peter Hawkins
b56d1ec6cb [mlir python] Port Python core code to nanobind. (#120473)
Relands #118583, with a fix for Python 3.8 compatibility. It was not
possible to set the buffer protocol accessers via slots in Python 3.8.

Why? https://nanobind.readthedocs.io/en/latest/why.html says it better
than I can, but my primary motivation for this change is to improve MLIR
IR construction time from JAX.

For a complicated Google-internal LLM model in JAX, this change improves
the MLIR
lowering time by around 5s (out of around 30s), which is a significant
speedup for simply switching binding frameworks.

To a large extent, this is a mechanical change, for instance changing
`pybind11::` to `nanobind::`.

Notes:
* this PR needs Nanobind 2.4.0, because it needs a bug fix
(https://github.com/wjakob/nanobind/pull/806) that landed in that
release.
* this PR does not port the in-tree dialect extension modules. They can
be ported in a future PR.
* I removed the py::sibling() annotations from def_static and def_class
in `PybindAdapters.h`. These ask pybind11 to try to form an overload
with an existing method, but it's not possible to form mixed
pybind11/nanobind overloads this ways and the parent class is now
defined in nanobind. Better solutions may be possible here.
* nanobind does not contain an exact equivalent of pybind11's buffer
protocol support. It was not hard to add a nanobind implementation of a
similar API.
* nanobind is pickier about casting to std::vector<bool>, expecting that
the input is a sequence of bool types, not truthy values. In a couple of
places I added code to support truthy values during casting.
* nanobind distinguishes bytes (`nb::bytes`) from strings (e.g.,
`std::string`). This required nb::bytes overloads in a few places.
2024-12-18 18:55:42 -08:00
Jacques Pienaar
6e8b3a3e0c Revert "[mlir python] Port Python core code to nanobind. (#118583)"
This reverts commit 41bd35b58b.

Breakage detected, rolling back.
2024-12-18 19:31:32 +00:00
Peter Hawkins
41bd35b58b [mlir python] Port Python core code to nanobind. (#118583)
Why? https://nanobind.readthedocs.io/en/latest/why.html says it better
than I can, but my primary motivation for this change is to improve MLIR
IR construction time from JAX.

For a complicated Google-internal LLM model in JAX, this change improves
the MLIR
lowering time by around 5s (out of around 30s), which is a significant
speedup for simply switching binding frameworks.

To a large extent, this is a mechanical change, for instance changing
`pybind11::`
to `nanobind::`.

Notes:
* this PR needs Nanobind 2.4.0, because it needs a bug fix
(https://github.com/wjakob/nanobind/pull/806) that landed in that
release.
* this PR does not port the in-tree dialect extension modules. They can
be ported in a future PR.
* I removed the py::sibling() annotations from def_static and def_class
in `PybindAdapters.h`. These ask pybind11 to try to form an overload
with an existing method, but it's not possible to form mixed
pybind11/nanobind overloads this ways and the parent class is now
defined in nanobind. Better solutions may be possible here.
* nanobind does not contain an exact equivalent of pybind11's buffer
protocol support. It was not hard to add a nanobind implementation of a
similar API.
* nanobind is pickier about casting to std::vector<bool>, expecting that
the input is a sequence of bool types, not truthy values. In a couple of
places I added code to support truthy values during casting.
* nanobind distinguishes bytes (`nb::bytes`) from strings (e.g.,
`std::string`). This required nb::bytes overloads in a few places.
2024-12-18 11:16:11 -08:00
Tristan Ross
7477b61b24 [libc] Add unistd overlay (#119312)
Reverts the revert #119295 of #118882 by expanding #118882 with
additional fixes which made CI unhappy.
2024-12-17 10:40:22 -08:00
Mikhail Goncharov
525c818f08 [bazel] port 6a7d6c5f69 2024-12-17 17:56:43 +01:00
Mikhail Goncharov
34c4f6f937 [MLIR][bazel] port 0693b9e9cc 2024-12-17 13:41:38 +01:00
Yifei Xu
e2a94a97bd Update BUILD.bazel
Fix bazel build after https://github.com/llvm/llvm-project/pull/120116
2024-12-16 22:39:10 -06:00
norx1991
dda1d16747 Update BUILD.bazel
Fix issue introduced by https://github.com/llvm/llvm-project/pull/118839.
2024-12-16 17:33:40 -06:00
Danial Klimkin
a21f9bfe29 [bazel]Fix Bazel build past bc29fc937c (#119874) 2024-12-13 13:56:28 +01:00
Jordan Rupprecht
eac1e13add [bzl][mlir][emitc] Add build targets for EmitC C-API/Python bindings (#119610)
Added by 3c464d2368
2024-12-11 14:31:29 -06:00
Nick Desaulniers
8c3a8c2619 [bazel][libc] fix typo in comment
Link: #119433
2024-12-10 14:40:12 -08:00
Keith Smiley
5d0957fc23 [bazel] Allow overriding py_test rule for lit_test (#119460)
This allows replacing this implementation with another one, such as the
one from aspect_rules_py
2024-12-10 14:22:15 -08:00
Keith Smiley
bedbafff2d [bazel] Fix lit tests with bazel 8.x (#119462)
https://github.com/llvm/llvm-project/issues/83066
2024-12-10 14:09:08 -08:00
Nick Desaulniers
5877e5bd12 [bazel] update .bazelversion to 8.0.0 (#119425)
Fixes:

ERROR: The project you're trying to build requires Bazel 7.3.0
(specified
    in llvm-project/utils/bazel/.bazelversion), but it wasn't found in
    /usr/bin.

    You can install the required Bazel version via apt:
      sudo apt update && sudo apt install bazel-7.3.0

If this doesn't work, check Bazel's installation instructions for help:
      https://bazel.build/install/ubuntu

Link: https://blog.bazel.build/2024/12/09/bazel-8-release.html
2024-12-10 13:07:52 -08:00
Jordan Rupprecht
b2cc66b4f2 [bzl][mlir][mlir-vulkan-runner] Add vulkan deps (#119457)
9735873009
2024-12-10 15:05:16 -06:00
Keith Smiley
f3c675feec [bazel] Port 9a9c1d4a61 (#119456) 2024-12-10 12:56:26 -08:00
Nick Desaulniers
1d0ca626d8 [bazel] fix libc build (#119433)
Due to moving strings out of string.

Link: #118899
2024-12-10 12:29:49 -08:00
Maksim Levental
392622d084 Revert "Revert "[mlir python] Add nanobind support (#119232)
Reverts revert #118517 after (hopefully) fixing builders
(https://github.com/llvm/llvm-zorg/pull/328,
https://github.com/llvm/llvm-zorg/pull/327)

This reverts commit 61bf308cf2.
2024-12-09 16:37:43 -05:00
Dmitri Gribenko
6f190cabe0 [bazel] Port e6cf5d2863 2024-12-06 10:30:09 +01:00
Dmitri Gribenko
e9fb0ad21d [bazel] Port 2ccf7ed277 2024-12-06 10:07:05 +01:00
Schrodinger ZHU Yifan
e6cf5d2863 Reapply "[libc][windows] start time API implementation (#117775)" (#118886) 2024-12-05 18:21:03 -05:00
Joseph Huber
9fd052a122 Revert "[libc][windows] start time API implementation (#117775)"
This reverts commit 0adff0af20.

Breaks the GPU build
2024-12-05 14:43:06 -06:00
Schrodinger ZHU Yifan
0adff0af20 [libc][windows] start time API implementation (#117775)
Add a `clock_gettime` emulation layer and use it to implement the `time`
entrypoint.

For windows, the monotonic clock is emulated using `QPC`.
The realtime clock is emulated using `GetSystemTimePreciseAsFileTime`.
2024-12-05 14:08:27 -05:00
Dmitri Gribenko
5cbc421427 [bazel] Port 9c9d4b9e73 2024-12-04 10:33:15 +01:00
Augie Fackler
f6f16b5f54 [bazel] update for a0c4f854ca 2024-12-03 20:55:11 -05:00
Michael Jones
a0c4f854ca [libc] Change ctype to be encoding independent (#110574)
The previous implementation of the ctype functions assumed ASCII.
This patch changes to a switch/case implementation that looks odd, but
actually is easier for the compiler to understand and optimize.
2024-12-03 12:36:04 -08:00
Augie Fackler
e8b9e1354a [bazel] update config.h.cmake
for 4dafb091a0
reverts 1a1de2465d
2024-12-03 13:16:58 -05:00
Maksim Levental
61bf308cf2 Revert "[mlir python] Add nanobind support for standalone dialects." (#118517)
Reverts llvm/llvm-project#117922 because deps aren't met on some of the
post-commit build bots.
2024-12-03 09:26:33 -08:00
Peter Hawkins
afe75b4d5f [mlir python] Add nanobind support for standalone dialects. (#117922)
This PR allows out-of-tree dialects to write Python dialect modules
using nanobind instead of pybind11.

It may make sense to migrate in-tree dialects and some of the ODS Python
infrastructure to nanobind, but that is a topic for a future change.

This PR makes the following changes:
* adds nanobind to the CMake and Bazel build systems. We also add
robin_map to the Bazel build, which is a dependency of nanobind.
* adds a PYTHON_BINDING_LIBRARY option to various CMake functions, such
as declare_mlir_python_extension, allowing users to select a Python
binding library.
* creates a fork of mlir/include/mlir/Bindings/Python/PybindAdaptors.h
named NanobindAdaptors.h. This plays the same role, using nanobind
instead of pybind11.
* splits CollectDiagnosticsToStringScope out of PybindAdaptors.h and
into a new header mlir/include/mlir/Bindings/Python/Diagnostics.h, since
it is code that is no way related to pybind11 or for that matter,
Python.
* changed the standalone Python extension example to have both pybind11
and nanobind variants.
* changed mlir/python/mlir/dialects/python_test.py to have both pybind11
and nanobind variants.

Notes:
* A slightly unfortunate thing that I needed to do in the CMake
integration was to use FindPython in addition to FindPython3, since
nanobind's CMake integration expects the Python_ names for variables.
Perhaps there's a better way to do this.
2024-12-03 09:13:34 -08:00
Nick Desaulniers
68112f0f5b libc: fixup include path and bazel stale comments (#118510)
Downstream builders are having issues with this local include. Use a
fuller
path that's more standard throughout the codebase.

Also some of the comments in the bazel overlay are stale. Remove them.

Reported-by: Brooks Moses <bmoses@google.com>
2024-12-03 08:59:58 -08:00
Christian Sigg
6f55d7d22c [mlir][bazel] Port 79eb406a67 2024-11-28 11:54:32 +01:00
Christian Sigg
2585b6e8fa [mlir][bazel] Fix layering check failure. 2024-11-25 09:10:14 +01:00
Christian Sigg
b0bdbf4288 [mlir][bazel] Port 7498eaa9ab 2024-11-25 08:31:16 +01:00
Benjamin Kramer
c4d656a4e9 [bazel] Add missing dependencies for a0ef12c642 2024-11-24 11:27:37 +01:00
Benjamin Kramer
bd7d6c8066 [bazel] Port 776476c282 2024-11-24 11:21:04 +01:00
Mikhail Goncharov
b8eef18868 [bazel] port ecaf2c335c 2024-11-22 16:22:34 +01:00
Mikhail Goncharov
5bdee35544 [bazel] format utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl 2024-11-21 11:41:34 +01:00
Jeremy Kun
69cc3f096c Add mlir-query bazel rules (#116063)
I noticed there's no bazel query for `mlir-query`, unlike the other MLIR
tools, so adding one.
2024-11-20 20:24:24 -06:00
lntue
14667119bc [libc] Allow each function can have extra attributes by defining LLVM_LIBC_FUNCTION_ATTR_func macro. (#116160) 2024-11-20 17:50:00 -05:00
Haojian Wu
12cfa414a3 [bazel] Port for 08e7609692 2024-11-20 15:36:52 +01:00
Mikhail Goncharov
1bfcf89107 [bazel] port a8744066e9 2024-11-19 17:50:51 +01:00
Mikhail Goncharov
b64095c795 [bazel] port e370946978 2024-11-18 11:24:24 +01:00
Mikhail Goncharov
20c653c313 [bazel] port 63b926af5f 2024-11-18 11:00:33 +01:00
Daniel Thornburgh
95b680e4c3 [libc] Rename libc/src/__support/endian.h to endian_internal.h (#115950)
This prevents a conflict with the Linux system endian.h when built in
overlay mode for CPP files in __support.

This issue appeared in PR #106259.
2024-11-13 10:28:07 -08:00
Haojian Wu
716a095a80 [bazel] Port for 8cc616bc71 2024-11-13 15:59:29 +01:00
Haojian Wu
70d6789c7a [bazel] Port for 7302c8dbe7 2024-11-12 21:06:19 +01:00
Michael Jones
36cbc09e63 [libc][bazel] config macros is a support library (#115776)
Previously __support_macros_config was a cc_library, but making it a
libc_support_library makes things cleaner.
2024-11-11 14:16:53 -08:00
Haojian Wu
d1aa0da7e2 [bazel] Port for ffc7feadec 2024-11-11 09:00:43 +01:00
weiwei chen
fb4f426c81 [Bazel] Add a comment why an export file is needed. (#115556)
- [x] Add follow-up comment on why the export file is needed in
BUILD.bazel
2024-11-08 23:15:22 -05:00