Skip to content

zig cc: Treat cu files as C++ source files #10704

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2022
Merged

Conversation

saierd
Copy link
Contributor

@saierd saierd commented Jan 27, 2022

First step towards #10634.

Treating stub files as C++ allows to use zig c++ as a host
compiler for nvcc.

Treating cu files as C++ allow using zig c++ as a host compiler in
CMake. CMake calls the host compiler with -E on a cu file to identify
the compiler.

Using zig c++ to directly compile CUDA code is untested.

First step towards ziglang#10634.

Treating stub files as C++ allows to use zig c++ as a host
compiler for nvcc.

Treating cu files as C++ allow using zig c++ as a host compiler in
CMake. CMake calls the host compiler with -E on a cu file to identify
the compiler.

Using zig c++ to directly compile CUDA code is untested.
@Vexu Vexu merged commit 2f41bd3 into ziglang:master Jan 27, 2022
@andrewrk
Copy link
Member

Are .cu files and .stub files strictly C++ code? Or are they something different, that is also passed to a c++ compiler?

If so, we should add an additional enum tag to FileExt for it.

@saierd
Copy link
Contributor Author

saierd commented Jan 27, 2022

Thank you for merging. Will this change be included in 0.9.1 or is there already a branch for that version?


To answer your question:

The .stub files are actually C++ as far as I can tell.

.cu files are not really C++, they contain some language extensions. As I wrote in #10634, clang can compile .cu files itself but this probably needs some more work to pass the correct parameters to clang (which then requires an additional enum tag).

That is not what is usually done, though. When using Nvidia's nvcc for compiling a .cu file it splits out the C++ code into a separate file and calls a host compiler to process it, which can be zig c++ now. See the nvcc documentation for more information on how this works. In principle zig c++ should never see the .cu file in this mode. When using CMake, though, it tries to identify the host compiler by executing it with -E on a .cu file directly. That is what this pull request aimed to fix as a first step.

In summary, with this pull request zig c++ can be used as a host compiler for CUDA using CMake and nvcc. The direct compilation of .cu files using clang's CUDA mode probably does not work yet and needs some additional handling of .cu files.

@andrewrk
Copy link
Member

andrewrk commented Jan 27, 2022

Thanks for the info! This is eligible for being included in the bug fix release.

@saierd saierd deleted the zig_cc_cu_files branch January 28, 2022 08:11
@gwenzek
Copy link
Contributor

gwenzek commented Feb 2, 2022

@saierd If you're interested in Cuda programming with Zig you should look at #10189 and cudaz

@saierd
Copy link
Contributor Author

saierd commented Feb 3, 2022

@saierd If you're interested in Cuda programming with Zig you should look at #10189 and cudaz

Thank you for the reference, this is interesting. I already have code in C++, though, I just want to compile it 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants