def _setup_cuda_marker(item): """Pytest marker to indicate number of NVIDIA GPUs required to run the test. Tests can be annotated with this decorator (e.g., ``@pytest.mark.cuda``) to declare that one NVIDIA GPU is required to run. Tests can also be annotated as ``@pytest.mark.cuda(2)`` to declare number of NVIDIA GPUs required to run. When running tests, if ``CHAINERX_TEST_CUDA_DEVICE_LIMIT`` environment variable is set to value greater than or equals to 0, test cases that require GPUs more than the limit will be skipped. """ cuda_marker = [m for m in item.iter_markers() if m.name == 'cuda'] if cuda_marker: cuda_marker, = cuda_marker # asserts len == 1 required_num = cuda_marker.args[0] if cuda_marker.args else 1 if cuda_utils.get_cuda_limit() < required_num: pytest.skip('{} NVIDIA GPUs required'.format(required_num))
def _setup_cuda_marker(item): """Pytest marker to indicate number of NVIDIA GPUs required to run the test. Tests can be annotated with this decorator (e.g., ``@pytest.mark.cuda``) to declare that one NVIDIA GPU is required to run. Tests can also be annotated as ``@pytest.mark.cuda(2)`` to declare number of NVIDIA GPUs required to run. When running tests, if ``CHAINERX_TEST_CUDA_DEVICE_LIMIT`` environment variable is set to value greater than or equals to 0, test cases that require GPUs more than the limit will be skipped. """ cuda_marker = [m for m in item.iter_markers() if m.name == 'cuda'] if len(cuda_marker) > 0: cuda_marker, = cuda_marker # asserts len == 1 required_num = cuda_marker.args[0] if cuda_marker.args else 1 if cuda_utils.get_cuda_limit() < required_num: pytest.skip('{} NVIDIA GPUs required'.format(required_num))
def device(request): # A fixture to wrap a test with a device scope, given a device name. # Device instance is passed to the test. device_name = request.param # Skip if the device is CUDA device and there's no sufficient CUDA devices. cuda_device_count = _get_required_cuda_devices_from_device_name( device_name) if cuda_device_count > cuda_utils.get_cuda_limit(): pytest.skip() device = chainerx.get_device(device_name) device_scope = chainerx.using_device(device) def finalize(): device_scope.__exit__() request.addfinalizer(finalize) device_scope.__enter__() return device
def device(request): # A fixture to wrap a test with a device scope, given a device name. # Device instance is passed to the test. device_name = request.param # Skip if the device is CUDA device and there's no sufficient CUDA devices. cuda_device_count = _get_required_cuda_devices_from_device_name( device_name) if cuda_device_count > cuda_utils.get_cuda_limit(): pytest.skip() device = chainerx.get_device(device_name) device_scope = chainerx.using_device(device) def finalize(): device_scope.__exit__() request.addfinalizer(finalize) device_scope.__enter__() return device
def pytest_ignore_collect(path, config): if 0 == cuda_utils.get_cuda_limit(): if str(path).endswith('_cuda.rst'): return True return False
def _skip_if_no_cuda_device_available(device_name): # Skip if the device is CUDA device and there's no sufficient CUDA devices. cuda_device_count = _get_required_cuda_devices_from_device_name( device_name) if cuda_device_count > cuda_utils.get_cuda_limit(): pytest.skip()