From cacc4abc84d0d53318c972d0ebf20b78fd653dfc Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 6 Aug 2026 07:12:44 -0700 Subject: [PATCH 1/6] Add meson build option for ILP64 fixes compiler warning about unused function --- meson.build | 4 ++++ meson.options | 2 ++ mkl/_mklinitmodule.c | 11 ++++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 meson.options diff --git a/meson.build b/meson.build index 1b9ce893..16f2efa1 100644 --- a/meson.build +++ b/meson.build @@ -16,6 +16,10 @@ py = import('python').find_installation(pure: false) c_args = ['-DNDEBUG'] +if get_option('ilp64') + c_args += '-DMKL_ILP64' +endif + thread_dep = dependency('threads') cc = meson.get_compiler('c') diff --git a/meson.options b/meson.options new file mode 100644 index 00000000..46117a34 --- /dev/null +++ b/meson.options @@ -0,0 +1,2 @@ +option('ilp64', type: 'boolean', value: false, + description: 'Build with MKL ILP64 interface') diff --git a/mkl/_mklinitmodule.c b/mkl/_mklinitmodule.c index 11571dda..3a317924 100644 --- a/mkl/_mklinitmodule.c +++ b/mkl/_mklinitmodule.c @@ -28,8 +28,11 @@ static struct PyMethodDef methods[] = {{NULL, NULL, 0, NULL}}; #define MKL_SERVICE_INLINE inline #endif +#ifdef MKL_ILP64 static MKL_SERVICE_INLINE void _set_mkl_ilp64(void); +#else static MKL_SERVICE_INLINE void _set_mkl_lp64(void); +#endif static MKL_SERVICE_INLINE void _set_mkl_interface(void); static const char *mtlayer; @@ -154,6 +157,7 @@ static void _preload_threading_layer(void) return; } +#ifdef MKL_ILP64 static MKL_SERVICE_INLINE void _set_mkl_ilp64(void) { #ifdef USING_MKL_RT @@ -161,7 +165,7 @@ static MKL_SERVICE_INLINE void _set_mkl_ilp64(void) #endif return; } - +#else static MKL_SERVICE_INLINE void _set_mkl_lp64(void) { #ifdef USING_MKL_RT @@ -169,10 +173,15 @@ static MKL_SERVICE_INLINE void _set_mkl_lp64(void) #endif return; } +#endif static MKL_SERVICE_INLINE void _set_mkl_interface(void) { +#ifdef MKL_ILP64 + _set_mkl_ilp64(); +#else _set_mkl_lp64(); +#endif _preload_threading_layer(); } From 35d3e081f3961fa45111b7810ea5361aac0d0700 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 6 Aug 2026 08:21:00 -0700 Subject: [PATCH 2/6] add gh-184 to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87995ead..03927eb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added support for free-threaded (GIL-disabled) CPython builds: the Cython extension is compiled with `freethreading_compatible=True` and `_mklinit` declares `Py_MOD_GIL_NOT_USED`, so importing `mkl` no longer re-enables the GIL [gh-213](https://github.com/IntelPython/mkl-service/pull/213) +* Added support for new build option `ilp64` to initialize MKL with the ILP64 interface, which also resolves some build warnings [gh-184](https://github.com/IntelPython/mkl-service/pull/184) ### Changed * Raised the minimum build-time `Cython` requirement to `3.1.0`, the first release providing the `freethreading_compatible` directive [gh-213](https://github.com/IntelPython/mkl-service/pull/213) From 8a77a18dadf14a23d45bfbcaf2f6de86faca7cdd Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 2 Sep 2026 10:10:40 -0700 Subject: [PATCH 3/6] define MKL_INT types from mkl.h --- mkl/_mkl_service.pxd | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mkl/_mkl_service.pxd b/mkl/_mkl_service.pxd index 4cba157d..ed5a1064 100644 --- a/mkl/_mkl_service.pxd +++ b/mkl/_mkl_service.pxd @@ -24,12 +24,13 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -ctypedef long long MKL_INT64 -ctypedef unsigned long long MKL_UINT64 -ctypedef int MKL_INT - - cdef extern from "mkl.h": + # defer definition of integer types to mkl.h + # Cython will narrow the types based on what mkl.h defines + ctypedef long long MKL_INT64 + ctypedef unsigned long long MKL_UINT64 + ctypedef long long MKL_INT + # MKL Function Domains Constants int MKL_DOMAIN_BLAS int MKL_DOMAIN_FFT From ba7bcdca50c5bb4d19ffa244ddb2635026cb51e6 Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Wed, 2 Sep 2026 10:36:24 -0700 Subject: [PATCH 4/6] add ILP64 option to README --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 52620af6..dd36e19e 100644 --- a/README.md +++ b/README.md @@ -54,3 +54,36 @@ then build against the existing installation with: ```sh python -m pip install --no-build-isolation --no-deps . ``` + +### Build options + +| Option | Type | Default | Description | +| ------- | ------- | ------- | ------------------------------------ | +| `ilp64` | boolean | `false` | Build with the oneMKL ILP64 interface | + +Options are passed using `-Csetup-args`: +```sh +python -m pip install . -Csetup-args=-Dilp64=true +``` + +By default `mkl-service` is built against the LP64 interface, in which oneMKL's +integer type `MKL_INT` is 32-bit. Enabling `ilp64` makes `MKL_INT` 64-bit +and requests the ILP64 interface layer from `libmkl_rt` on import. +Use it when the oneMKL libraries you link against provide the ILP64 interface. + +The Python API is identical in both configurations — no function signature or +return value changes. + +> **Warning:** the oneMKL interface layer is process-global and can only be +> selected before the first oneMKL call. `mkl-service` requests it on import, +> so an ILP64 build is order-dependent and unsafe to mix with LP64 +> consumers: +> +> * If imported before another oneMKL consumer initializes oneMKL, that +> consumer's LP64 calls get reinterpreted as ILP64. LAPACK routines in +> particular may crash. +> * If the other consumer initializes oneMKL first, the ILP64 request is ignored +> and the process stays LP64. +> +> Only enable `ilp64` when every consumer uses the ILP64 interface or +> `mkl-service` is the sole oneMKL consumer in the process. From 5156b08792896914268dd903e5835c35be7369a6 Mon Sep 17 00:00:00 2001 From: ndgrigorian <46709016+ndgrigorian@users.noreply.github.com> Date: Thu, 3 Sep 2026 10:37:47 -0700 Subject: [PATCH 5/6] Fix options table in README Co-authored-by: Anton <100830759+antonwolfy@users.noreply.github.com> --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dd36e19e..3eb6e975 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ python -m pip install --no-build-isolation --no-deps . ### Build options -| Option | Type | Default | Description | -| ------- | ------- | ------- | ------------------------------------ | +| Option | Type | Default | Description | +| ------- | ------- | ------- | ------------------------------------- | | `ilp64` | boolean | `false` | Build with the oneMKL ILP64 interface | Options are passed using `-Csetup-args`: From 77980890501128fa222bc7deeacc315f6cb9f1cc Mon Sep 17 00:00:00 2001 From: Nikita Grigorian Date: Thu, 3 Sep 2026 10:55:58 -0700 Subject: [PATCH 6/6] set MKL_INTERFACE explicitly --- meson.build | 3 +++ 1 file changed, 3 insertions(+) diff --git a/meson.build b/meson.build index 16f2efa1..0972a6b7 100644 --- a/meson.build +++ b/meson.build @@ -15,9 +15,11 @@ project( py = import('python').find_installation(pure: false) c_args = ['-DNDEBUG'] +cmake_mkl_interface = 'lp64' if get_option('ilp64') c_args += '-DMKL_ILP64' + cmake_mkl_interface = 'ilp64' endif thread_dep = dependency('threads') @@ -28,6 +30,7 @@ mkl_dep = dependency('MKL', method: 'cmake', cmake_args: [ '-DMKL_ARCH=intel64', '-DMKL_LINK=sdl', + '-DMKL_INTERFACE=' + cmake_mkl_interface, ], required: true )