Skip to content

Commit 8ec516b

Browse files
further polishing with removing inline where function is bulky or returning an object
1 parent 15be6f6 commit 8ec516b

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

mkl/_mkl_service.pyx

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ cpdef domain_set_num_threads(num_threads, domain='all'):
102102
__check_positive_num_threads(c_num_threads, 'domain_set_num_threads')
103103

104104
cdef int c_mkl_domain = __domain_to_mkl_domain(domain)
105-
cdef int mkl_status = __domain_set_num_threads(c_num_threads, c_mkl_domain)
105+
cdef int c_mkl_status = __domain_set_num_threads(c_num_threads, c_mkl_domain)
106106

107-
return __mkl_status_to_string(mkl_status)
107+
return __mkl_status_to_string(c_mkl_status)
108108

109109

110110
cpdef set_num_threads_local(num_threads):
@@ -598,7 +598,7 @@ cdef inline MemStatData __mem_stat():
598598
return mem_stat_data
599599

600600

601-
cdef inline __peak_mem_usage(mem_const):
601+
cdef object __peak_mem_usage(mem_const):
602602
"""
603603
Reports the peak memory allocated by the Intel(R) MKL Memory Allocator.
604604
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-peak-mem-usage
@@ -622,7 +622,7 @@ cdef inline __peak_mem_usage(mem_const):
622622
return memory_allocator
623623

624624

625-
cdef inline __set_memory_limit(limit):
625+
cdef inline object __set_memory_limit(limit):
626626
"""
627627
On Linux, sets the limit of memory that Intel(R) MKL can allocate for a specified type of memory.
628628
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-set-memory-limit
@@ -634,7 +634,7 @@ cdef inline __set_memory_limit(limit):
634634

635635

636636
# Conditional Numerical Reproducibility
637-
cdef inline __cbwr_set(branch=None):
637+
cdef object __cbwr_set(branch=None):
638638
"""
639639
Configures the CNR mode of Intel(R) MKL.
640640
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-cbwr-set
@@ -704,13 +704,12 @@ cdef inline __cbwr_get(cnr_const=None):
704704
return status
705705

706706

707-
cdef inline __cbwr_get_auto_branch():
707+
cdef object __cbwr_get_auto_branch():
708708
"""
709709
Automatically detects the CNR code branch for your platform.
710710
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-cbwr-get-auto-branch
711711
"""
712712
__variables = {
713-
'input': None,
714713
'output': {
715714
mkl.MKL_CBWR_AUTO: 'auto',
716715
mkl.MKL_CBWR_COMPATIBLE: 'compatible',
@@ -733,7 +732,7 @@ cdef inline __cbwr_get_auto_branch():
733732

734733

735734
# Miscellaneous
736-
cdef inline __enable_instructions(isa=None):
735+
cdef object __enable_instructions(isa=None):
737736
"""
738737
Enables dispatching for new Intel architectures or restricts the set of Intel instruction sets available for dispatching.
739738
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-enable-instructions
@@ -747,20 +746,15 @@ cdef inline __enable_instructions(isa=None):
747746
'avx': mkl.MKL_ENABLE_AVX,
748747
'sse4_2': mkl.MKL_ENABLE_SSE4_2,
749748
},
750-
'output': {
751-
0: 'error',
752-
1: 'success',
753-
},
754749
}
755-
mkl_isa = __mkl_str_to_int(isa, __variables['input'])
750+
cdef int c_mkl_isa = __mkl_str_to_int(isa, __variables['input'])
756751

757-
mkl_status = mkl.mkl_enable_instructions(mkl_isa)
758-
759-
status = __mkl_int_to_str(mkl_status, __variables['output'])
760-
return status
752+
cdef int c_mkl_status = mkl.mkl_enable_instructions(c_mkl_isa)
753+
754+
return __mkl_status_to_string(c_mkl_status)
761755

762756

763-
cdef inline __set_env_mode():
757+
cdef object __set_env_mode():
764758
"""
765759
Sets up the mode that ignores environment settings specific to Intel(R) MKL. See mkl_set_env_mode(1).
766760
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-set-env-mode
@@ -772,27 +766,26 @@ cdef inline __set_env_mode():
772766
1: 'ignore',
773767
},
774768
}
775-
mkl_status = mkl.mkl_set_env_mode(1)
769+
cdef int c_mkl_status = mkl.mkl_set_env_mode(1)
776770

777-
status = __mkl_int_to_str(mkl_status, __variables['output'])
771+
status = __mkl_int_to_str(c_mkl_status, __variables['output'])
778772
return status
779773

780774

781-
cdef inline __get_env_mode():
775+
cdef object __get_env_mode():
782776
"""
783777
Query the current environment mode. See mkl_set_env_mode(0).
784778
https://software.intel.com/en-us/mkl-developer-reference-c-mkl-set-env-mode
785779
"""
786780
__variables = {
787-
'input': None,
788781
'output': {
789782
0: 'default',
790783
1: 'ignore',
791784
},
792785
}
793-
mkl_status = mkl.mkl_set_env_mode(0)
786+
cdef int c_mkl_status = mkl.mkl_set_env_mode(0)
794787

795-
status = __mkl_int_to_str(mkl_status, __variables['output'])
788+
status = __mkl_int_to_str(c_mkl_status, __variables['output'])
796789
return status
797790

798791

@@ -842,7 +835,7 @@ cdef __set_mpi(vendor, custom_library_name=None):
842835

843836

844837
# VM Service Functions
845-
cdef inline __vml_set_mode(accuracy, ftzdaz, errmode):
838+
cdef object __vml_set_mode(accuracy, ftzdaz, errmode):
846839
"""
847840
Sets a new mode for VM functions according to the mode parameter and stores the previous VM mode to oldmode.
848841
https://software.intel.com/en-us/mkl-developer-reference-c-vmlsetmode
@@ -888,25 +881,31 @@ cdef inline __vml_set_mode(accuracy, ftzdaz, errmode):
888881
},
889882
},
890883
}
891-
mkl_accuracy = __mkl_str_to_int(accuracy, __variables['input']['accuracy'])
892-
mkl_ftzdaz = __mkl_str_to_int(ftzdaz, __variables['input']['ftzdaz'])
893-
mkl_errmode = __mkl_str_to_int(errmode, __variables['input']['errmode'])
884+
cdef int c_mkl_accuracy = __mkl_str_to_int(accuracy, __variables['input']['accuracy'])
885+
cdef int c_mkl_ftzdaz = __mkl_str_to_int(ftzdaz, __variables['input']['ftzdaz'])
886+
cdef int c_mkl_errmode = __mkl_str_to_int(errmode, __variables['input']['errmode'])
887+
888+
cdef int c_mkl_status = mkl.vmlSetMode(c_mkl_accuracy | c_mkl_ftzdaz | c_mkl_errmode)
894889

895-
status = mkl.vmlSetMode(mkl_accuracy | mkl_ftzdaz | mkl_errmode)
890+
accuracy = __mkl_int_to_str(
891+
c_mkl_status & mkl.VML_ACCURACY_MASK,
892+
__variables['output']['accuracy'])
893+
ftzdaz = __mkl_int_to_str(
894+
c_mkl_status & mkl.VML_FTZDAZ_MASK,
895+
__variables['output']['ftzdaz'])
896+
errmode = __mkl_int_to_str(
897+
c_mkl_status & mkl.VML_ERRMODE_MASK,
898+
__variables['output']['errmode'])
896899

897-
accuracy = __mkl_int_to_str(status & mkl.VML_ACCURACY_MASK, __variables['output']['accuracy'])
898-
ftzdaz = __mkl_int_to_str(status & mkl.VML_FTZDAZ_MASK, __variables['output']['ftzdaz'])
899-
errmode = __mkl_int_to_str(status & mkl.VML_ERRMODE_MASK, __variables['output']['errmode'])
900-
return accuracy, ftzdaz, errmode
900+
return (accuracy, ftzdaz, errmode)
901901

902902

903-
cdef inline __vml_get_mode():
903+
cdef object __vml_get_mode():
904904
"""
905905
Gets the VM mode.
906906
https://software.intel.com/en-us/mkl-developer-reference-c-vmlgetmode
907907
"""
908908
__variables = {
909-
'input': None,
910909
'output': {
911910
'accuracy': {
912911
mkl.VML_HA: 'ha',
@@ -929,12 +928,18 @@ cdef inline __vml_get_mode():
929928
},
930929
}
931930

932-
status = mkl.vmlGetMode()
931+
cdef int c_mkl_status = mkl.vmlGetMode()
933932

934-
accuracy = __mkl_int_to_str(status & mkl.VML_ACCURACY_MASK, __variables['output']['accuracy'])
935-
ftzdaz = __mkl_int_to_str(status & mkl.VML_FTZDAZ_MASK, __variables['output']['ftzdaz'])
936-
errmode = __mkl_int_to_str(status & mkl.VML_ERRMODE_MASK, __variables['output']['errmode'])
937-
return accuracy, ftzdaz, errmode
933+
accuracy = __mkl_int_to_str(
934+
c_mkl_status & mkl.VML_ACCURACY_MASK,
935+
__variables['output']['accuracy'])
936+
ftzdaz = __mkl_int_to_str(
937+
c_mkl_status & mkl.VML_FTZDAZ_MASK,
938+
__variables['output']['ftzdaz'])
939+
errmode = __mkl_int_to_str(
940+
c_mkl_status & mkl.VML_ERRMODE_MASK,
941+
__variables['output']['errmode'])
942+
return (accuracy, ftzdaz, errmode)
938943

939944

940945
__mkl_vml_status = {
@@ -949,7 +954,7 @@ __mkl_vml_status = {
949954
}
950955

951956

952-
cdef inline __vml_set_err_status(status):
957+
cdef object __vml_set_err_status(status):
953958
"""
954959
Sets the new VM Error Status according to err and stores the previous VM Error Status to olderr.
955960
https://software.intel.com/en-us/mkl-developer-reference-c-vmlseterrstatus
@@ -976,15 +981,15 @@ cdef inline __vml_set_err_status(status):
976981
mkl.VML_STATUS_UNDERFLOW: 'underflow',
977982
},
978983
}
979-
mkl_status_in = __mkl_str_to_int(status, __variables['input'])
984+
cdef int mkl_status_in = __mkl_str_to_int(status, __variables['input'])
980985

981-
mkl_status_out = mkl.vmlSetErrStatus(mkl_status_in)
986+
cdef int mkl_status_out = mkl.vmlSetErrStatus(mkl_status_in)
982987

983988
status = __mkl_int_to_str(mkl_status_out, __variables['output'])
984989
return status
985990

986991

987-
cdef inline __vml_get_err_status():
992+
cdef object __vml_get_err_status():
988993
"""
989994
Gets the VM Error Status.
990995
https://software.intel.com/en-us/mkl-developer-reference-c-vmlgeterrstatus
@@ -1003,13 +1008,13 @@ cdef inline __vml_get_err_status():
10031008
},
10041009
}
10051010

1006-
mkl_status = mkl.vmlGetErrStatus()
1011+
cdef int mkl_status = mkl.vmlGetErrStatus()
10071012

10081013
status = __mkl_int_to_str(mkl_status, __variables['output'])
10091014
return status
10101015

10111016

1012-
cdef inline __vml_clear_err_status():
1017+
cdef object __vml_clear_err_status():
10131018
"""
10141019
Sets the VM Error Status to VML_STATUS_OK and stores the previous VM Error Status to olderr.
10151020
https://software.intel.com/en-us/mkl-developer-reference-c-vmlclearerrstatus
@@ -1028,7 +1033,7 @@ cdef inline __vml_clear_err_status():
10281033
},
10291034
}
10301035

1031-
mkl_status = mkl.vmlClearErrStatus()
1036+
cdef int mkl_status = mkl.vmlClearErrStatus()
10321037

10331038
status = __mkl_int_to_str(mkl_status, __variables['output'])
10341039
return status

0 commit comments

Comments
 (0)