Skip to content

Commit 8f4f221

Browse files
committed
arch: add intel gpu basic gpu_info support
1 parent 049f17a commit 8f4f221

9 files changed

Lines changed: 106 additions & 34 deletions

File tree

devito/arch/archinfo.py

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,67 @@ def cbk(deviceid=0):
330330
except OSError:
331331
pass
332332

333+
# *** Third try: `sycl-ls`
334+
try:
335+
gpu_infos = {}
336+
337+
# sycl-ls sometimes finds gpu twice with opencl and without so
338+
# we need to make sure we don't get duplicates
339+
selected_platform = None
340+
platform_block = ""
341+
342+
proc = Popen(["sycl-ls", "--verbose"], stdout=PIPE, stderr=DEVNULL, text=True)
343+
sycl_output, _ = proc.communicate()
344+
345+
# Extract platform blocks
346+
platforms = re.findall(r"Platform \[#(\d+)\]:([\s\S]*?)(?=Platform \[#\d+\]:|$)",
347+
sycl_output)
348+
349+
# Select Level-Zero if available, otherwise use OpenCL
350+
for platform_id, platform_content in platforms:
351+
if "Intel(R) Level-Zero" in platform_content:
352+
selected_platform = platform_id
353+
platform_block = platform_content
354+
break
355+
elif "Intel(R) OpenCL Graphics" in platform_content and \
356+
selected_platform is None:
357+
selected_platform = platform_id
358+
platform_block = platform_content
359+
360+
# Extract GPU devices from the selected platform
361+
devices = re.findall(r"Device \[#(\d+)\]:([\s\S]*?)(?=Device \[#\d+\]:|$)",
362+
platform_block)
363+
364+
for device_id, device_block in devices:
365+
if re.search(r"^\s*Type\s*:\s*gpu", device_block, re.MULTILINE):
366+
name_match = re.search(r"^\s*Name\s*:\s*(.+)", device_block, re.MULTILINE)
367+
368+
if name_match:
369+
name = name_match.group(1).strip()
370+
371+
# Store GPU info with correct physical ID
372+
gpu_infos[device_id] = {
373+
"physicalid": device_id,
374+
"product": name
375+
}
376+
377+
gpu_info = homogenise_gpus(list(gpu_infos.values()))
378+
379+
# Also attach callbacks to retrieve instantaneous memory info
380+
# Now this should be done use xpu-smi but for some reason
381+
# it throws a lot of weird errors in docker so skipping for now
382+
for i in ['total', 'free', 'used']:
383+
def make_cbk(i):
384+
def cbk(deviceid=0):
385+
return None
386+
gpu_info['mem.%s' % i] = make_cbk(i)
387+
388+
gpu_infos['architecture'] = 'Intel'
389+
return gpu_info
390+
391+
except OSError:
392+
pass
393+
333394
# *** Second try: `lshw`
334395
try:
335396
info_cmd = ['lshw', '-C', 'video']
@@ -391,7 +452,8 @@ def parse_product_arch():
391452
gpu_infos = []
392453
for line in lines:
393454
# Graphics cards are listed as VGA or 3D controllers in lspci
394-
if 'VGA' in line or '3D' in line:
455+
if 'VGA' in line or '3D' in line or 'Display' in line:
456+
print(line)
395457
gpu_info = {}
396458
# Lines produced by lspci command are of the form:
397459
# xxxx:xx:xx.x Device Type: Name

devito/arch/compiler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ def __init_finalize__(self, **kwargs):
915915
elif isinstance(platform, IntelDevice):
916916
self.cflags.append('-fsycl-targets=spir64')
917917
else:
918-
raise NotImplementedError(f"Unsupported platform {platform}")
918+
warning(f"Unsupported platform {platform}")
919919

920920

921921
class CustomCompiler(Compiler):

devito/ir/cgen/printer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from devito.arch.compiler import AOMPCompiler
1818
from devito.symbolics.inspection import has_integer_args, sympy_dtype
1919
from devito.types.basic import AbstractFunction
20-
from devito.tools import ctypes_to_cstr, dtype_to_ctype
20+
from devito.tools import ctypes_to_cstr, dtype_to_ctype, ctypes_vector_mapper
2121

2222
__all__ = ['BasePrinter', 'ccode']
2323

@@ -118,6 +118,9 @@ def _print_type(self, expr):
118118
except KeyError:
119119
return ctypes_to_cstr(expr)
120120

121+
def _print_VoidDType(self, expr):
122+
return ctypes_vector_mapper[expr].__name__
123+
121124
def _print_Function(self, expr):
122125
if isinstance(expr, AbstractFunction):
123126
return str(expr)

devito/passes/iet/languages/C.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class CBB(LangBB):
2424
Call('free', (i,)),
2525
'alloc-global-symbol': lambda i, j, k:
2626
Call('memcpy', (i, j, k)),
27-
# Complex and float16
27+
# Complex
2828
'includes-complex': 'complex.h',
2929
}
3030

devito/passes/iet/languages/CXX.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,44 @@
88
__all__ = ['CXXBB']
99

1010

11-
std_arith = """
11+
def std_arith(qualifier=None):
12+
if qualifier:
13+
qual = qualifier if qualifier.endswith(" ") else f"{qualifier} "
14+
else:
15+
qual = ""
16+
return f"""
1217
#include <complex>
1318
1419
template<typename _Tp, typename _Ti>
15-
std::complex<_Tp> operator * (const _Ti & a, const std::complex<_Tp> & b){
20+
{qual}std::complex<_Tp> operator * (const _Ti & a, const std::complex<_Tp> & b){{
1621
return std::complex<_Tp>(b.real() * a, b.imag() * a);
17-
}
22+
}}
1823
1924
template<typename _Tp, typename _Ti>
20-
std::complex<_Tp> operator * (const std::complex<_Tp> & b, const _Ti & a){
25+
{qual}std::complex<_Tp> operator * (const std::complex<_Tp> & b, const _Ti & a){{
2126
return std::complex<_Tp>(b.real() * a, b.imag() * a);
22-
}
27+
}}
2328
2429
template<typename _Tp, typename _Ti>
25-
std::complex<_Tp> operator / (const _Ti & a, const std::complex<_Tp> & b){
26-
_Tp denom = b.real() * b.real () + b.imag() * b.imag()
30+
{qual}std::complex<_Tp> operator / (const _Ti & a, const std::complex<_Tp> & b){{
31+
_Tp denom = b.real() * b.real () + b.imag() * b.imag();
2732
return std::complex<_Tp>(b.real() * a / denom, - b.imag() * a / denom);
28-
}
33+
}}
2934
3035
template<typename _Tp, typename _Ti>
31-
std::complex<_Tp> operator / (const std::complex<_Tp> & b, const _Ti & a){
36+
{qual}std::complex<_Tp> operator / (const std::complex<_Tp> & b, const _Ti & a){{
3237
return std::complex<_Tp>(b.real() / a, b.imag() / a);
33-
}
38+
}}
3439
3540
template<typename _Tp, typename _Ti>
36-
std::complex<_Tp> operator + (const _Ti & a, const std::complex<_Tp> & b){
41+
{qual}std::complex<_Tp> operator + (const _Ti & a, const std::complex<_Tp> & b){{
3742
return std::complex<_Tp>(b.real() + a, b.imag());
38-
}
43+
}}
3944
4045
template<typename _Tp, typename _Ti>
41-
std::complex<_Tp> operator + (const std::complex<_Tp> & b, const _Ti & a){
46+
{qual}std::complex<_Tp> operator + (const std::complex<_Tp> & b, const _Ti & a){{
4247
return std::complex<_Tp>(b.real() + a, b.imag());
43-
}
48+
}}
4449
4550
"""
4651

@@ -60,10 +65,10 @@ class CXXBB(LangBB):
6065
Call('free', (i,)),
6166
'alloc-global-symbol': lambda i, j, k:
6267
Call('memcpy', (i, j, k)),
63-
# Complex and float16
68+
# Complex
6469
'includes-complex': 'complex',
6570
'complex-namespace': [UsingNamespace('std::complex_literals')],
66-
'def-complex': std_arith,
71+
'def-complex': std_arith(),
6772
}
6873

6974

devito/symbolics/extended_dtypes.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,11 @@ class CustomType(ReservedWord):
6161
pass
6262

6363

64-
# Dynamically create INT, INT2, .... INTP, INT2P, ... FLOAT, ...
65-
for base_name in ['int', 'float', 'double']:
66-
for i in ['', '2', '3', '4']:
67-
v = '%s%s' % (base_name, i)
68-
cls = type(v.upper(), (Cast,), {'_base_typ': v})
69-
globals()[cls.__name__] = cls
70-
71-
clsp = type('%sP' % v.upper(), (Cast,), {'base': cls})
72-
globals()[clsp.__name__] = clsp
73-
74-
7564
def cast_mapper(arg):
7665
try:
7766
assert len(arg) == 2 and arg[1] == '*'
7867
return lambda v, dtype=None, **kw: Cast(v, dtype=arg[0], stars=arg[1], **kw)
79-
except TypeError:
68+
except (AssertionError, TypeError):
8069
return lambda v, dtype=None, **kw: Cast(v, dtype=arg, **kw)
8170

8271

@@ -102,3 +91,11 @@ class VOID(BaseCast):
10291
class INT(BaseCast):
10392

10493
_dtype = np.int32
94+
95+
96+
# Dynamically create INT, INT2, .... INTP, INT2P, ... FLOAT, ...
97+
for base_name in ['int', 'float', 'double']:
98+
for i in ['2', '3', '4']:
99+
v = '%s%s' % (base_name, i)
100+
globals()[v.upper()] = cast_mapper(v)
101+
globals()[f'{v.upper()}P'] = cast_mapper((v, '*'))

devito/symbolics/manipulation.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ def _(mapper, rule):
128128

129129
@singledispatch
130130
def _uxreplace_handle(expr, args, kwargs):
131-
return expr.func(*args)
131+
try:
132+
return expr.func(*args, evaluate=False)
133+
except TypeError:
134+
return expr.func(*args)
132135

133136

134137
@_uxreplace_handle.register(Min)

devito/tools/dtypes_lowering.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ class c_restrict_void_p(ctypes.c_void_p):
236236

237237
name = "%s%d" % (base_name, count)
238238
ctype = type(name, (ctypes.Structure,),
239-
{'_fields_': [(i, base_ctype)] for i in field_names[:count]})
239+
{'_fields_': [(i, base_ctype) for i in field_names[:count]],
240+
'_base_dtype': True})
240241

241242
ctypes_vector_mapper[dtype] = ctype
242243

devito/types/object.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _sympystr(self, printer):
5454
return str(self)
5555

5656
_ccode = _sympystr
57+
_cxxcode = _sympystr
5758

5859
def _hashable_content(self):
5960
return (self.name, self.dtype)

0 commit comments

Comments
 (0)