Skip to content

Commit a926941

Browse files
ENH: More descriptive error message on internal errors
On the example from issue #24, the raised exception now contains MKL's own error message: ``` import numpy as np from scipy.signal import fftconvolve d1 = np.random.rand(18768768) d2 = np.random.rand(15243648) xcraw = fftconvolve(d1, d2, mode='full') ``` produces ``` ValueError: Internal error occurred: b'Intel MKL DFTI ERROR: Inconsistent configuration parameters' ``` Once the underlying issue in Intel(R) MKL is solved, the message will disappear and the expected result will be computed, but addition of sensible description of the nature of internal error is a good edition and will make future spelunking easier.
1 parent 2715ff5 commit a926941

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

mkl_fft/_pydfti.pyx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ cdef extern from "src/mklfft.h":
9999
int double_cdouble_mkl_fftnd_out(cnp.ndarray, cnp.ndarray)
100100
int float_cfloat_mkl_ifftnd_out(cnp.ndarray, cnp.ndarray)
101101
int double_cdouble_mkl_ifftnd_out(cnp.ndarray, cnp.ndarray)
102+
char * mkl_dfti_error(int)
102103

103104
# Initialize numpy
104105
cnp.import_array()
@@ -265,6 +266,8 @@ def _fft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
265266
cdef long n_, axis_
266267
cdef int x_type, f_type, status = 0
267268
cdef int ALL_HARMONICS = 1
269+
cdef char * c_error_msg = NULL
270+
cdef bytes py_error_msg
268271

269272
x_arr = __process_arguments(x, n, axis, overwrite_arg, direction,
270273
&axis_, &n_, &in_place, &xnd, &dir_, 0)
@@ -307,7 +310,9 @@ def _fft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
307310
status = 1
308311

309312
if status:
310-
raise ValueError("Internal error, status={}".format(status))
313+
c_error_msg = mkl_dfti_error(status)
314+
py_error_msg = c_error_msg
315+
raise ValueError("Internal error occurred: {}".format(py_error_msg))
311316

312317
n_max = <long> cnp.PyArray_DIM(x_arr, axis_)
313318
if (n_ < n_max):
@@ -355,7 +360,9 @@ def _fft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
355360
x_arr, n_, <int> axis_, f_arr)
356361

357362
if (status):
358-
raise ValueError("Internal error occurred, status={}".format(status))
363+
c_error_msg = mkl_dfti_error(status)
364+
py_error_msg = c_error_msg
365+
raise ValueError("Internal error occurred: {}".format(py_error_msg))
359366

360367
return f_arr
361368

@@ -379,6 +386,8 @@ def _rrfft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
379386
cdef int xnd, err, n_max = 0, in_place, dir_
380387
cdef long n_, axis_
381388
cdef int x_type, status
389+
cdef char * c_error_msg = NULL
390+
cdef bytes py_error_msg
382391

383392
x_arr = __process_arguments(x, n, axis, overwrite_arg, direction,
384393
&axis_, &n_, &in_place, &xnd, &dir_, 1)
@@ -419,7 +428,9 @@ def _rrfft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
419428
status = 1
420429

421430
if status:
422-
raise ValueError("Internal error, status={}".format(status))
431+
c_error_msg = mkl_dfti_error(status)
432+
py_error_msg = c_error_msg
433+
raise ValueError("Internal error occurred: {}".format(py_error_msg))
423434

424435
n_max = <long> cnp.PyArray_DIM(x_arr, axis_)
425436
if (n_ < n_max):
@@ -445,7 +456,9 @@ def _rrfft1d_impl(x, n=None, axis=-1, overwrite_arg=False, direction=+1):
445456
status = float_float_mkl_rfft_out(x_arr, n_, <int> axis_, f_arr)
446457

447458
if (status):
448-
raise ValueError("Internal error occurred, status={}".format(status))
459+
c_error_msg = mkl_dfti_error(status)
460+
py_error_msg = c_error_msg
461+
raise ValueError("Internal error occurred: {}".format(py_error_msg))
449462

450463
return f_arr
451464

@@ -463,7 +476,9 @@ def _rc_fft1d_impl(x, n=None, axis=-1, overwrite_arg=False):
463476
cdef long n_, axis_
464477
cdef int x_type, f_type, status, requirement
465478
cdef int HALF_HARMONICS = 0 # give only positive index harmonics
466-
direction = 1 # dummy, only used for the sake of arg-processing
479+
cdef int direction = 1 # dummy, only used for the sake of arg-processing
480+
cdef char * c_error_msg = NULL
481+
cdef bytes py_error_msg
467482

468483
x_arr = __process_arguments(x, n, axis, overwrite_arg, direction,
469484
&axis_, &n_, &in_place, &xnd, &dir_, 1)
@@ -501,7 +516,9 @@ def _rc_fft1d_impl(x, n=None, axis=-1, overwrite_arg=False):
501516
status = double_cdouble_mkl_fft1d_out(x_arr, n_, <int> axis_, f_arr, HALF_HARMONICS)
502517

503518
if (status):
504-
raise ValueError("Internal error occurred, with status={}".format(status))
519+
c_error_msg = mkl_dfti_error(status)
520+
py_error_msg = c_error_msg
521+
raise ValueError("Internal error occurred: {}".format(str(py_error_msg)))
505522

506523
return f_arr
507524

@@ -533,7 +550,9 @@ def _rc_ifft1d_impl(x, n=None, axis=-1, overwrite_arg=False):
533550
cdef int xnd, err, n_max = 0, in_place, dir_, int_n
534551
cdef long n_, axis_
535552
cdef int x_type, f_type, status
536-
direction = 1 # dummy, only used for the sake of arg-processing
553+
cdef int direction = 1 # dummy, only used for the sake of arg-processing
554+
cdef char * c_error_msg = NULL
555+
cdef bytes py_error_msg
537556

538557
int_n = _is_integral(n)
539558
# nn gives the number elements along axis of the input that we use
@@ -579,7 +598,9 @@ def _rc_ifft1d_impl(x, n=None, axis=-1, overwrite_arg=False):
579598
status = cdouble_double_mkl_irfft_out(x_arr, n_, <int> axis_, f_arr)
580599

581600
if (status):
582-
raise ValueError("Internal error occurred, status={}".format(status))
601+
c_error_msg = mkl_dfti_error(status)
602+
py_error_msg = c_error_msg
603+
raise ValueError("Internal error occurred: {}".format(str(py_error_msg)))
583604

584605
return f_arr
585606

mkl_fft/src/mklfft.c.src

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ static NPY_INLINE MKL_LONG _to_mkl_long(npy_intp x)
5454
return lr;
5555
}
5656

57+
NPY_INLINE char * mkl_dfti_error(MKL_LONG status)
58+
{
59+
return DftiErrorMessage(status);
60+
}
61+
5762
static npy_intp ar_size(npy_intp *sh, int len)
5863
{
5964
npy_intp r = (len > 0) ? 1 : 0;
@@ -567,11 +572,11 @@ int @name@_mkl_@mode@_in(PyArrayObject* x_inout, npy_intp n, int axis)
567572
}
568573

569574

570-
return OK;
575+
return status;
571576

572577
failed:
573578

574-
return ERROR;
579+
return status;
575580
}
576581
/**end repeat**/
577582

@@ -841,7 +846,6 @@ int @REALIN@_@COMPLEXOUT@_mkl_@mode@_out(
841846

842847
failed:
843848

844-
status = ERROR;
845849
goto cleanup;
846850
}
847851
/**end repeat**/
@@ -1016,7 +1020,6 @@ int @COMPLEXIN@_@COMPLEXOUT@_mkl_@mode@_out(
10161020

10171021
failed:
10181022

1019-
status = ERROR;
10201023
goto cleanup;
10211024
}
10221025
/**end repeat**/
@@ -1145,7 +1148,7 @@ int @name@_mkl_@mode@_in(PyArrayObject* x_inout, npy_intp n, int axis)
11451148

11461149
failed:
11471150

1148-
return ERROR;
1151+
return status;
11491152
}
11501153
/**end repeat**/
11511154

@@ -1317,7 +1320,6 @@ int
13171320

13181321
failed:
13191322

1320-
status = ERROR;
13211323
goto cleanup;
13221324
}
13231325
/**end repeat**/
@@ -1496,7 +1498,6 @@ int @name@_@name@_mkl_@mode@_out(
14961498

14971499
failed:
14981500

1499-
status = ERROR;
15001501
goto cleanup;
15011502
}
15021503
/**end repeat**/

mkl_fft/src/mklfft.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ extern int float_cfloat_mkl_fftnd_out(PyArrayObject*, PyArrayObject*);
7676
extern int float_cfloat_mkl_ifftnd_out(PyArrayObject*, PyArrayObject*);
7777
extern int double_cdouble_mkl_fftnd_out(PyArrayObject*, PyArrayObject*);
7878
extern int double_cdouble_mkl_ifftnd_out(PyArrayObject*, PyArrayObject*);
79+
80+
extern char* mkl_dfti_error(int);

0 commit comments

Comments
 (0)