Coverage for cuda / core / system / _nvml_context.pxd: 57.14%

7 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-29 01:27 +0000

1# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 

2# 

3# SPDX-License-Identifier: Apache-2.0 

4  

5  

6cdef extern from *: 

7 """ 

8 #if defined(_WIN32) || defined(_WIN64) 

9 #include <process.h> 

10 #else 

11 #include <unistd.h> 

12 #endif 

13 """ 

14 int getpid() nogil 

15  

16  

17ctypedef enum _NVMLState: 

18 UNINITIALIZED = 0 

19 INITIALIZED = 1 

20 DISABLED_LIBRARY_NOT_FOUND = 2 

21  

22  

23# Initialisation must occur per-process, so an initialised state is a 

24# (state, pid) pair 

25cdef _NVMLState _NVML_STATE 

26  

27  

28cdef int _NVML_OWNER_PID 

29  

30  

31cpdef _initialize() 

32  

33  

34cpdef inline initialize(): 

35 """ 

36 Initializes Nvidia Management Library (NVML), ensuring it only happens once per process. 

37 """ 

38 if _NVML_STATE == _NVMLState.DISABLED_LIBRARY_NOT_FOUND or ( 2a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdb

39 _NVML_STATE == _NVMLState.INITIALIZED and getpid() == _NVML_OWNER_PID 2a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } ~ abbbcbdb

40 ): 

41 return 2a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ' ( ) * + , - . / : ; = ? @ [ ] ^ _ ` { | } abbbcbdb

42  

43 _initialize() 1~

44  

45  

46cpdef inline bint is_initialized(): 

47 """ 

48 Check whether the NVML context is initialized on this process. 

49  

50 Returns 

51 ------- 

52 result: bool 

53 Whether the NVML context is initialized on this process. 

54 """ 

55 return _NVML_STATE == _NVMLState.INITIALIZED and getpid() == _NVML_OWNER_PID 

56  

57  

58cpdef validate()