Skip to content

Commit 649919f

Browse files
Merge pull request #19 from IntelPython/feature/set_num_stripes
Added set_num_stripes/get_num_stripes
2 parents 6f64750 + 90a3310 commit 649919f

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

mkl/_mkl_service.pxd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ cdef extern from "mkl.h":
7373
int MKL_CBWR_ERR_MODE_CHANGE_FAILURE
7474

7575
# ISA Constants
76+
int MKL_SINGLE_PATH_ENABLE
77+
int MKL_ENABLE_AVX512_E2
78+
int MKL_ENABLE_AVX512_E3
79+
int MKL_ENABLE_AVX512_E4
7680
int MKL_ENABLE_AVX512_MIC_E1
81+
int MKL_ENABLE_AVX512_E1
7782
int MKL_ENABLE_AVX512
7883
int MKL_ENABLE_AVX512_MIC
7984
int MKL_ENABLE_AVX2
85+
int MKL_ENABLE_AVX2_E1
8086
int MKL_ENABLE_AVX
8187
int MKL_ENABLE_SSE4_2
8288

@@ -131,6 +137,8 @@ cdef extern from "mkl.h":
131137
int mkl_get_max_threads()
132138
int mkl_domain_get_max_threads(int domain)
133139
int mkl_get_dynamic()
140+
int mkl_get_num_stripes()
141+
void mkl_set_num_stripes(int)
134142

135143
# Timing
136144
float second()

mkl/_mkl_service.pyx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ cpdef get_max_threads():
153153

154154
cpdef domain_get_max_threads(domain='all'):
155155
"""
156-
Gets the number of OpenMP* threads targeted for parallelism for a particular function domain.
156+
Gets the number of OpenMP* threads targeted for parallelism for a particular
157+
function domain.
157158
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-domain-get-max-threads
158159
"""
159160
cdef int c_mkl_domain = __domain_to_mkl_domain(domain)
@@ -162,12 +163,47 @@ cpdef domain_get_max_threads(domain='all'):
162163

163164
cpdef get_dynamic():
164165
"""
165-
Determines whether Intel(R) MKL is enabled to dynamically change the number of OpenMP* threads.
166+
Determines whether Intel(R) MKL is enabled to dynamically change the number
167+
of OpenMP* threads.
166168
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-get-dynamic
167169
"""
168170
return bool(__get_dynamic())
169171

170172

173+
cpdef int set_num_stripes(int num_stripes):
174+
"""
175+
Specifies the number of stripes, or partitions along the leading dimension
176+
of the output matrix, for the parallel ``?gemm`` functions.
177+
178+
Setting `num_stripes` argument to zero instructs Intel(R) MKL to default
179+
partitioning algorithm. A positive `num_stripes` arguments specifies a hint,
180+
and the library may actually use a smaller numbers.
181+
182+
Returns the number of stripes the library uses, or a zero.
183+
"""
184+
if num_stripes < 0:
185+
raise ValueError(
186+
"Expected non-negative number of stripes"
187+
", got {}".format(num_stripes)
188+
)
189+
mkl.mkl_set_num_stripes(num_stripes)
190+
return mkl.mkl_get_num_stripes()
191+
192+
193+
cpdef int get_num_stripes():
194+
"""
195+
Returns the number of stripes, or partitions along the leading dimension
196+
of the output matrix, for the parallel ``?gemm`` functions.
197+
198+
Non-positive returned value indicates Intel(R) MKL uses default partitioning
199+
algorithm.
200+
201+
Positive returned value is a hint, and the library may actually use a
202+
smaller number.
203+
"""
204+
return mkl.mkl_get_num_stripes()
205+
206+
171207
# Timing
172208
cpdef second():
173209
"""
@@ -759,13 +795,20 @@ cdef object __cbwr_get_auto_branch():
759795
cdef object __enable_instructions(isa=None):
760796
"""
761797
Enables dispatching for new Intel architectures or restricts the set of Intel instruction sets available for dispatching.
798+
762799
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-enable-instructions
763800
"""
764801
__variables = {
765802
'input': {
803+
'single_path': mkl.MKL_SINGLE_PATH_ENABLE,
804+
'avx512_e4': mkl.MKL_ENABLE_AVX512_E4,
805+
'avx512_e3': mkl.MKL_ENABLE_AVX512_E3,
806+
'avx512_e2': mkl.MKL_ENABLE_AVX512_E2,
807+
'avx512_e1': mkl.MKL_ENABLE_AVX512_E1,
766808
'avx512_mic_e1': mkl.MKL_ENABLE_AVX512_MIC_E1,
767809
'avx512': mkl.MKL_ENABLE_AVX512,
768810
'avx512_mic': mkl.MKL_ENABLE_AVX512_MIC,
811+
'avx2_e1': mkl.MKL_ENABLE_AVX2_E1,
769812
'avx2': mkl.MKL_ENABLE_AVX2,
770813
'avx': mkl.MKL_ENABLE_AVX,
771814
'sse4_2': mkl.MKL_ENABLE_SSE4_2,

0 commit comments

Comments
 (0)