Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from numba.cuda.cudadrv import driver, devices, libs
from numba.cuda.dispatcher import CUDADispatcher
from numba.core import config
from numba.tests.support import TestCase
from numba.cuda.tests.support import TestCase
from pathlib import Path
from typing import Union
from io import StringIO
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudadrv/test_cuda_ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from numba import cuda
from numba.cuda.testing import unittest, CUDATestCase
from numba.cuda.testing import skip_on_cudasim
from numba.tests.support import IS_NUMPY_2
from numba.cuda.tests.support import IS_NUMPY_2


class TestCudaNDArray(CUDATestCase):
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudadrv/test_deallocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
skip_if_external_memmgr,
CUDATestCase,
)
from numba.tests.support import captured_stderr
from numba.cuda.tests.support import captured_stderr
from numba.core import config


Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudadrv/test_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
skip_on_cudasim,
skip_under_cuda_memcheck,
)
from numba.tests.support import captured_stdout
from numba.cuda.tests.support import captured_stdout


class TestCudaDetect(CUDATestCase):
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudadrv/test_emm_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from numba import cuda
from numba.core import config
from numba.cuda.testing import unittest, CUDATestCase, skip_on_cudasim
from numba.tests.support import linux_only
from numba.cuda.tests.support import linux_only

if not config.ENABLE_CUDASIM:

Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudadrv/test_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from numba.cuda.testing import CUDATestCase, test_data_dir
from numba.cuda.cudadrv.driver import CudaAPIError, _Linker, LinkerError
from numba.cuda import require_context
from numba.tests.support import ignore_internal_warnings
from numba.cuda.tests.support import ignore_internal_warnings
from numba import cuda, void, float64, int64, int32, typeof, float32
from numba.cuda.cudadrv.error import NvrtcError

Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudadrv/test_managed_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from numba import cuda
from numba.cuda.testing import unittest, ContextResettingTestCase
from numba.cuda.testing import skip_on_cudasim, skip_on_arm
from numba.tests.support import linux_only
from numba.cuda.tests.support import linux_only


@skip_on_cudasim("CUDA Driver API unsupported in the simulator")
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudadrv/test_mvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
skip_under_cuda_memcheck,
skip_if_mvc_libraries_unavailable,
)
from numba.tests.support import linux_only
from numba.cuda.tests.support import linux_only


def child_test():
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudadrv/test_ptds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
skip_with_cuda_python,
skip_under_cuda_memcheck,
)
from numba.tests.support import linux_only
from numba.cuda.tests.support import linux_only


def child_test():
Expand Down
149 changes: 146 additions & 3 deletions numba_cuda/numba/cuda/tests/cudapy/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import shutil
import unittest
import warnings
import sys
import stat
import subprocess

from numba import cuda
from numba.core.errors import NumbaWarning
Expand All @@ -14,12 +17,152 @@
skip_if_mvc_enabled,
test_data_dir,
)
from numba.tests.test_caching import (
DispatcherCacheUsecasesTest,
skip_bad_access,
from numba.cuda.tests.support import (
TestCase,
temp_directory,
import_dynamic,
)


class BaseCacheTest(TestCase):
# The source file that will be copied
usecases_file = None
# Make sure this doesn't conflict with another module
modname = None

def setUp(self):
self.tempdir = temp_directory("test_cache")
sys.path.insert(0, self.tempdir)
self.modfile = os.path.join(self.tempdir, self.modname + ".py")
self.cache_dir = os.path.join(self.tempdir, "__pycache__")
shutil.copy(self.usecases_file, self.modfile)
os.chmod(self.modfile, stat.S_IREAD | stat.S_IWRITE)
self.maxDiff = None

def tearDown(self):
sys.modules.pop(self.modname, None)
sys.path.remove(self.tempdir)

def import_module(self):
# Import a fresh version of the test module. All jitted functions
# in the test module will start anew and load overloads from
# the on-disk cache if possible.
old = sys.modules.pop(self.modname, None)
if old is not None:
# Make sure cached bytecode is removed
cached = [old.__cached__]
for fn in cached:
try:
os.unlink(fn)
except FileNotFoundError:
pass
mod = import_dynamic(self.modname)
self.assertEqual(mod.__file__.rstrip("co"), self.modfile)
return mod

def cache_contents(self):
try:
return [
fn
for fn in os.listdir(self.cache_dir)
if not fn.endswith((".pyc", ".pyo"))
]
except FileNotFoundError:
return []

def get_cache_mtimes(self):
return dict(
(fn, os.path.getmtime(os.path.join(self.cache_dir, fn)))
for fn in sorted(self.cache_contents())
)

def check_pycache(self, n):
c = self.cache_contents()
self.assertEqual(len(c), n, c)

def dummy_test(self):
pass


class DispatcherCacheUsecasesTest(BaseCacheTest):
here = os.path.dirname(__file__)
usecases_file = os.path.join(here, "cache_usecases.py")
modname = "dispatcher_caching_test_fodder"

def run_in_separate_process(self, *, envvars={}):
# Cached functions can be run from a distinct process.
# Also stresses issue #1603: uncached function calling cached function
# shouldn't fail compiling.
code = """if 1:
import sys

sys.path.insert(0, %(tempdir)r)
mod = __import__(%(modname)r)
mod.self_test()
""" % dict(tempdir=self.tempdir, modname=self.modname)

subp_env = os.environ.copy()
subp_env.update(envvars)
popen = subprocess.Popen(
[sys.executable, "-c", code],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=subp_env,
)
out, err = popen.communicate()
if popen.returncode != 0:
raise AssertionError(
"process failed with code %s: \n"
"stdout follows\n%s\n"
"stderr follows\n%s\n"
% (popen.returncode, out.decode(), err.decode()),
)

def check_hits(self, func, hits, misses=None):
st = func.stats
self.assertEqual(sum(st.cache_hits.values()), hits, st.cache_hits)
if misses is not None:
self.assertEqual(
sum(st.cache_misses.values()), misses, st.cache_misses
)


def check_access_is_preventable():
# This exists to check whether it is possible to prevent access to
# a file/directory through the use of `chmod 500`. If a user has
# elevated rights (e.g. root) then writes are likely to be possible
# anyway. Tests that require functioning access prevention are
# therefore skipped based on the result of this check.
tempdir = temp_directory("test_cache")
test_dir = os.path.join(tempdir, "writable_test")
os.mkdir(test_dir)
# check a write is possible
with open(os.path.join(test_dir, "write_ok"), "wt") as f:
f.write("check1")
# now forbid access
os.chmod(test_dir, 0o500)
try:
with open(os.path.join(test_dir, "write_forbidden"), "wt") as f:
f.write("check2")
# access prevention is not possible
return False
except PermissionError:
# Check that the cause of the exception is due to access/permission
# as per
# https://github.com/conda/conda/blob/4.5.0/conda/gateways/disk/permissions.py#L35-L37 # noqa: E501
# errno reports access/perm fail so access prevention via
# `chmod 500` works for this user.
return True
finally:
os.chmod(test_dir, 0o775)
shutil.rmtree(test_dir)


_access_preventable = check_access_is_preventable()
_access_msg = "Cannot create a directory to which writes are preventable"
skip_bad_access = unittest.skipUnless(_access_preventable, _access_msg)


@skip_on_cudasim("Simulator does not implement caching")
class CUDACachingTest(DispatcherCacheUsecasesTest):
here = os.path.dirname(__file__)
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_cffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
unittest,
CUDATestCase,
)
from numba.tests.support import skip_unless_cffi
from numba.cuda.tests.support import skip_unless_cffi


@skip_unless_cffi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from numba import cuda
from numba.cuda.testing import unittest, ContextResettingTestCase, ForeignArray
from numba.cuda.testing import skip_on_cudasim, skip_if_external_memmgr
from numba.tests.support import linux_only, override_config
from numba.cuda.tests.support import linux_only, override_config
from unittest.mock import call, patch


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from numba import cuda
import numpy as np
from numba.cuda.testing import CUDATestCase
from numba.tests.support import override_config
from numba.cuda.tests.support import override_config
import unittest


Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from numba.core.utils import PYVERSION
from numba.cuda.testing import skip_on_cudasim, CUDATestCase
from numba.tests.support import (
from numba.cuda.tests.support import (
override_config,
captured_stderr,
captured_stdout,
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from numba.tests.support import override_config, captured_stdout
from numba.cuda.tests.support import override_config, captured_stdout
from numba.cuda.testing import skip_on_cudasim
from numba import cuda
from numba.core import types
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_device_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)
from numba import cuda, jit, float32, int32, types
from numba.core.errors import TypingError
from numba.tests.support import skip_unless_cffi
from numba.cuda.tests.support import skip_unless_cffi
from types import ModuleType


Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_gufunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import unittest
import warnings
from numba.core.errors import NumbaPerformanceWarning, TypingError
from numba.tests.support import override_config
from numba.cuda.tests.support import override_config


def _get_matmulcore_gufunc(dtype=float32):
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ContextResettingTestCase,
ForeignArray,
)
from numba.tests.support import linux_only, windows_only
from numba.cuda.tests.support import linux_only, windows_only
import unittest


Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_lineinfo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from numba import cuda, float32, int32
from numba.core.errors import NumbaInvalidConfigWarning
from numba.cuda.testing import CUDATestCase, skip_on_cudasim
from numba.tests.support import ignore_internal_warnings
from numba.cuda.tests.support import ignore_internal_warnings
import re
import unittest
import warnings
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest

from numba import config, cuda, types
from numba.tests.support import TestCase
from numba.cuda.tests.support import TestCase
from numba.tests.test_ufuncs import BasicUFuncTest


Expand Down
6 changes: 5 additions & 1 deletion numba_cuda/numba/cuda/tests/cudapy/test_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
CUDATestCase,
skip_on_cudasim,
)
from numba.tests.support import linux_only, override_config, run_in_subprocess
from numba.cuda.tests.support import (
linux_only,
override_config,
run_in_subprocess,
)
from numba.core.errors import NumbaPerformanceWarning
from numba.core import config
import warnings
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/doc_examples/test_cpointer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from numba.cuda.testing import CUDATestCase, skip_on_cudasim
from numba.tests.support import captured_stdout
from numba.cuda.tests.support import captured_stdout


@skip_on_cudasim("cudasim doesn't support cuda import at non-top-level")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from numba.cuda.testing import CUDATestCase, skip_on_cudasim
from numba.tests.support import captured_stdout
from numba.cuda.tests.support import captured_stdout
import numpy as np


Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/doc_examples/test_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import unittest
from numba.cuda.testing import CUDATestCase, skip_on_cudasim
from numba.tests.support import skip_unless_cffi, override_config
from numba.cuda.tests.support import skip_unless_cffi, override_config


@skip_unless_cffi
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/doc_examples/test_laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
skip_unless_cc_60,
skip_if_mvc_enabled,
)
from numba.tests.support import captured_stdout
from numba.cuda.tests.support import captured_stdout


@skip_if_cudadevrt_missing
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/tests/doc_examples/test_matmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import unittest
from numba.cuda.testing import CUDATestCase, skip_on_cudasim
from numba.tests.support import captured_stdout
from numba.cuda.tests.support import captured_stdout


@skip_on_cudasim("cudasim doesn't support cuda import at non-top-level")
Expand Down
Loading