Skip to content

Commit e32e3ba

Browse files
Merge pull request #34 from IntelPython/cleanup-code
Cleanup code
2 parents 1bc00fa + 204c059 commit e32e3ba

File tree

5 files changed

+143
-70
lines changed

5 files changed

+143
-70
lines changed

mkl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2019, Intel Corporation
1+
# Copyright (c) 2018-2024, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions are met:

mkl/_mkl_service.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2019, Intel Corporation
1+
# Copyright (c) 2018-2024, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions are met:

mkl/_mkl_service.pyx

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2019, Intel Corporation
1+
# Copyright (c) 2018-2024, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions are met:
@@ -391,33 +391,33 @@ cpdef vml_clear_err_status():
391391
return __vml_clear_err_status()
392392

393393

394-
cdef __mkl_status_to_string(int mkl_status):
394+
cdef str __mkl_status_to_string(int mkl_status) noexcept:
395395
if mkl_status == 1:
396396
return 'success'
397397
else:
398398
return 'error'
399399

400400

401-
cdef int __python_obj_to_int(obj, func_name):
401+
cdef int __python_obj_to_int(obj, func_name) except *:
402402
if not isinstance(obj, numbers.Integral):
403403
raise ValueError("The argument of " + func_name + " is expected to be a positive integer")
404404
cdef int c_int = <int>obj
405405
return c_int
406406

407407

408-
cdef void __check_positive_num_threads(int p, func_name):
408+
cdef void __check_positive_num_threads(int p, func_name) except *:
409409
if p <= 0:
410410
warnings.warn("Non-positive argument of " + func_name +
411411
" is being ignored, number of threads will not be changed")
412412

413413

414-
cdef void __check_non_negative_num_threads(int p, func_name):
414+
cdef void __check_non_negative_num_threads(int p, func_name) except *:
415415
if p < 0:
416416
warnings.warn("Negative argument of " + func_name +
417417
" is being ignored, number of threads will not be changed")
418418

419419

420-
cdef inline int __mkl_str_to_int(variable, possible_variables_dict):
420+
cdef inline int __mkl_str_to_int(variable, possible_variables_dict) except *:
421421
if variable is None:
422422
raise ValueError("Variable can not be None")
423423
if possible_variables_dict is None:
@@ -429,7 +429,7 @@ cdef inline int __mkl_str_to_int(variable, possible_variables_dict):
429429
return possible_variables_dict[variable]
430430

431431

432-
cdef __mkl_int_to_str(int mkl_int_variable, possible_variables_dict):
432+
cdef __mkl_int_to_str(int mkl_int_variable, possible_variables_dict) except *:
433433
if possible_variables_dict is None:
434434
raise RuntimeError("Dictionary mapping possible internal code to output string is missing")
435435

@@ -441,7 +441,7 @@ cdef __mkl_int_to_str(int mkl_int_variable, possible_variables_dict):
441441

442442

443443
# Version Information
444-
cdef inline mkl.MKLVersion __get_version():
444+
cdef mkl.MKLVersion __get_version() noexcept:
445445
"""
446446
Returns the Intel(R) MKL version.
447447
"""
@@ -450,7 +450,7 @@ cdef inline mkl.MKLVersion __get_version():
450450
return c_mkl_version
451451

452452

453-
cdef __get_version_string():
453+
cdef str __get_version_string() except *:
454454
"""
455455
Returns the Intel(R) MKL version in a character string.
456456
"""
@@ -461,7 +461,7 @@ cdef __get_version_string():
461461

462462

463463
# Threading
464-
cdef inline int __set_num_threads(int num_threads):
464+
cdef inline int __set_num_threads(int num_threads) noexcept:
465465
"""
466466
Specifies the number of OpenMP* threads to use.
467467
"""
@@ -471,15 +471,15 @@ cdef inline int __set_num_threads(int num_threads):
471471
return prev_num_threads
472472

473473

474-
cdef inline int __domain_set_num_threads(int c_num_threads, int mkl_domain):
474+
cdef inline int __domain_set_num_threads(int c_num_threads, int mkl_domain) noexcept:
475475
"""
476476
Specifies the number of OpenMP* threads for a particular function domain.
477477
"""
478478
cdef int mkl_status = mkl.mkl_domain_set_num_threads(c_num_threads, mkl_domain)
479479
return mkl_status
480480

481481

482-
cdef inline int __set_num_threads_local(int c_num_threads):
482+
cdef inline int __set_num_threads_local(int c_num_threads) noexcept:
483483
"""
484484
Specifies the number of OpenMP* threads for all Intel(R) MKL functions on the current execution thread.
485485
"""
@@ -488,7 +488,7 @@ cdef inline int __set_num_threads_local(int c_num_threads):
488488
return c_mkl_status
489489

490490

491-
cdef inline int __set_dynamic(int c_enable):
491+
cdef inline int __set_dynamic(int c_enable) noexcept:
492492
"""
493493
Enables Intel(R) MKL to dynamically change the number of OpenMP* threads.
494494
"""
@@ -497,14 +497,14 @@ cdef inline int __set_dynamic(int c_enable):
497497
return __get_max_threads()
498498

499499

500-
cdef inline int __get_max_threads():
500+
cdef inline int __get_max_threads() noexcept:
501501
"""
502502
Gets the number of OpenMP* threads targeted for parallelism.
503503
"""
504504
return mkl.mkl_get_max_threads()
505505

506506

507-
cdef inline int __domain_get_max_threads(int c_mkl_domain):
507+
cdef inline int __domain_get_max_threads(int c_mkl_domain) noexcept:
508508
"""
509509
Gets the number of OpenMP* threads targeted for parallelism for a particular function domain.
510510
"""
@@ -513,15 +513,15 @@ cdef inline int __domain_get_max_threads(int c_mkl_domain):
513513
return c_num_threads
514514

515515

516-
cdef inline int __get_dynamic():
516+
cdef inline int __get_dynamic() noexcept:
517517
"""
518518
Determines whether Intel(R) MKL is enabled to dynamically change the number of OpenMP* threads.
519519
"""
520520
return mkl.mkl_get_dynamic()
521521

522522

523523
# Timing
524-
cdef inline float __second():
524+
cdef inline float __second() noexcept:
525525
"""
526526
Returns elapsed time in seconds.
527527
Use to estimate real time between two calls to this function.
@@ -530,7 +530,7 @@ cdef inline float __second():
530530
return mkl.second()
531531

532532

533-
cdef inline double __dsecnd():
533+
cdef inline double __dsecnd() noexcept:
534534
"""
535535
Returns elapsed time in seconds.
536536
Use to estimate real time between two calls to this function.
@@ -539,7 +539,7 @@ cdef inline double __dsecnd():
539539
return mkl.dsecnd()
540540

541541

542-
cdef inline mkl.MKL_UINT64 __get_cpu_clocks():
542+
cdef inline mkl.MKL_UINT64 __get_cpu_clocks() noexcept:
543543
"""
544544
Returns elapsed CPU clocks.
545545
"""
@@ -548,52 +548,52 @@ cdef inline mkl.MKL_UINT64 __get_cpu_clocks():
548548
return clocks
549549

550550

551-
cdef inline double __get_cpu_frequency():
551+
cdef inline double __get_cpu_frequency() noexcept:
552552
"""
553553
Returns the current CPU frequency value in GHz.
554554
"""
555555
return mkl.mkl_get_cpu_frequency()
556556

557557

558-
cdef inline double __get_max_cpu_frequency():
558+
cdef inline double __get_max_cpu_frequency() noexcept:
559559
"""
560560
Returns the maximum CPU frequency value in GHz.
561561
"""
562562
return mkl.mkl_get_max_cpu_frequency()
563563

564564

565-
cdef inline double __get_clocks_frequency():
565+
cdef inline double __get_clocks_frequency() noexcept:
566566
"""
567567
Returns the frequency value in GHz based on constant-rate Time Stamp Counter.
568568
"""
569569
return mkl.mkl_get_clocks_frequency()
570570

571571

572572
# Memory Management. See the Intel(R) MKL Developer Guide for more memory usage information.
573-
cdef inline void __free_buffers():
573+
cdef inline void __free_buffers() noexcept:
574574
"""
575575
Frees unused memory allocated by the Intel(R) MKL Memory Allocator.
576576
"""
577577
mkl.mkl_free_buffers()
578578
return
579579

580580

581-
cdef inline void __thread_free_buffers():
581+
cdef inline void __thread_free_buffers() noexcept:
582582
"""
583583
Frees unused memory allocated by the Intel(R) MKL Memory Allocator in the current thread.
584584
"""
585585
mkl.mkl_thread_free_buffers()
586586
return
587587

588588

589-
cdef inline int __disable_fast_mm():
589+
cdef inline int __disable_fast_mm() noexcept:
590590
"""
591591
Turns off the Intel(R) MKL Memory Allocator for Intel(R) MKL functions to directly use the system malloc/free functions.
592592
"""
593593
return mkl.mkl_disable_fast_mm()
594594

595595

596-
cdef inline MemStatData __mem_stat():
596+
cdef inline MemStatData __mem_stat() noexcept:
597597
"""
598598
Reports the status of the Intel(R) MKL Memory Allocator.
599599
"""
@@ -602,7 +602,7 @@ cdef inline MemStatData __mem_stat():
602602
return mem_stat_data
603603

604604

605-
cdef object __peak_mem_usage(mem_const):
605+
cdef object __peak_mem_usage(mem_const) except *:
606606
"""
607607
Reports the peak memory allocated by the Intel(R) MKL Memory Allocator.
608608
"""
@@ -625,7 +625,7 @@ cdef object __peak_mem_usage(mem_const):
625625
return memory_allocator
626626

627627

628-
cdef inline object __set_memory_limit(limit):
628+
cdef inline object __set_memory_limit(limit) except *:
629629
"""
630630
On Linux, sets the limit of memory that Intel(R) MKL can allocate for a specified type of memory.
631631
"""
@@ -636,7 +636,7 @@ cdef inline object __set_memory_limit(limit):
636636

637637

638638
# Conditional Numerical Reproducibility
639-
cdef object __cbwr_set(branch=None):
639+
cdef object __cbwr_set(branch=None) except *:
640640
"""
641641
Configures the CNR mode of Intel(R) MKL.
642642
"""
@@ -676,7 +676,7 @@ cdef object __cbwr_set(branch=None):
676676
return status
677677

678678

679-
cdef inline __cbwr_get(cnr_const=None):
679+
cdef inline __cbwr_get(cnr_const=None) except *:
680680
"""
681681
Returns the current CNR settings.
682682
"""
@@ -714,7 +714,7 @@ cdef inline __cbwr_get(cnr_const=None):
714714
return status
715715

716716

717-
cdef object __cbwr_get_auto_branch():
717+
cdef object __cbwr_get_auto_branch() except *:
718718
"""
719719
Automatically detects the CNR code branch for your platform.
720720
"""
@@ -749,7 +749,7 @@ cdef object __cbwr_get_auto_branch():
749749

750750

751751
# Miscellaneous
752-
cdef object __enable_instructions(isa=None):
752+
cdef object __enable_instructions(isa=None) except *:
753753
"""
754754
Enables dispatching for new Intel architectures or restricts the set of Intel instruction sets available for dispatching.
755755
"""
@@ -776,7 +776,7 @@ cdef object __enable_instructions(isa=None):
776776
return __mkl_status_to_string(c_mkl_status)
777777

778778

779-
cdef object __set_env_mode():
779+
cdef object __set_env_mode() except *:
780780
"""
781781
Sets up the mode that ignores environment settings specific to Intel(R) MKL. See mkl_set_env_mode(1).
782782
"""
@@ -793,7 +793,7 @@ cdef object __set_env_mode():
793793
return status
794794

795795

796-
cdef object __get_env_mode():
796+
cdef object __get_env_mode() except *:
797797
"""
798798
Query the current environment mode. See mkl_set_env_mode(0).
799799
"""
@@ -809,14 +809,14 @@ cdef object __get_env_mode():
809809
return status
810810

811811

812-
cdef inline int __verbose(int c_enable):
812+
cdef inline int __verbose(int c_enable) noexcept:
813813
"""
814814
Enables or disables Intel(R) MKL Verbose mode.
815815
"""
816816
return mkl.mkl_verbose(c_enable)
817817

818818

819-
cdef __set_mpi(vendor, custom_library_name=None):
819+
cdef __set_mpi(vendor, custom_library_name=None) except *:
820820
"""
821821
Sets the implementation of the message-passing interface to be used by Intel(R) MKL.
822822
"""
@@ -854,7 +854,7 @@ cdef __set_mpi(vendor, custom_library_name=None):
854854

855855

856856
# VM Service Functions
857-
cdef object __vml_set_mode(accuracy, ftzdaz, errmode):
857+
cdef object __vml_set_mode(accuracy, ftzdaz, errmode) except *:
858858
"""
859859
Sets a new mode for VM functions according to the mode parameter and stores the previous VM mode to oldmode.
860860
"""
@@ -919,7 +919,7 @@ cdef object __vml_set_mode(accuracy, ftzdaz, errmode):
919919
return (accuracy, ftzdaz, errmode)
920920

921921

922-
cdef object __vml_get_mode():
922+
cdef object __vml_get_mode() except *:
923923
"""
924924
Gets the VM mode.
925925
"""
@@ -972,7 +972,7 @@ __mkl_vml_status = {
972972
}
973973

974974

975-
cdef object __vml_set_err_status(status):
975+
cdef object __vml_set_err_status(status) except *:
976976
"""
977977
Sets the new VM Error Status according to err and stores the previous VM Error Status to olderr.
978978
"""
@@ -1006,7 +1006,7 @@ cdef object __vml_set_err_status(status):
10061006
return status
10071007

10081008

1009-
cdef object __vml_get_err_status():
1009+
cdef object __vml_get_err_status() except *:
10101010
"""
10111011
Gets the VM Error Status.
10121012
"""
@@ -1030,7 +1030,7 @@ cdef object __vml_get_err_status():
10301030
return status
10311031

10321032

1033-
cdef object __vml_clear_err_status():
1033+
cdef object __vml_clear_err_status() except *:
10341034
"""
10351035
Sets the VM Error Status to VML_STATUS_OK and stores the previous VM Error Status to olderr.
10361036
"""

0 commit comments

Comments
 (0)