你好,我发现你实现的这个CudaAllocator是好用的CUDA内存管理工具,我尝试将CudaAllocator.h文件拷贝到我的工程中,并写了一个非常简单测试函数:
int main()
{
int N = 3;
std::vector<int, CudaAllocator<int>> arr(N);
TestVectorKernel <<<1, 4 >>> (arr.data(), N);
checkCudaErrors(cudaDeviceSynchronize());
for (size_t i = 0; i < N; i++)
{
std::cout << arr[i] << std::endl;
}
return 0;
}
Build started...
1>------ Build started: Project: Project2, Configuration: Debug x64 ------
1>Compiling CUDA source file Source.cpp...
1>
1>C:\Users\user\source\repos\cuda_test\Project2>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin\nvcc.exe" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64" -x cu -rdc=true -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -allow-unsupported-compiler -g -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W3 /nologo /Od /Fdx64\Debug\vc143.pdb /FS /Zi /RTC1 /MDd " -o x64\Debug\Source.cpp.obj "C:\Users\user\source\repos\cuda_test\Project2\Source.cpp"
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\vector(1908): error : no suitable user-defined conversion from "std::_Rebind_alloc_t<CudaAllocator<int>, int>" to "std::_Rebind_alloc_t<std::_Rebind_alloc_t<CudaAllocator<int>, int>, std::_Container_proxy>" exists
1> detected during:
1> instantiation of "void std::vector<_Ty, _Alloc>::_Construct_n(std::vector<_Ty, _Alloc>::size_type, _Valty &&...) [with _Ty=int, _Alloc=CudaAllocator<int>, _Valty=<>]"
1>(669): here
1> instantiation of "std::vector<_Ty, _Alloc>::vector(std::vector<_Ty, _Alloc>::size_type, const _Alloc &) [with _Ty=int, _Alloc=CudaAllocator<int>]"
1>C:/Users/user/source/repos/cuda_test/Project2/Source.cpp(34): here
1>
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\vector(793): error : no suitable user-defined conversion from "std::_Rebind_alloc_t<CudaAllocator<int>, int>" to "std::_Rebind_alloc_t<std::_Rebind_alloc_t<CudaAllocator<int>, int>, std::_Container_proxy>" exists
1> detected during instantiation of "std::vector<_Ty, _Alloc>::~vector() [with _Ty=int, _Alloc=CudaAllocator<int>]"
1>C:/Users/user/source/repos/cuda_test/Project2/Source.cpp(34): here
1>
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\vector(794): error : no instance of function template "std::_Delete_plain_internal" matches the argument list
1> argument types are: (<error-type>, std::_Container_proxy *)
1> detected during instantiation of "std::vector<_Ty, _Alloc>::~vector() [with _Ty=int, _Alloc=CudaAllocator<int>]"
1>C:/Users/user/source/repos/cuda_test/Project2/Source.cpp(34): here
1>
1>3 errors detected in the compilation of "C:/Users/user/source/repos/cuda_test/Project2/Source.cpp".
1>Source.cpp
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\BuildCustomizations\CUDA 11.1.targets(785,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin\nvcc.exe" -gencode=arch=compute_52,code=\"sm_52,compute_52\" --use-local-env -ccbin "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64" -x cu -rdc=true -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include" -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -allow-unsupported-compiler -g -D_DEBUG -D_CONSOLE -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W3 /nologo /Od /Fdx64\Debug\vc143.pdb /FS /Zi /RTC1 /MDd " -o x64\Debug\Source.cpp.obj "C:\Users\user\source\repos\cuda_test\Project2\Source.cpp"" exited with code 1.
1>Done building project "Project2.vcxproj" -- FAILED.