在我的 Windows 7 戴尔笔记本电脑上重新安装 VS2015 以使用 Update 3 版本后,我开始遇到编译带有未来标头的 cuda 项目的问题:
#include "cuda_runtime.h"
#include <future>
#include <iostream>
int main()
{
auto future = std::async(std::launch::async, [](int i) {
std::cout << i << std::endl;
}
,2);
future.get();
}
1>------ Build started: Project: TestFuture, Configuration: Debug x64 ------
1>Build started 2019-05-16 01:23:56.
1> 1>
1>InitializeBuildStatus:
1> Touching "x64\Debug\TestFuture.tlog\unsuccessfulbuild".
1> AddCudaCompileDeps:
1> Skipping target "AddCudaCompileDeps" because all output files are up-to-date with respect to the input files.
1> 1>
1>CudaBuildCore:
1> Compiling CUDA source file kernel.cu...
1>
1> C:\Users\dell\documents\visual studio 2015\Projects\TestFuture\TestFuture>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2015 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64" -I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" -I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include" -I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\um" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\shared" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\winrt" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -o x64\Debug\kernel.cu.obj "C:\Users\dell\documents\visual studio 2015\Projects\TestFuture\TestFuture\kernel.cu"
1> 1>
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\utility(445): error : static assertion failed with "tuple index out of bounds"
1> detected during:
1> instantiation of class "std::tuple_element<_Index, std::tuple<>> [with _Index=0ULL]"
1> (461): here
1> instantiation of class "std::tuple_element<_Index, std::tuple<_This, _Rest...>> [with _Index=1ULL, _This=std::decay_t<int>, _Rest=<>]"
1> (461): here
1> instantiation of class "std::tuple_element<_Index, std::tuple<_This, _Rest...>> [with _Index=2ULL, _This=std::decay_t<lambda [](int)->void>, _Rest=<std::decay_t<int>>]"
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(1888): here
1> instantiation of class "std::_Fake_no_copy_callable_adapter<_Types...> [with _Types=<lambda [](int)->void, int>]"
1> C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(1925): here
1> instantiation of "std::future<std::result_of_t<std::decay_t<_Fty> (std::decay_t<_ArgTypes>...)>> std::async(std::launch, _Fty &&, _ArgTypes &&...) [with _Fty=lambda [](int)->void, _ArgTypes=<int>]"
1> C:/Users/dell/documents/visual studio 2015/Projects/TestFuture/TestFuture/kernel.cu(19): here
1>
1> 1>
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(1888): error : no instance of function template "std::_Invoke_stored" matches the argument list
1> argument types are: (std::tuple<std::decay_t<lambda [](int)->void>, std::decay_t<int>>)
1> detected during:
1> instantiation of class "std::_Fake_no_copy_callable_adapter<_Types...> [with _Types=<lambda [](int)->void, int>]"
1> (1925): here
1> instantiation of "std::future<std::result_of_t<std::decay_t<_Fty> (std::decay_t<_ArgTypes>...)>> std::async(std::launch, _Fty &&, _ArgTypes &&...) [with _Fty=lambda [](int)->void, _ArgTypes=<int>]"
1> C:/Users/dell/documents/visual studio 2015/Projects/TestFuture/TestFuture/kernel.cu(19): here
1>
1> 1>
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\future(720): error : no instance of constructor "std::function<_Fty>::function [with _Fty=void ()]" matches the argument list
1> argument types are: (std::_Fake_no_copy_callable_adapter<lambda [](int)->void, int>)
1> detected during:
1> instantiation of "std::_Packaged_state<void (_ArgTypes...)>::_Packaged_state(_Fty2 &&) [with _ArgTypes=<>, _Fty2=std::_Fake_no_copy_callable_adapter<lambda [](int)->void, int>]"
1> (902): here
1> instantiation of "std::_Task_async_state<_Rx, _Inline>::_Task_async_state(_Fty2 &&) [with _Rx=std::result_of_t<std::decay_t<lambda [](int)->void> (std::decay_t<int>)>, _Inline=false, _Fty2=std::_Fake_no_copy_callable_adapter<lambda [](int)->void, int>]"
1> (1906): here
1> instantiation of "std::_Associated_state<std::_P_arg_type<_Ret>::type> *std::_Get_associated_state<_Ret,_Fty>(std::_Launch_type, _Fty &&) [with _Ret=std::result_of_t<std::decay_t<lambda [](int)->void> (std::decay_t<int>)>, _Fty=std::_Fake_no_copy_callable_adapter<lambda [](int)->void, int>]"
1> (1928): here
1> instantiation of "std::future<std::result_of_t<std::decay_t<_Fty> (std::decay_t<_ArgTypes>...)>> std::async(std::launch, _Fty &&, _ArgTypes &&...) [with _Fty=lambda [](int)->void, _ArgTypes=<int>]"
1> C:/Users/dell/documents/visual studio 2015/Projects/TestFuture/TestFuture/kernel.cu(19): here
1>
1> 3 errors detected in the compilation of "C:/Users/dell/AppData/Local/Temp/tmpxft_0000182c_00000000-8_kernel.cpp1.ii".
1> 1>
1>CUDACOMPILE : nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
1> kernel.cu
1> 1>
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\BuildCustomizations\CUDA 8.0.targets(689,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2015 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64" -I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include" -I"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include" -I"C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\um" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\shared" -I"C:\Program Files (x86)\Windows Kits\8.1\Include\winrt" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -o x64\Debug\kernel.cu.obj "C:\Users\dell\documents\visual studio 2015\Projects\TestFuture\TestFuture\kernel.cu"" exited with code 2.
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:03.80
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
在重新安装之前,我已经安装了 VS2019 社区,首先我认为实际上与一个系统上的 Visuals 存在一些不好的相关性,所以我决定卸载它们并只安装 VS2015,因为我的 GPU 具有 2.0 计算能力但它没有帮助。在控制台项目中,带有未来标头的代码编译得很好