From 4f6cc56d4654700953cf17a55686520169d72cdb Mon Sep 17 00:00:00 2001 From: mloubout Date: Fri, 11 Oct 2024 16:36:26 -0400 Subject: [PATCH] arch: make sure Device get thread config from host --- .github/workflows/examples.yml | 1 + devito/arch/archinfo.py | 16 +++++++++------- tests/test_gpu_common.py | 11 ++++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index f9a86a5232..4df8a929b6 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -42,6 +42,7 @@ jobs: activate-environment: devito environment-file: environment-dev.yml auto-activate-base: false + python-version: 3.11 - name: Install dependencies run: | diff --git a/devito/arch/archinfo.py b/devito/arch/archinfo.py index 1fcf864614..ca3c52dd63 100644 --- a/devito/arch/archinfo.py +++ b/devito/arch/archinfo.py @@ -648,6 +648,10 @@ def numa_domains(self): def threads_per_core(self): return self.cores_logical // self.cores_physical + @property + def cores_physical_per_numa_domain(self): + return self.cores_physical // self.numa_domains + @property def memtotal(self): """Physical memory size in bytes, or None if unknown.""" @@ -734,10 +738,6 @@ def numa_domains(self): warning("NUMA domain count autodetection failed") return 1 - @property - def cores_physical_per_numa_domain(self): - return self.cores_physical // self.numa_domains - @cached_property def memtotal(self): return psutil.virtual_memory().total @@ -804,13 +804,15 @@ def _detect_isa(self): class Device(Platform): - def __init__(self, name, cores_logical=1, cores_physical=1, isa='cpp', + def __init__(self, name, cores_logical=None, cores_physical=None, isa='cpp', max_threads_per_block=1024, max_threads_dimx=1024, max_threads_dimy=1024, max_threads_dimz=64): super().__init__(name) - self.cores_logical = cores_logical - self.cores_physical = cores_physical + cpu_info = get_cpu_info() + + self.cores_logical = cores_logical or cpu_info['logical'] + self.cores_physical = cores_physical or cpu_info['physical'] self.isa = isa self.max_threads_per_block = max_threads_per_block diff --git a/tests/test_gpu_common.py b/tests/test_gpu_common.py index 70879b4ce7..1be9ec3fbe 100644 --- a/tests/test_gpu_common.py +++ b/tests/test_gpu_common.py @@ -10,7 +10,7 @@ SubDimension, SubDomain, SubDomainSet, TimeFunction, Operator, configuration, switchconfig, TensorTimeFunction, Buffer) -from devito.arch import get_gpu_info +from devito.arch import get_gpu_info, get_cpu_info, Device, Cpu64 from devito.exceptions import InvalidArgument from devito.ir import (Conditional, Expression, Section, FindNodes, FindSymbols, retrieve_iteration_tree) @@ -47,6 +47,15 @@ def custom_compiler(self): op.apply(time_M=10) assert np.all(u.data[1] == 11) + def test_host_threads(self): + plat = configuration['platform'] + + assert isinstance(plat, Device) + + nth = plat.cores_physical + assert nth == get_cpu_info()['physical'] + assert nth == Cpu64("test").cores_physical + class TestCodeGeneration: