Skip to content
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

File cuda/rtc.hpp fails to compile. #546

Closed
aryan-programmer opened this issue Oct 6, 2023 · 9 comments
Closed

File cuda/rtc.hpp fails to compile. #546

aryan-programmer opened this issue Oct 6, 2023 · 9 comments
Assignees
Labels
ms-windows Related to the Microsoft Windows operating system resolved-on-development

Comments

@aryan-programmer
Copy link

File cuda/rtc.hpp fails to compile.

Minimal example:

#include <iostream>
#include <cuda/rtc.hpp>

using namespace std;

int main() {
	cout << "Hello world!" << endl;
	return 0;
}
Current output:

63 compilation errors similar to:

C:\local\cuda-api-wrappers\src\cuda\rtc/compilation_options.hpp(585): error : more than one operator "<<" matches these operands:
            function template "MarshalTarget &cuda::rtc::operator<<(MarshalTarget &, cuda::rtc::detail_::opt_start_t<Delimiter> &)"
(489): here
            function template "cuda::rtc::marshalled_options_t &cuda::rtc::marshalled_options_t::operator<<(T &&)"
C:\local\cuda-api-wrappers\src\cuda\rtc\detail/marshalled_options.hpp(53): here
            operand types are: cuda::rtc::marshalled_options_t << cuda::rtc::detail_::opt_start_t<void (*)()>
          detected during:
            instantiation of "void cuda::rtc::process(const cuda::rtc::compilation_options_t<cuda::ptx> &, MarshalTarget &, Delimiter, __nv_bool) [with MarshalTarget=cuda::rtc::marshalled_options_t, Delimiter=void (*)()]"
(689): here
            instantiation of "cuda::rtc::marshalled_options_t cuda::rtc::marshal(const cuda::rtc::compilation_options_t<Kind> &) [with Kind=cuda::ptx]"
C:\local\cuda-api-wrappers\src\cuda\rtc/program.hpp(567): here
Expected output:

The code should compile and output:

Hello world!
@eyalroz
Copy link
Owner

eyalroz commented Oct 6, 2023

It works for me:

g++ -o a a.cpp -I/opt/cuda-api-wrappers/include/ -I/usr/local/cuda/include

Can you give me more exact details on how you tried to build this? And - were you using v0.6.3 ? Another version?

@aryan-programmer
Copy link
Author

aryan-programmer commented Oct 7, 2023

Visual Studio 2022 (Version 17.7.4) (v143) with

  • Platform toolset: Visual Studio 2022 (v143)
  • C++ Language Standard: "ISO C++17 Standard (/std:c++17)"
  • C Language Standard: "Default (Legacy MSVC)"

I also tested with "ISO C++20 Standard (/std:c++20)", "ISO C++14 Standard (/std:c++14)", "ISO C11 Standard (/std:c11)" and "ISO C17 (2018) Standard (/std:c17)".

NVCC Version:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:41:10_Pacific_Daylight_Time_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

@eyalroz
Copy link
Owner

eyalroz commented Oct 7, 2023

Hmm, right, MSVC... maybe I can make the overload resolution easier for it somehow.

@eyalroz
Copy link
Owner

eyalroz commented Oct 7, 2023

Can you try playing with the signature on line 489? Replace:

MarshalTarget& operator<<(MarshalTarget& mt, detail_::opt_start_t<Delimiter>& opt_start);

with each of the following:

MarshalTarget& operator<<(MarshalTarget& mt, const detail_::opt_start_t<Delimiter>& opt_start);
MarshalTarget& operator<<(MarshalTarget& mt, const detail_::opt_start_t<Delimiter> opt_start);

... and see what happens with the compilation.

@aryan-programmer
Copy link
Author

The following works:

template <typename MarshalTarget, typename Delimiter>
MarshalTarget& operator<<(MarshalTarget& mt, const detail_::opt_start_t<Delimiter>& opt_start)

but you need to change cuda::rtc::detail_::opt_start_t into

template <typename Delimiter>
struct opt_start_t {
	mutable bool      ever_used;
	Delimiter         delimiter_;

	opt_start_t(Delimiter delimiter) : ever_used(false), delimiter_(delimiter){ }
};

Note the mutable keyword in the declaration of ever_used, which allows it to be edited even though the reference is const.

eyalroz added a commit that referenced this issue Oct 9, 2023
@eyalroz
Copy link
Owner

eyalroz commented Oct 9, 2023

Hmm. That's not a solution I favor, since it twists the meaning of opt_start_t. Let me try something else. Can you pull the fix_bug_546 branch and try that? It's an attempt to use SFINAE to reduce the overload set for streaming opt_start_t into a MarshalTarget.

@eyalroz
Copy link
Owner

eyalroz commented Oct 9, 2023

Also, thanks again for your help in working with me on this :-)

@eyalroz eyalroz self-assigned this Oct 9, 2023
@eyalroz eyalroz added the ms-windows Related to the Microsoft Windows operating system label Oct 9, 2023
@aryan-programmer
Copy link
Author

Your response is on the right track, the only thing needed was an std::decay_t around T before passing it into detail_::is_marshalling_control, like so:

template <typename T, typename = ::cuda::detail_::enable_if_t<not detail_::is_marshalling_control<std::decay_t<T>>::value>>
marshalled_options_t& operator<<(T&& x)
{
	oss << x;
	return *this;
}

This is ensure that the operator is not invoked for any of opt_start_t<Delimiter>, opt_start_t<Delimiter>&, const opt_start_t<Delimiter>&, opt_start_t<Delimiter>&&, const opt_start_t<Delimiter>&&, etc. all of which are different in the eyes of the C++ type system.

Also, it was my pleasure.

eyalroz added a commit that referenced this issue Oct 12, 2023
@eyalroz
Copy link
Owner

eyalroz commented Oct 12, 2023

Some more cosmetic fiddling. I believe we're done...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ms-windows Related to the Microsoft Windows operating system resolved-on-development
Projects
None yet
Development

No branches or pull requests

2 participants