Skip to content

Commit 88c5ed2

Browse files
committed
handle culink and nvjitlink differences in the backend and test
1 parent 702fbaa commit 88c5ed2

File tree

15 files changed

+1327
-1327
lines changed

15 files changed

+1327
-1327
lines changed

cuda_core/cuda/core/experimental/_linker.py

Lines changed: 444 additions & 444 deletions
Large diffs are not rendered by default.
-1 Bytes
Loading
-1 Bytes
Loading
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# `cuda.core` Release notes
2-
3-
Released on Nov <TODO>, 2024
4-
5-
## Hightlights
6-
- Addition of the Linker class which gives object oriented and pythonic access to the nvJitLink API.
7-
8-
## Limitations
9-
10-
-The Linker class only supports cuda >=12. For cuda <12, use low level cuLink API.
1+
# `cuda.core` Release notes
2+
3+
Released on Nov <TODO>, 2024
4+
5+
## Hightlights
6+
- Addition of the Linker class which gives object oriented and pythonic access to the nvJitLink API.
7+
8+
## Limitations
9+
10+
-The Linker class only supports cuda >=12. For cuda <12, use low level cuLink API.

cuda_core/tests/conftest.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
1-
# Copyright 2024 NVIDIA Corporation. All rights reserved.
2-
#
3-
# Please refer to the NVIDIA end user license agreement (EULA) associated
4-
# with this source code for terms and conditions that govern your use of
5-
# this software. Any use, reproduction, disclosure, or distribution of
6-
# this software and related documentation outside the terms of the EULA
7-
# is strictly prohibited.
8-
try:
9-
from cuda.bindings import driver
10-
except ImportError:
11-
from cuda import cuda as driver
12-
13-
import pytest
14-
15-
from cuda.core.experimental import Device, _device
16-
from cuda.core.experimental._utils import handle_return
17-
18-
19-
@pytest.fixture(scope="function")
20-
def init_cuda():
21-
device = Device()
22-
device.set_current()
23-
yield
24-
_device_unset_current()
25-
26-
27-
def _device_unset_current():
28-
handle_return(driver.cuCtxPopCurrent())
29-
with _device._tls_lock:
30-
del _device._tls.devices
31-
32-
33-
@pytest.fixture(scope="function")
34-
def deinit_cuda():
35-
yield
36-
_device_unset_current()
1+
# Copyright 2024 NVIDIA Corporation. All rights reserved.
2+
#
3+
# Please refer to the NVIDIA end user license agreement (EULA) associated
4+
# with this source code for terms and conditions that govern your use of
5+
# this software. Any use, reproduction, disclosure, or distribution of
6+
# this software and related documentation outside the terms of the EULA
7+
# is strictly prohibited.
8+
try:
9+
from cuda.bindings import driver
10+
except ImportError:
11+
from cuda import cuda as driver
12+
13+
import pytest
14+
15+
from cuda.core.experimental import Device, _device
16+
from cuda.core.experimental._utils import handle_return
17+
18+
19+
@pytest.fixture(scope="function")
20+
def init_cuda():
21+
device = Device()
22+
device.set_current()
23+
yield
24+
_device_unset_current()
25+
26+
27+
def _device_unset_current():
28+
handle_return(driver.cuCtxPopCurrent())
29+
with _device._tls_lock:
30+
del _device._tls.devices
31+
32+
33+
@pytest.fixture(scope="function")
34+
def deinit_cuda():
35+
yield
36+
_device_unset_current()
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
# Copyright 2024 NVIDIA Corporation. All rights reserved.
2-
#
3-
# Please refer to the NVIDIA end user license agreement (EULA) associated
4-
# with this source code for terms and conditions that govern your use of
5-
# this software. Any use, reproduction, disclosure, or distribution of
6-
# this software and related documentation outside the terms of the EULA
7-
# is strictly prohibited.
8-
9-
# If we have subcategories of examples in the future, this file can be split along those lines
10-
11-
import glob
12-
import os
13-
14-
import pytest
15-
16-
from .utils import run_example
17-
18-
samples_path = os.path.join(os.path.dirname(__file__), "..", "..", "examples")
19-
sample_files = glob.glob(samples_path + "**/*.py", recursive=True)
20-
21-
22-
@pytest.mark.parametrize("example", sample_files)
23-
class TestExamples:
24-
def test_example(self, example, deinit_cuda):
25-
run_example(samples_path, example)
1+
# Copyright 2024 NVIDIA Corporation. All rights reserved.
2+
#
3+
# Please refer to the NVIDIA end user license agreement (EULA) associated
4+
# with this source code for terms and conditions that govern your use of
5+
# this software. Any use, reproduction, disclosure, or distribution of
6+
# this software and related documentation outside the terms of the EULA
7+
# is strictly prohibited.
8+
9+
# If we have subcategories of examples in the future, this file can be split along those lines
10+
11+
import glob
12+
import os
13+
14+
import pytest
15+
16+
from .utils import run_example
17+
18+
samples_path = os.path.join(os.path.dirname(__file__), "..", "..", "examples")
19+
sample_files = glob.glob(samples_path + "**/*.py", recursive=True)
20+
21+
22+
@pytest.mark.parametrize("example", sample_files)
23+
class TestExamples:
24+
def test_example(self, example, deinit_cuda):
25+
run_example(samples_path, example)
Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
1-
# Copyright 2024 NVIDIA Corporation. All rights reserved.
2-
#
3-
# Please refer to the NVIDIA end user license agreement (EULA) associated
4-
# with this source code for terms and conditions that govern your use of
5-
# this software. Any use, reproduction, disclosure, or distribution of
6-
# this software and related documentation outside the terms of the EULA
7-
# is strictly prohibited.
8-
9-
import gc
10-
import os
11-
import sys
12-
13-
import cupy as cp
14-
import pytest
15-
16-
17-
class SampleTestError(Exception):
18-
pass
19-
20-
21-
def parse_python_script(filepath):
22-
if not filepath.endswith(".py"):
23-
raise ValueError(f"{filepath} not supported")
24-
with open(filepath, encoding="utf-8") as f:
25-
script = f.read()
26-
return script
27-
28-
29-
def run_example(samples_path, filename, env=None):
30-
fullpath = os.path.join(samples_path, filename)
31-
script = parse_python_script(fullpath)
32-
try:
33-
old_argv = sys.argv
34-
sys.argv = [fullpath]
35-
old_sys_path = sys.path.copy()
36-
sys.path.append(samples_path)
37-
exec(script, env if env else {})
38-
except ImportError as e:
39-
# for samples requiring any of optional dependencies
40-
for m in ("cupy",):
41-
if f"No module named '{m}'" in str(e):
42-
pytest.skip(f"{m} not installed, skipping related tests")
43-
break
44-
else:
45-
raise
46-
except Exception as e:
47-
msg = "\n"
48-
msg += f"Got error ({filename}):\n"
49-
msg += str(e)
50-
raise SampleTestError(msg) from e
51-
finally:
52-
sys.path = old_sys_path
53-
sys.argv = old_argv
54-
# further reduce the memory watermark
55-
gc.collect()
56-
cp.get_default_memory_pool().free_all_blocks()
1+
# Copyright 2024 NVIDIA Corporation. All rights reserved.
2+
#
3+
# Please refer to the NVIDIA end user license agreement (EULA) associated
4+
# with this source code for terms and conditions that govern your use of
5+
# this software. Any use, reproduction, disclosure, or distribution of
6+
# this software and related documentation outside the terms of the EULA
7+
# is strictly prohibited.
8+
9+
import gc
10+
import os
11+
import sys
12+
13+
import cupy as cp
14+
import pytest
15+
16+
17+
class SampleTestError(Exception):
18+
pass
19+
20+
21+
def parse_python_script(filepath):
22+
if not filepath.endswith(".py"):
23+
raise ValueError(f"{filepath} not supported")
24+
with open(filepath, encoding="utf-8") as f:
25+
script = f.read()
26+
return script
27+
28+
29+
def run_example(samples_path, filename, env=None):
30+
fullpath = os.path.join(samples_path, filename)
31+
script = parse_python_script(fullpath)
32+
try:
33+
old_argv = sys.argv
34+
sys.argv = [fullpath]
35+
old_sys_path = sys.path.copy()
36+
sys.path.append(samples_path)
37+
exec(script, env if env else {})
38+
except ImportError as e:
39+
# for samples requiring any of optional dependencies
40+
for m in ("cupy",):
41+
if f"No module named '{m}'" in str(e):
42+
pytest.skip(f"{m} not installed, skipping related tests")
43+
break
44+
else:
45+
raise
46+
except Exception as e:
47+
msg = "\n"
48+
msg += f"Got error ({filename}):\n"
49+
msg += str(e)
50+
raise SampleTestError(msg) from e
51+
finally:
52+
sys.path = old_sys_path
53+
sys.argv = old_argv
54+
# further reduce the memory watermark
55+
gc.collect()
56+
cp.get_default_memory_pool().free_all_blocks()

0 commit comments

Comments
 (0)