Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
7 changes: 7 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ project(
py = import('python').find_installation(pure: false)

c_args = ['-DNDEBUG']
cmake_mkl_interface = 'lp64'

if get_option('ilp64')
c_args += '-DMKL_ILP64'
Comment thread
ndgrigorian marked this conversation as resolved.
Comment thread
ndgrigorian marked this conversation as resolved.
cmake_mkl_interface = 'ilp64'
endif

thread_dep = dependency('threads')

Expand All @@ -24,6 +30,7 @@ mkl_dep = dependency('MKL', method: 'cmake',
cmake_args: [
'-DMKL_ARCH=intel64',
'-DMKL_LINK=sdl',
'-DMKL_INTERFACE=' + cmake_mkl_interface,
],
required: true
)
Expand Down
2 changes: 2 additions & 0 deletions meson.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
option('ilp64', type: 'boolean', value: false,
Comment thread
ndgrigorian marked this conversation as resolved.
Comment thread
ndgrigorian marked this conversation as resolved.
Comment thread
ndgrigorian marked this conversation as resolved.
Comment thread
ndgrigorian marked this conversation as resolved.
description: 'Build with MKL ILP64 interface')
11 changes: 6 additions & 5 deletions mkl/_mkl_service.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion mkl/_mklinitmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,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;
Expand Down Expand Up @@ -151,25 +154,31 @@ static void _preload_threading_layer(void)
return;
}

#ifdef MKL_ILP64
static MKL_SERVICE_INLINE void _set_mkl_ilp64(void)
{
#ifdef USING_MKL_RT
mkl_set_interface_layer(MKL_INTERFACE_ILP64);
#endif
return;
}

#else
static MKL_SERVICE_INLINE void _set_mkl_lp64(void)
{
#ifdef USING_MKL_RT
mkl_set_interface_layer(MKL_INTERFACE_LP64);
#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();
}

Expand Down
Loading