gulrak / filesystem

An implementation of C++17 std::filesystem for C++11 /C++14/C++17/C++20 on Windows, macOS, Linux and FreeBSD.
MIT License
1.34k stars 173 forks source link

Can't compile with nvcc #139

Open yanggthomas opened 2 years ago

yanggthomas commented 2 years ago

Describe the bug Hi. I get a compile error when I compile with nvcc(cuda).

/tmp/tmp.opBbT90DDi/extern/filesystem/include/ghc/filesystem.hpp:5219:40: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
 GHC_INLINE directory_entry::operator const filesystem::path&() const noexcept
                                        ^~~~
/tmp/tmp.opBbT90DDi/extern/filesystem/include/ghc/filesystem.hpp:5219:40: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
/tmp/tmp.opBbT90DDi/extern/filesystem/include/ghc/filesystem.hpp:5219:40: error: ‘operator const int’ in ‘class ghc::filesystem::directory_entry’ does not name a type
/tmp/tmp.opBbT90DDi/extern/filesystem/include/ghc/filesystem.hpp:5219:40: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
 GHC_INLINE directory_entry::operator const filesystem::path&() const noexcept
                                        ^~~~
/tmp/tmp.opBbT90DDi/extern/filesystem/include/ghc/filesystem.hpp:5219:40: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
/tmp/tmp.opBbT90DDi/extern/filesystem/include/ghc/filesystem.hpp:5219:40: error: ‘operator const int’ in ‘class ghc::filesystem::directory_entry’ does not name a type

To Reproduce single header mode

#include <ghc/filesystem>

I could fix this bug by using forward/implementation in my project.

gulrak commented 2 years ago

Thanks for reporting this, not sure why this is happening. I don't have access to a system with nvcc yet, maybe I can set up one in a VM, but I need more informations like the version of nvcc and the OS to at least try to replicate it.

yanggthomas commented 2 years ago
截屏2022-01-13 下午10 32 59 截屏2022-01-13 下午10 33 57

hope these could help you

gulrak commented 2 years ago

Sorry, it took more time than expected to look into this. I had a test installing nvidia-cuda-toolkit on my 20.04 Ubuntu, that gives me:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

So sadly not exactly the same conditions.

I then made a build folder and from there simply tried:

$  nvcc ../test/filesystem_test.cpp -I ../include/

It ran without any error and the resulting a.out of that test gave me:

$ ./a.out 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.out is a Catch v2.13.7 host application.
Run with -? for options
[... cut expected warning output for things that can vary on platforms ...]
===============================================================================
All tests passed (1081 assertions in 70 test cases)

So my OS is newer but the CUDA toolkit is older, but I have the feeling something else is leading to those errors and I would need some reproducible example with the compile parameters.

I'm by no means a CUDA expert and don't use it in any project, so any help is welcome.

yanggthomas commented 2 years ago

Sorry for the late reply.

It could be because nvcc is actually passing the pure cpp/c source file to g++/gcc on linux. As you can see in https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#supported-host-compilers, which says "During non-CUDA phases (except the run phase), because these phases will be forwarded by nvcc to this compiler.". Here the host compiler means gcc on Linux.

As for this particular case, the error occurs if I put some code of filesystem in *.cu file, which will be processed by nvcc first. However, basiclly filesystem is not required on device(GPU) since generally this is not the part we want to accelerate via GPU and CUDA. Actually, this is a supported feature of nvcc that host only code in *.cu will be forward to host compiler.

So personally speaking, I tend to regard this problem as a bug of nvcc. Probably add a hint in the documentation to suggest others to use "forward/implementation" style with CUDA, in this way, the filesystem code will be processed only by host compiler and nvcc will stop complaining.

Additionally, to reproduce the error, maybe I can write some small examples. But I am relative new to github and I am not sure how to pass the code properly.