Skip to content

Conversation

vorlac
Copy link
Contributor

@vorlac vorlac commented Aug 11, 2024

These changes just resolved some ambiguity in the assignment operator for poor_mans_optional<> in a few locations when building on windows using msvc (should be latest version). I get the same errors from the vcpkg release as well as just including your repo as a submodule. In both cases the build is using cmake and /std:c++17.

Let me know if there's a chance something might have just been misconfigured on my end to run into these build errors. Or if the changes seem necessary to resolve these errors, let me know if you'd prefer the template parameter in pci_id.hpp to be int rather than cuda::rtc::optimization_level_t and I can update the PR.

Here's the output of the build prior to these changes:

03:11:56:531	    0% [0.002s] (0/2)  -Re-checking globbed directories...
03:11:56:531	   50% [0.477s] (1/2)  -Building CXX object CMakeFiles\cuda_analysis.dir\src\main.cpp.obj
03:11:56:531	  FAILED: CMakeFiles/cuda_analysis.dir/src/main.cpp.obj 
03:11:56:531	  C:\PROGRA~1\MICROS~2\2022\COMMUN~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\cl.exe  /nologo /TP -DBSONCXX_STATIC -DCUDA_API_WRAPPERS_USE_WIN32_THREADS -DCUTLASS_ENABLE_CUBLAS=1 -DCUTLASS_ENABLE_CUDNN=1 -DMONGOCXX_STATIC -IC:\Users\sal\development\vorlac\routeanalytics-cuda\src -IC:\Users\sal\development\vorlac\routeanalytics-cuda\SYSTEM -I\include -IC:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src -external:IC:\Users\sal\development\vorlac\routeanalytics-cuda\.out\build\msvc-debug\vcpkg_installed\x64-windows-static-md\include -external:I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.6\include" -external:IC:\Users\sal\development\vorlac\routeanalytics-cuda\.out\build\msvc-debug\vcpkg_installed\x64-windows-static-md\include\bsoncxx\v_noabi -external:IC:\Users\sal\development\vorlac\routeanalytics-cuda\.out\build\msvc-debug\vcpkg_installed\x64-windows-static-md\include\mongocxx\v_noabi -external:W0 /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++17 -MDd /std:c++17 /utf-8 -openmp /showIncludes /FoCMakeFiles\cuda_analysis.dir\src\main.cpp.obj /FdCMakeFiles\cuda_analysis.dir\ /FS -c C:\Users\sal\development\vorlac\routeanalytics-cuda\src\main.cpp
03:11:56:531	C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail\pci_id.hpp(57): error C2593: 'operator =' is ambiguous
03:11:56:531	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(79): note: could be 'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(T &&) noexcept(<expr>)'
03:11:56:531	          with
03:11:56:531	          [
03:11:56:531	              T=int
03:11:56:531	          ]
03:11:56:531	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(73): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(cuda::detail_::no_value_t)'
03:11:56:532	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(66): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(const T &&) noexcept(<expr>)'
03:11:56:532	          with
03:11:56:532	          [
03:11:56:532	              T=int
03:11:56:532	          ]
03:11:56:532	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(59): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(const T &) noexcept(<expr>)'
03:11:56:532	          with
03:11:56:532	          [
03:11:56:532	              T=int
03:11:56:532	          ]
03:11:56:532	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(57): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(cuda::detail_::poor_mans_optional<int> &&) noexcept'
03:11:56:532	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(55): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(const cuda::detail_::poor_mans_optional<int> &) noexcept'
03:11:56:532	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api/detail/pci_id.hpp(57): note: while trying to match the argument list '(cuda::detail_::poor_mans_optional<int>, initializer list)'
03:11:56:532	C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail\pci_id.hpp(72): error C2593: 'operator =' is ambiguous
03:11:56:532	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(79): note: could be 'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(T &&) noexcept(<expr>)'
03:11:56:532	          with
03:11:56:532	          [
03:11:56:532	              T=int
03:11:56:532	          ]
03:11:56:532	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(73): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(cuda::detail_::no_value_t)'
03:11:56:533	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(66): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(const T &&) noexcept(<expr>)'
03:11:56:533	          with
03:11:56:533	          [
03:11:56:533	              T=int
03:11:56:533	          ]
03:11:56:533	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(59): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(const T &) noexcept(false)'
03:11:56:533	          with
03:11:56:533	          [
03:11:56:533	              T=int
03:11:56:533	          ]
03:11:56:533	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(57): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(cuda::detail_::poor_mans_optional<int> &&) noexcept'
03:11:56:533	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(55): note: or       'cuda::detail_::poor_mans_optional<int> &cuda::detail_::poor_mans_optional<int>::operator =(const cuda::detail_::poor_mans_optional<int> &) noexcept'
03:11:56:533	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api/detail/pci_id.hpp(72): note: while trying to match the argument list '(cuda::detail_::poor_mans_optional<int>, initializer list)'
03:11:56:534	C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\rtc\compilation_options.hpp(482): error C2593: 'operator =' is ambiguous
03:11:56:534	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(79): note: could be 'cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t> &cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t>::operator =(T &&) noexcept(<expr>)'
03:11:56:534	          with
03:11:56:534	          [
03:11:56:534	              T=cuda::rtc::cpp_dialect_t
03:11:56:534	          ]
03:11:56:534	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(73): note: or       'cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t> &cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t>::operator =(cuda::detail_::no_value_t)'
03:11:56:616	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(66): note: or       'cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t> &cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t>::operator =(const T &&) noexcept(<expr>)'
03:11:56:616	          with
03:11:56:616	          [
03:11:56:616	              T=cuda::rtc::cpp_dialect_t
03:11:56:645	          ]
03:11:56:645	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(59): note: or       'cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t> &cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t>::operator =(const T &) noexcept(<expr>)'
03:11:56:646	          with
03:11:56:646	          [
03:11:56:646	              T=cuda::rtc::cpp_dialect_t
03:11:56:646	          ]
03:11:56:646	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(57): note: or       'cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t> &cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t>::operator =(cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t> &&) noexcept'
03:11:56:646	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\api\detail/optional.hpp(55): note: or       'cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t> &cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t>::operator =(const cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t> &) noexcept'
03:11:56:646	  C:\Users\sal\development\vorlac\routeanalytics-cuda\extern\cuda-api-wrappers\src\cuda\rtc/compilation_options.hpp(482): note: while trying to match the argument list '(cuda::detail_::poor_mans_optional<cuda::rtc::cpp_dialect_t>, initializer list)'
03:11:56:646	  ninja: build stopped: subcommand failed.
03:11:56:648	

@vorlac
Copy link
Contributor Author

vorlac commented Aug 11, 2024

I just pushed another update to change those two template params to int since it seems like cuda::rtc::optimization_level_t wasn't recognized for all automated builds using cuda version < 12.0.

Also, if this is something you'd like to try to replicate on your end, the project repo I'm working with can be found here:
https://github.com/vorlac/routeanalytics-cuda

You should just be able to open the repo dir from vscode on windows (requires the Microsoft extensions for C++ and CMake), then run the configure/build commands using the cmake extension functionality. You can also just build/configure using the cmake preset argument: --preset msvc-debug. If you end up building from the command line, you'll either need to run the bat files to setup the msvc toolchain env, or just run the cmake configuration & build commands using the 64 bit developer terminal that comes with the msvc toolchain installation.

@eyalroz
Copy link
Owner

eyalroz commented Aug 11, 2024

Hello @vorlac .

  • Please first a bug, or more than one bug, about these issues. I was under the impression I was building my packages on Windows as part of the GitHub actions... do you believe that this may be a case of a template not getting instantiated?
  • I would rather avoid explicitly naming the type on every assignment of an empty. So, I would rather make the compiler accept it as it is...

@vorlac
Copy link
Contributor Author

vorlac commented Aug 13, 2024

Sorry @eyalroz - I completely missed all of your windows builds when I submitted this. Since you have it building successfully on your end without those errors I can dig a little deeper into this on my end. It's probably safe to close this since it's likely just a setup issue on my side. To answer your first question, i'm not exactly sure why msvc is complaining about this. The code in question seemed fine at a glance, but I can let you know if I uncover anything in a few days when I should free up to pick this project back up.

@eyalroz
Copy link
Owner

eyalroz commented Aug 13, 2024

Sorry @eyalroz - I completely missed all of your windows builds when I submitted this.

Oh, no problem, on the contrary - it's important that the library get to a state where it can build on potentially-'questionable' setups; plus, if there's something which fails the build, like maybe an MSVC version - then I should be catching it at CMake configuration time, rather than allowing the build itself to fail.

And it might also eventually be the case that I do have to explicitly set the type for some reason, who knows?. So, awaiting your further investigation.

@vorlac
Copy link
Contributor Author

vorlac commented Aug 14, 2024

after some further experimenting, it seems like removing this assignment operator for poor_mans_optional<> also resolves the build errors (without the need of explicitly specifying the type in the previous commits for this PR).

poor_mans_optional& operator=(const T&& value) noexcept(::std::is_nothrow_move_assignable<T>::value) {
    has_value_ = true;
    maybe_value.value = ::std::move(value);
    return *this;
}

The ambiguity it seems to be struggling with is with the operator above, and the definition that takes in a non-cost T r-value.

Before messing with the poor_mans_optional's definition I changed my project's build to be as close as possible to yours, the main difference being the version of visual studio your builds are using (vs2019) and the one I have installed (vs2022). I was still seeing the failures when using the same command/generator you use in your CI builds. It may be also worth pointing out my entire "project" is just building one of your smaller examples that you ported from the nvidia examples repo:
https://github.com/vorlac/routeanalytics-cuda/blob/main/src/main.cpp

The exact version of my VS installation is:
image

other tooling used for my project's build, output directly from cmake:

[cmake] Project Configuration Settigs: cuda_analysis
[cmake] =============================================
[cmake] 
[cmake] Build Configuration
[cmake]     CMAKE_SYSTEM_PROCESSOR:..................: AMD64
[cmake]     CMAKE_HOST_SYSTEM_NAME:..................: Windows
[cmake]     CMAKE_BUILD_TYPE:........................: Debug
[cmake]     CMAKE_CXX_COMPILER_ARCHITECTURE_ID:......: x64
[cmake]     CMAKE_CXX_STANDARD:......................: 17
[cmake]     CMAKE_CXX_COMPILER_VERSION:..............: 19.40.33812.0
[cmake]     CMAKE_GENERATOR:.........................: Ninja
[cmake]     CMAKE_VERSION:...........................: 3.29.6
[cmake]     CMAKE_MINIMUM_REQUIRED_VERSION:..........: 3.22
[cmake]     CMAKE_CXX_SIZEOF_DATA_PTR:...............: 8
[cmake]     VCPKG_TARGET_TRIPLET.....................: x64-windows-static-md
[cmake]     CMAKE_DEBUG_POSTFIX......................: .debug.x64
[cmake] 
[cmake] CMake Paths
[cmake]     CMAKE_CURRENT_SOURCE_DIR.................: C:/Users/sal/development/vorlac/routeanalytics-cuda
[cmake]     CMAKE_TOOLCHAIN_FILE:....................: C:/Users/Sal/development/vorlac/routeanalytics-cuda/extern/vcpkg/scripts/buildsystems/vcpkg.cmake
[cmake]     CMAKE_SOURCE_DIR:........................: C:/Users/sal/development/vorlac/routeanalytics-cuda
[cmake]     CMAKE_COMMAND:...........................: C:/Program Files/CMake/bin/cmake.exe
[cmake]     CLANG_FORMAT_PROGRAM:....................: C:/Program Files/LLVM/bin/clang-format.exe
[cmake]     CMAKE_CUDA_COMPILER:.....................: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin/nvcc.exe
[cmake]     CMAKE_CXX_COMPILER:......................: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe
[cmake]     CMAKE_LINKER:............................: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/link.exe
[cmake]     CMAKE_BUILD_TOOL:........................: C:/ProgramData/chocolatey/bin/ninja.exe
[cmake]     VCPKG_PROGRAM:...........................: C:/Users/sal/development/vorlac/routeanalytics-cuda/extern/vcpkg/vcpkg.exe
[cmake]     CMAKE_INSTALL_PREFIX:....................: C:/Users/sal/development/vorlac/routeanalytics-cuda/.out/install/msvc-debug
[cmake]     CMAKE_BINARY_DIR:........................: C:/Users/sal/development/vorlac/routeanalytics-cuda/.out/build/msvc-debug

If you want confirmation of the VS2019 vs VS2022 build being the culprit I can install VS2019 to see if that also give me a clean build with no changes required. Or I can also change the PR to undo the previous changes and instead remove that const T&& assignment operator to confirm all of your other builds still work fine without it. Let me know if you have a preference, or any other suggestions worth trying out before either of those two.

@vorlac
Copy link
Contributor Author

vorlac commented Aug 15, 2024

One more update, I tried downloading and installing vs2019 to get the confirmation that the toolchain it includes differs in a way that would/could prevent this error... but I can't seem to find the installer download anywhere for the community edition. They only seem to have the professional version available for download on the site which requires a SaaS subscription. If you know of a good location to find the installer let me know and I can give it a try. It'd probably be good to get confirmation if that's truly the root cause of the build errors I'm seeing that don't show up in your builds.

@eyalroz
Copy link
Owner

eyalroz commented Aug 18, 2024

Can you check and see what happens if we replace const T&& with just T&&? That const doesn't really belong there and I'm wondering whether MSVC might behave better without it.

@vorlac
Copy link
Contributor Author

vorlac commented Aug 18, 2024

The const can't be removed from the const T&& definition because you already have the mutable r-value definition here:

poor_mans_optional &operator=(T &&value) noexcept(::std::is_nothrow_move_assignable<T>::value)
{ return *this = value; }

eyalroz added a commit that referenced this pull request Aug 21, 2024
…of `poor_mans_optional<T>` from `const T&&`
@eyalroz
Copy link
Owner

eyalroz commented Aug 21, 2024

So, I removed it, please make sure that this addresses the issues you've seen...

removed the const T&& constructor from poor_mans_optional
@vorlac
Copy link
Contributor Author

vorlac commented Aug 22, 2024

OK cool, I can confirm everything builds without any warnings/errors after switching the submodule I'm using over to your development branch. I also updated this PR in case you wanted an easy merge to master, but feel free to discard if your workflow is to only merge changes into master from development.

@eyalroz
Copy link
Owner

eyalroz commented Aug 22, 2024

free to discard if your workflow is to only merge changes into master from development.

That is indeed my workflow. When I make a release, I graft the changes from development onto master.

Feel very free to make suggestions/requests even if they aren't bugs - I am always lacking concrete user feedback on this library.

@eyalroz eyalroz closed this Aug 22, 2024
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.

2 participants