Coverage for cuda / core / experimental / _context.pyx: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-10 01:19 +0000

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

2# 

3# SPDX-License-Identifier: Apache-2.0 

4  

5from dataclasses import dataclass 

6  

7from cuda.core.experimental._utils.cuda_utils import driver 

8  

9  

10@dataclass 

11class ContextOptions: 

12 pass # TODO 

13  

14  

15cdef class Context: 

16  

17 cdef: 

18 readonly object _handle 

19 int _device_id 

20  

21 def __init__(self, *args, **kwargs): 

22 raise RuntimeError("Context objects cannot be instantiated directly. Please use Device or Stream APIs.") 

23  

24 @classmethod 

25 def _from_ctx(cls, handle: driver.CUcontext, int device_id): 

26 cdef Context ctx = Context.__new__(Context) 

27 ctx._handle = handle 

28 ctx._device_id = device_id 

29 return ctx 

30  

31 def __eq__(self, other): 

32 if not isinstance(other, Context): 

33 return NotImplemented 

34 cdef Context _other = <Context>other 

35 return int(self._handle) == int(_other._handle) 

36  

37 def __hash__(self) -> int: 

38 return hash(int(self._handle))