@@ -3,24 +3,19 @@ from enum import IntEnum
3
3
4
4
5
5
class enums (IntEnum ):
6
- # MKL Function Domains
6
+ # MKL Function Domains Constants
7
7
MKL_DOMAIN_BLAS = mkl.MKL_DOMAIN_BLAS
8
8
MKL_DOMAIN_FFT = mkl.MKL_DOMAIN_FFT
9
9
MKL_DOMAIN_VML = mkl.MKL_DOMAIN_VML
10
10
MKL_DOMAIN_PARDISO = mkl.MKL_DOMAIN_PARDISO
11
11
MKL_DOMAIN_ALL = mkl.MKL_DOMAIN_ALL
12
12
13
- # MKL_INT64 mkl_peak_mem_usage(int mode)
14
- # In
13
+ # MKL Peak Memory Usage Constants
15
14
MKL_PEAK_MEM_ENABLE = mkl.MKL_PEAK_MEM_ENABLE
16
15
MKL_PEAK_MEM_DISABLE = mkl.MKL_PEAK_MEM_DISABLE
17
16
MKL_PEAK_MEM = mkl.MKL_PEAK_MEM
18
17
MKL_PEAK_MEM_RESET = mkl.MKL_PEAK_MEM_RESET
19
18
20
- # int mkl_set_memory_limit(int mem_type, size_t limit)
21
- # In
22
- MKL_MEM_MCDRAM = mkl.MKL_MEM_MCDRAM
23
-
24
19
# CNR Control Constants
25
20
MKL_CBWR_AUTO = mkl.MKL_CBWR_AUTO
26
21
MKL_CBWR_COMPATIBLE = mkl.MKL_CBWR_COMPATIBLE
@@ -40,14 +35,19 @@ class enums(IntEnum):
40
35
MKL_CBWR_ERR_UNSUPPORTED_BRANCH = mkl.MKL_CBWR_ERR_UNSUPPORTED_BRANCH
41
36
MKL_CBWR_ERR_MODE_CHANGE_FAILURE = mkl.MKL_CBWR_ERR_MODE_CHANGE_FAILURE
42
37
43
- # int mkl_enable_instructions(int isa)
44
- # In
38
+ # ISA Constants
45
39
MKL_ENABLE_AVX512 = mkl.MKL_ENABLE_AVX512
46
40
MKL_ENABLE_AVX512_MIC = mkl.MKL_ENABLE_AVX512_MIC
47
41
MKL_ENABLE_AVX2 = mkl.MKL_ENABLE_AVX2
48
42
MKL_ENABLE_AVX = mkl.MKL_ENABLE_AVX
49
43
MKL_ENABLE_SSE4_2 = mkl.MKL_ENABLE_SSE4_2
50
44
45
+ # MPI Implementation Constants
46
+ MKL_BLACS_CUSTOM = mkl.MKL_BLACS_CUSTOM
47
+ MKL_BLACS_MSMPI = mkl.MKL_BLACS_MSMPI
48
+ MKL_BLACS_INTELMPI = mkl.MKL_BLACS_INTELMPI
49
+ # MKL_BLACS_MPICH = mkl.MKL_BLACS_MPICH
50
+
51
51
# unsigned int vmlSetMode(unsigned int mode)
52
52
# In
53
53
VML_HA = mkl.VML_HA
@@ -73,14 +73,20 @@ class enums(IntEnum):
73
73
VML_STATUS_OVERFLOW = mkl.VML_STATUS_OVERFLOW
74
74
VML_STATUS_UNDERFLOW = mkl.VML_STATUS_UNDERFLOW
75
75
76
- # MKL Function Domains
76
+ # MKL Function Domains Constants
77
77
__mkl_domain_enums = {' blas' : mkl.MKL_DOMAIN_BLAS,
78
78
' fft' : mkl.MKL_DOMAIN_FFT,
79
79
' vml' : mkl.MKL_DOMAIN_VML,
80
80
' pardiso' : mkl.MKL_DOMAIN_PARDISO,
81
81
' all' : mkl.MKL_DOMAIN_ALL}
82
82
83
- # CNR Control Constants
83
+ # MKL Peak Memory Usage Constants
84
+ __mkl_peak_mem_usage_enums = {' enable' : mkl.MKL_PEAK_MEM_ENABLE,
85
+ ' disable' : mkl.MKL_PEAK_MEM_DISABLE,
86
+ ' peak_mem' : mkl.MKL_PEAK_MEM,
87
+ ' peak_mem_reset' : mkl.MKL_PEAK_MEM_RESET}
88
+
89
+ # CNR Control Constants Constants
84
90
__mkl_cbwr_set_in_enums = {' auto' : mkl.MKL_CBWR_AUTO,
85
91
' compatible' : mkl.MKL_CBWR_COMPATIBLE,
86
92
' sse2' : mkl.MKL_CBWR_SSE2,
@@ -108,6 +114,19 @@ __mkl_cbwr_get_out_enums.update({value: key for key, value in __mkl_cbwr_set_in_
108
114
__mkl_cbwr_get_auto_branch_out_enums = {}
109
115
__mkl_cbwr_get_auto_branch_out_enums.update({value: key for key, value in __mkl_cbwr_set_in_enums.items()})
110
116
117
+ # ISA Constants
118
+ __mkl_isa_enums = {' avx512' : mkl.MKL_ENABLE_AVX512,
119
+ ' avx512_mic' : mkl.MKL_ENABLE_AVX512_MIC,
120
+ ' avx2' : mkl.MKL_ENABLE_AVX2,
121
+ ' avx' : mkl.MKL_ENABLE_AVX,
122
+ ' sse4_2' : mkl.MKL_ENABLE_SSE4_2}
123
+
124
+ # MPI Implementation Constants
125
+ __mkl_blacs_enums = {' custom' : mkl.MKL_BLACS_CUSTOM,
126
+ ' msmpi' : mkl.MKL_BLACS_MSMPI,
127
+ ' intelmpi' : mkl.MKL_BLACS_INTELMPI}
128
+ # 'mpich': mkl.MKL_BLACS_MPICH}
129
+
111
130
112
131
'''
113
132
# MKL support functions
@@ -287,12 +306,35 @@ def mkl_mem_stat():
287
306
return AllocatedBytes, AllocatedBuffers
288
307
289
308
290
- def mkl_peak_mem_usage (mode ):
291
- return mkl.mkl_peak_mem_usage(mode)
309
+ def mkl_peak_mem_usage (mem_const ):
310
+ mem_const_type = type (mem_const)
311
+ if mem_const_type is str :
312
+ assert (mem_const in __mkl_peak_mem_usage_enums.keys())
313
+ mem_const = __mkl_peak_mem_usage_enums[mem_const]
314
+ else :
315
+ assert ((mem_const_type is int ) and (mem_const in __mkl_peak_mem_usage_enums.values()))
316
+
317
+ memory_allocator = mkl.mkl_peak_mem_usage(mem_const)
318
+ assert (type (memory_allocator) is int )
319
+ assert (memory_allocator >= - 1 )
320
+
321
+ if memory_allocator == - 1 :
322
+ memory_allocator = ' error'
323
+
324
+ return memory_allocator
292
325
293
326
294
- def mkl_set_memory_limit (mem_type , limit ):
295
- return mkl.mkl_set_memory_limit(mem_type, limit)
327
+ def mkl_set_memory_limit (limit ):
328
+ assert (limit >= 0 )
329
+ status = mkl.mkl_set_memory_limit(mkl.MKL_MEM_MCDRAM, limit)
330
+ assert ((status == 0 ) or (status == 1 ))
331
+
332
+ if status == 1 :
333
+ status = ' success'
334
+ else :
335
+ status = ' error'
336
+
337
+ return status
296
338
297
339
298
340
'''
@@ -301,7 +343,7 @@ def mkl_set_memory_limit(mem_type, limit):
301
343
int mkl_cbwr_get(int option)
302
344
int mkl_cbwr_get_auto_branch()
303
345
'''
304
- def mkl_cbwr_set (branch = ' ' ):
346
+ def mkl_cbwr_set (branch = None ):
305
347
branch_type = type (branch)
306
348
if branch_type is str :
307
349
assert (branch in __mkl_cbwr_set_in_enums.keys())
@@ -315,7 +357,7 @@ def mkl_cbwr_set(branch=''):
315
357
return __mkl_cbwr_set_out_enums[status]
316
358
317
359
318
- def mkl_cbwr_get (cnr_const = ' ' ):
360
+ def mkl_cbwr_get (cnr_const = None ):
319
361
cnr_const_type = type (cnr_const)
320
362
if cnr_const_type is str :
321
363
assert (cnr_const in __mkl_cbwr_get_in_enums)
@@ -346,11 +388,31 @@ def mkl_cbwr_get_auto_branch():
346
388
int mkl_verbose(int enable)
347
389
int mkl_set_mpi (int vendor, const char *custom_library_name)
348
390
'''
349
- def mkl_enable_instructions (isa ):
350
- return mkl.mkl_enable_instructions(isa)
391
+ __mkl_isa_enums
392
+ def mkl_enable_instructions (isa = None ):
393
+ isa_type = type (isa)
394
+ if isa_type is str :
395
+ assert (isa in __mkl_isa_enums)
396
+ isa = __mkl_isa_enums[isa]
397
+ else :
398
+ assert (issubclass (isa_type, IntEnum))
399
+ assert (type (isa.value) is int )
400
+ assert (isa.value in __mkl_isa_enums.values())
401
+ isa = isa.value
402
+
403
+ status = mkl.mkl_enable_instructions(isa)
404
+ assert ((status == 0 ) or (status == 1 ))
405
+
406
+ if (status == 1 ):
407
+ status = ' success'
408
+ else :
409
+ status = ' error'
410
+
411
+ return status
351
412
352
413
353
414
def mkl_set_env_mode (mode ):
415
+ assert ((mode == 0 ) or (mode == 1 ))
354
416
return mkl.mkl_set_env_mode(mode)
355
417
356
418
@@ -360,9 +422,31 @@ def mkl_verbose(enable):
360
422
361
423
362
424
def mkl_set_mpi (vendor , custom_library_name ):
425
+ vendor_type = type (vendor)
426
+ if vendor_type is str :
427
+ assert (vendor in __mkl_blacs_enums)
428
+ vendor = __mkl_blacs_enums[vendor]
429
+ else :
430
+ assert (issubclass (vendor_type, IntEnum))
431
+ assert (type (vendor.value) is int )
432
+ assert (vendor.value in __mkl_blacs_enums.values())
433
+ vendor = vendor.value
434
+
363
435
cdef bytes c_bytes = custom_library_name.encode()
364
436
cdef char * c_string = c_bytes
365
- return mkl.mkl_set_mpi(vendor, c_string)
437
+ status = mkl.mkl_set_mpi(vendor, c_string)
438
+ assert (status in range (- 3 , 1 ))
439
+
440
+ if status == 0 :
441
+ status = ' success'
442
+ elif status == - 1 :
443
+ status = ' vendor_invalid'
444
+ elif status == ' -2' :
445
+ status = ' custom_library_name_invalid'
446
+ else :
447
+ status = ' the MPI library cannot be set at this point'
448
+
449
+ return status
366
450
367
451
368
452
'''
0 commit comments