ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.81k stars 2.54k forks source link

Unknown target CPU 'x86-64' when compiling CUDA #19442

Open glyh opened 7 months ago

glyh commented 7 months ago

Zig Version

0.11.0

Steps to Reproduce and Observed Behavior

$ zig c++ runtime.cu 
zig: warning: CUDA version 11.8 is only partially supported [-Wunknown-cuda-version]
error: unknown target CPU 'x86-64'
note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35, sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72, sm_75, sm_80, sm_86, sm_87, sm_89, sm_90, gfx600, gfx601, gfx602, gfx700, gfx701, gfx702, gfx703, gfx704, gfx705, gfx801, gfx802, gfx803, gfx805, gfx810, gfx900, gfx902, gfx904, gfx906, gfx908, gfx909, gfx90a, gfx90c, gfx940, gfx1010, gfx1011, gfx1012, gfx1013, gfx1030, gfx1031, gfx1032, gfx1033, gfx1034, gfx1035, gfx1036, gfx1100, gfx1101, gfx1102, gfx1103

Expected Behavior

Pass compilation

RossComputerGuy commented 7 months ago

error: unknown target CPU 'x86-64'

Well, that target isn't even listed in the list of valid CPU types.

nektro commented 7 months ago

were u looking for -march=x86-64 ?

glyh commented 7 months ago

Doesn't matter:

$ zig c++ runtime.cu --cuda-gpu-arch=sm_70 -mcpu=x86-64 # replace with march will yield same output.
info: available CPUs for architecture 'x86_64':
 alderlake
 amdfam10
 athlon
 athlon64
 athlon64_sse3
 athlon_4
 athlon_fx
 athlon_mp
 athlon_tbird
 athlon_xp
 atom
 barcelona
 bdver1
 bdver2
 bdver3
 bdver4
 bonnell
 broadwell
 btver1
 btver2
 c3
 c3_2
 cannonlake
 cascadelake
 cooperlake
 core2
 core_avx2
 core_avx_i
 corei7
 corei7_avx
 emeraldrapids
 generic
 geode
 goldmont
 goldmont_plus
 grandridge
 graniterapids
 haswell
 i386
 i486
 i586
 i686
 icelake_client
 icelake_server
 ivybridge
 k6
 k6_2
 k6_3
 k8
 k8_sse3
 knl
 knm
 lakemont
 meteorlake
 nehalem
 nocona
 opteron
 opteron_sse3
 penryn
 pentium
 pentium2
 pentium3
 pentium3m
 pentium4
 pentium4m
 pentium_m
 pentium_mmx
 pentiumpro
 prescott
 raptorlake
 rocketlake
 sandybridge
 sapphirerapids
 sierraforest
 silvermont
 skx
 skylake
 skylake_avx512
 slm
 tigerlake
 tremont
 westmere
 winchip2
 winchip_c6
 x86_64
 x86_64_v2
 x86_64_v3
 x86_64_v4
 yonah
 znver1
 znver2
 znver3
 znver4

error: unknown CPU: 'x86'

In fact:

zig c++ runtime.cu 
zig: warning: CUDA version 11.8 is only partially supported [-Wunknown-cuda-version]
error: unknown target CPU 'x86-64'
note: valid target CPU values are: sm_20, sm_21, sm_30, sm_32, sm_35, sm_37, sm_50, sm_52, sm_53, sm_60, sm_61, sm_62, sm_70, sm_72, sm_75, sm_80, sm_86, sm_87, sm_89, sm_90, gfx600, gfx601, gfx602, gfx700, gfx701, gfx702, gfx703, gfx704, gfx705, gfx801, gfx802, gfx803, gfx805, gfx810, gfx900, gfx902, gfx904, gfx906, gfx908, gfx909, gfx90a, gfx90c, gfx940, gfx1010, gfx1011, gfx1012, gfx1013, gfx1030, gfx1031, gfx1032, gfx1033, gfx1034, gfx1035, gfx1036, gfx1100, gfx1101, gfx1102, gfx1103

Does partial support means no support at all?

glyh commented 7 months ago

Looks like this is not resolved in the first place: https://github.com/ziglang/zig/issues/10634#issuecomment-1028716658

glyh commented 5 months ago

Ideally I would like to see interop with nvidia GPU as easy as it's done in C++. There's cudaz available but it's basially a toy because you can't even share types definitions between host and device code without copying around.

For that to happen something like #4045 needs to be done because we need to manually handle all includes.

Some related:

There's https://github.com/libmir/dcompute and https://github.com/Rust-GPU/Rust-CUDA