@@ -180,12 +180,21 @@ def __init__(self):
180
180
"""
181
181
182
182
fields = {'cc' , 'ld' }
183
- _cpp = False
183
+ _default_cpp = False
184
+ _cxxstd = 'c++14'
185
+ _cstd = 'c99'
184
186
185
187
def __init__ (self , ** kwargs ):
188
+ maybe_name = kwargs .pop ('name' , self .__class__ .__name__ )
189
+ if isinstance (maybe_name , Compiler ):
190
+ self ._name = maybe_name .name
191
+ else :
192
+ self ._name = maybe_name
193
+
186
194
super ().__init__ (** kwargs )
187
195
188
196
self .__lookup_cmds__ ()
197
+ self ._cpp = kwargs .get ('cpp' , self ._default_cpp )
189
198
190
199
self .suffix = kwargs .get ('suffix' )
191
200
if not kwargs .get ('mpi' ):
@@ -195,7 +204,7 @@ def __init__(self, **kwargs):
195
204
self .cc = self .MPICC if self ._cpp is False else self .MPICXX
196
205
self .ld = self .cc # Wanted by the superclass
197
206
198
- self .cflags = ['-O3' , '-g' , '-fPIC' , '-Wall' , '-std=c99 ' ]
207
+ self .cflags = ['-O3' , '-g' , '-fPIC' , '-Wall' , f '-std={ self . std } ' ]
199
208
self .ldflags = ['-shared' ]
200
209
201
210
self .include_dirs = []
@@ -225,13 +234,13 @@ def __new_with__(self, **kwargs):
225
234
Create a new Compiler from an existing one, inherenting from it
226
235
the flags that are not specified via ``kwargs``.
227
236
"""
228
- return self .__class__ (suffix = kwargs .pop ('suffix' , self .suffix ),
237
+ return self .__class__ (name = self . name , suffix = kwargs .pop ('suffix' , self .suffix ),
229
238
mpi = kwargs .pop ('mpi' , configuration ['mpi' ]),
230
239
** kwargs )
231
240
232
241
@property
233
242
def name (self ):
234
- return self .__class__ . __name__
243
+ return self ._name
235
244
236
245
@property
237
246
def version (self ):
@@ -247,6 +256,10 @@ def version(self):
247
256
248
257
return version
249
258
259
+ @property
260
+ def std (self ):
261
+ return self ._cxxstd if self ._cpp else self ._cstd
262
+
250
263
def get_version (self ):
251
264
result , stdout , stderr = call_capture_output ((self .cc , "--version" ))
252
265
if result != 0 :
@@ -482,15 +495,15 @@ def __init_finalize__(self, **kwargs):
482
495
platform = kwargs .pop ('platform' , configuration ['platform' ])
483
496
484
497
if isinstance (platform , NvidiaDevice ):
485
- self .cflags .remove ('-std=c99 ' )
498
+ self .cflags .remove (f '-std={ self . std } ' )
486
499
# Add flags for OpenMP offloading
487
500
if language in ['C' , 'openmp' ]:
488
501
cc = get_nvidia_cc ()
489
502
if cc :
490
503
self .cflags += ['-Xopenmp-target' , f'-march=sm_{ cc } ' ]
491
504
self .ldflags += ['-fopenmp' , '-fopenmp-targets=nvptx64-nvidia-cuda' ]
492
505
elif platform is AMDGPUX :
493
- self .cflags .remove ('-std=c99 ' )
506
+ self .cflags .remove (f '-std={ self . std } ' )
494
507
# Add flags for OpenMP offloading
495
508
if language in ['C' , 'openmp' ]:
496
509
self .ldflags += ['-target' , 'x86_64-pc-linux-gnu' ]
@@ -553,9 +566,9 @@ def __init_finalize__(self, **kwargs):
553
566
self .ldflags += ['-fopenmp' ]
554
567
555
568
if isinstance (platform , NvidiaDevice ):
556
- self .cflags .remove ('-std=c99 ' )
569
+ self .cflags .remove (f '-std={ self . std } ' )
557
570
elif platform is AMDGPUX :
558
- self .cflags .remove ('-std=c99 ' )
571
+ self .cflags .remove (f '-std={ self . std } ' )
559
572
# Add flags for OpenMP offloading
560
573
if language in ['C' , 'openmp' ]:
561
574
self .ldflags += ['-target' , 'x86_64-pc-linux-gnu' ]
@@ -590,16 +603,13 @@ def __lookup_cmds__(self):
590
603
591
604
class PGICompiler (Compiler ):
592
605
593
- _cpp = True
606
+ _default_cpp = True
594
607
595
608
def __init_finalize__ (self , ** kwargs ):
596
609
597
- self .cflags .remove ('-std=c99' )
598
610
self .cflags .remove ('-O3' )
599
611
self .cflags .remove ('-Wall' )
600
612
601
- self .cflags .append ('-std=c++11' )
602
-
603
613
language = kwargs .pop ('language' , configuration ['language' ])
604
614
platform = kwargs .pop ('platform' , configuration ['platform' ])
605
615
@@ -643,14 +653,13 @@ def __lookup_cmds__(self):
643
653
644
654
class CudaCompiler (Compiler ):
645
655
646
- _cpp = True
656
+ _default_cpp = True
647
657
648
658
def __init_finalize__ (self , ** kwargs ):
649
659
650
- self .cflags .remove ('-std=c99' )
651
660
self .cflags .remove ('-Wall' )
652
661
self .cflags .remove ('-fPIC' )
653
- self .cflags .extend (['-std=c++14' , '- Xcompiler' , '-fPIC' ])
662
+ self .cflags .extend (['-Xcompiler' , '-fPIC' ])
654
663
655
664
if configuration ['mpi' ]:
656
665
# We rather use `nvcc` to compile MPI, but for this we have to
@@ -717,15 +726,10 @@ def __lookup_cmds__(self):
717
726
718
727
class HipCompiler (Compiler ):
719
728
720
- _cpp = True
729
+ _default_cpp = True
721
730
722
731
def __init_finalize__ (self , ** kwargs ):
723
732
724
- self .cflags .remove ('-std=c99' )
725
- self .cflags .remove ('-Wall' )
726
- self .cflags .remove ('-fPIC' )
727
- self .cflags .extend (['-std=c++14' , '-fPIC' ])
728
-
729
733
if configuration ['mpi' ]:
730
734
# We rather use `hipcc` to compile MPI, but for this we have to
731
735
# explicitly pass the flags that an `mpicc` would implicitly use
@@ -831,7 +835,7 @@ def __init_finalize__(self, **kwargs):
831
835
language = kwargs .pop ('language' , configuration ['language' ])
832
836
833
837
if language == 'sycl' :
834
- raise ValueError ( "Use SyclCompiler to jit-compile sycl" )
838
+ warning ( f "Use SyclCompiler (`sycl`) to jit-compile sycl, not { self . name } " )
835
839
836
840
elif language == 'openmp' :
837
841
# Earlier versions to OneAPI 2023.2.0 (clang17 underneath), have an
@@ -878,7 +882,7 @@ def __lookup_cmds__(self):
878
882
879
883
class SyclCompiler (OneapiCompiler ):
880
884
881
- _cpp = True
885
+ _default_cpp = True
882
886
883
887
def __init_finalize__ (self , ** kwargs ):
884
888
IntelCompiler .__init_finalize__ (self , ** kwargs )
@@ -887,9 +891,9 @@ def __init_finalize__(self, **kwargs):
887
891
language = kwargs .pop ('language' , configuration ['language' ])
888
892
889
893
if language != 'sycl' :
890
- raise ValueError ( "Expected language sycl with SyclCompiler" )
894
+ warning ( f "Expected language sycl with SyclCompiler, not { language } " )
891
895
892
- self .cflags .remove ('-std=c99 ' )
896
+ self .cflags .remove (f '-std={ self . std } ' )
893
897
self .cflags .append ('-fsycl' )
894
898
895
899
self .cflags .remove ('-g' ) # -g disables some optimizations in IGC
@@ -903,7 +907,7 @@ def __init_finalize__(self, **kwargs):
903
907
elif isinstance (platform , IntelDevice ):
904
908
self .cflags .append ('-fsycl-targets=spir64' )
905
909
else :
906
- raise NotImplementedError (f"Unsupported platform { platform } " )
910
+ warning (f"Unsupported platform { platform } " )
907
911
908
912
909
913
class CustomCompiler (Compiler ):
@@ -945,7 +949,6 @@ def __new__(cls, *args, **kwargs):
945
949
obj = super ().__new__ (cls )
946
950
# Keep base to initialize accordingly
947
951
obj ._base = kwargs .pop ('base' , _base )
948
- obj ._cpp = obj ._base ._cpp
949
952
950
953
return obj
951
954
@@ -976,6 +979,10 @@ def __lookup_cmds__(self):
976
979
def __new_with__ (self , ** kwargs ):
977
980
return super ().__new_with__ (base = self ._base , ** kwargs )
978
981
982
+ @property
983
+ def _default_cpp (self ):
984
+ return self ._base ._default_cpp
985
+
979
986
980
987
class CompilerRegistry (dict ):
981
988
"""
@@ -984,15 +991,19 @@ class CompilerRegistry(dict):
984
991
"""
985
992
986
993
def __getitem__ (self , key ):
994
+ if isinstance (key , Compiler ):
995
+ key = key .name
996
+
987
997
if key .startswith ('gcc-' ):
988
998
i = key .split ('-' )[1 ]
989
999
return partial (GNUCompiler , suffix = i )
1000
+
990
1001
return super ().__getitem__ (key )
991
1002
992
- def __contains__ (self , k ):
993
- if isinstance (k , Compiler ):
994
- k = k .name
995
- return k in self .keys () or k .startswith ('gcc-' )
1003
+ def __contains__ (self , key ):
1004
+ if isinstance (key , Compiler ):
1005
+ key = key .name
1006
+ return key in self .keys () or key .startswith ('gcc-' )
996
1007
997
1008
998
1009
_compiler_registry = {
@@ -1011,6 +1022,7 @@ def __contains__(self, k):
1011
1022
'nvc++' : NvidiaCompiler ,
1012
1023
'nvidia' : NvidiaCompiler ,
1013
1024
'cuda' : CudaCompiler ,
1025
+ 'nvcc' : CudaCompiler ,
1014
1026
'osx' : ClangCompiler ,
1015
1027
'intel' : OneapiCompiler ,
1016
1028
'icx' : OneapiCompiler ,
0 commit comments