Skip to content

Commit

Permalink
Adapt to Brian's logging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mstimberg committed Mar 22, 2024
1 parent aebdb8a commit 06e181c
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion brian2cuda/cuda_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
__all__ = ['CUDACodeGenerator', 'CUDAAtomicsCodeGenerator', 'c_data_type']


logger = get_logger('brian2.codegen.generators.cuda_generator')
logger = get_logger(__name__)


class ParallelisationError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion brian2cuda/cuda_prefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from brian2.utils.logger import get_logger


logger = get_logger('brian2.devices.cuda_standalone.cuda_prefs')
logger = get_logger(__name__)

def validate_bundle_size_expression(string):
known_vars = ['mean', 'std', 'max', 'min']
Expand Down
2 changes: 1 addition & 1 deletion brian2cuda/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

__all__ = []

logger = get_logger('brian2.devices.cuda_standalone')
logger = get_logger(__name__)


class CUDAWriter(CPPWriter):
Expand Down
2 changes: 1 addition & 1 deletion brian2cuda/tests/features/cuda_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
except ImportError:
pass

logger = get_logger('brian2.devices.cuda_standalone.cuda_configuration')
logger = get_logger(__name__)

__all__ = ['CUDAStandaloneConfiguration']

Expand Down
21 changes: 13 additions & 8 deletions brian2cuda/tests/test_cuda_generator.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import functools

import pytest
import numpy as np
import logging

from brian2 import *
from brian2.tests.utils import assert_allclose
from brian2.utils.logger import catch_logs
from brian2.utils.logger import catch_logs as _catch_logs
from brian2.devices.device import set_device
from brian2.tests.test_synapses import permutation_analysis_good_examples
from brian2.utils.stringtools import get_identifiers, deindent

import brian2cuda
from brian2cuda.cuda_generator import CUDACodeGenerator

# Only catch our own log messages
catch_logs = functools.partial(_catch_logs, only_from=["brian2cuda"])


@pytest.mark.parametrize(
'func,zero_point,offset',
Expand Down Expand Up @@ -198,24 +203,24 @@ def test_default_function_convertion_warnings():

assert len(logs1) == 1, len(logs1)
assert logs1[0][0] == 'WARNING'
assert logs1[0][1] == 'brian2.codegen.generators.cuda_generator'
assert logs1[0][1] == 'brian2cuda.cuda_generator'
assert len(logs2) == 1, len(logs2)
assert logs2[0][0] == 'WARNING'
assert logs2[0][1] == 'brian2.codegen.generators.cuda_generator'
assert logs2[0][1] == 'brian2cuda.cuda_generator'
assert len(logs3) == 0, len(logs3)
assert len(logs4) == 0, len(logs4)
assert len(logs5) == 1, len(logs5)
assert logs5[0][0] == 'WARNING'
assert logs5[0][1] == 'brian2.codegen.generators.cuda_generator'
assert logs5[0][1] == 'brian2cuda.cuda_generator'
assert len(logs6) == 1, len(logs6)
assert logs6[0][0] == 'WARNING'
assert logs6[0][1] == 'brian2.codegen.generators.cuda_generator'
assert logs6[0][1] == 'brian2cuda.cuda_generator'
assert len(logs7) == 1, len(logs7)
assert logs7[0][0] == 'WARNING'
assert logs7[0][1] == 'brian2.codegen.generators.cuda_generator'
assert logs7[0][1] == 'brian2cuda.cuda_generator'
assert len(logs8) == 1, len(logs8)
assert logs8[0][0] == 'WARNING'
assert logs8[0][1] == 'brian2.codegen.generators.cuda_generator'
assert logs8[0][1] == 'brian2cuda.cuda_generator'



Expand Down Expand Up @@ -292,7 +297,7 @@ def test_atomics_parallelisation(code):
device.reinit()
device.activate()
cuda_generator_messages = [l for l in caught_logs
if l[1]=='brian2.codegen.generators.cuda_generator']
if l[1]=='brian2cuda.cuda_generator']
if should_be_able_to_use_ufunc_at:
assert len(cuda_generator_messages) == 0, cuda_generator_messages
else:
Expand Down
10 changes: 7 additions & 3 deletions brian2cuda/tests/test_gpu_detection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import os
import logging
from io import StringIO
Expand All @@ -6,7 +7,7 @@
from numpy.testing import assert_equal

from brian2 import prefs, ms, run, set_device, device
from brian2.utils.logger import catch_logs
from brian2.utils.logger import catch_logs as _catch_logs
from brian2.core.preferences import PreferenceError
from brian2cuda.utils.gputools import (
reset_cuda_installation,
Expand All @@ -17,6 +18,9 @@
restore_gpu_selection,
)

# Only catch our own log messages
catch_logs = functools.partial(_catch_logs, only_from=["brian2cuda"])


### Pytest fixtures ###
# Detecting the CUDA installation and GPU to use is happening only once and sets global
Expand Down Expand Up @@ -108,7 +112,7 @@ def test_wrong_cuda_path_warning(reset_cuda_detection, use_default_prefs, monkey
assert len(logs) == 1, logs
log = logs[0]
assert log[0] == "WARNING"
assert log[1] == "brian2.devices.cuda_standalone"
assert log[1] == "brian2cuda.utils.gputools"
assert log[2].startswith("Couldn't find `nvcc` binary ")


Expand Down Expand Up @@ -149,7 +153,7 @@ def test_warning_compute_capability_set_twice(reset_gpu_detection, use_default_p
assert len(logs) == 1, logs
log = logs[0]
assert log[0] == "WARNING"
assert log[1] == "brian2.devices.cuda_standalone"
assert log[1] == "brian2cuda.device"
assert log[2].startswith("GPU architecture for compilation was specified via ")


Expand Down
3 changes: 1 addition & 2 deletions brian2cuda/tests/test_neurongroup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import numpy as np
import pytest
from numpy.testing import assert_equal
Expand All @@ -7,13 +6,13 @@
from brian2.core.magic import run
from brian2.groups.neurongroup import NeuronGroup
from brian2.synapses import Synapses
from brian2.tests import make_argv
from brian2.tests.utils import assert_allclose
from brian2.utils.logger import catch_logs
from brian2.units import second

# Adapted from brian2/tests/test_neurongroup.py::test_semantics_floor_division
# (brian2 test asserts for 0 warnings, brian2cuda warns for int to float64 conversion)
# Can be removed with the next version that includes brian-team/brian2#1519
@pytest.mark.standalone_compatible
def test_semantics_floor_division():
# See Brian2 github issues #815 and #661
Expand Down
2 changes: 1 addition & 1 deletion brian2cuda/utils/gputools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from brian2.utils.logger import get_logger
from brian2cuda.utils.logger import report_issue_message

logger = get_logger("brian2.devices.cuda_standalone")
logger = get_logger(__name__)

# To list all GPUs: nvidia-smi -L

Expand Down

0 comments on commit 06e181c

Please sign in to comment.