Thrust device vector won't compile

51 views Asked by At

I'm trying to learn the Thrust library in c++ to learn about GPU programming and I made a simple class in a header file here:

#ifndef GRAPH
#define GRAPH
 
#include "Sine.h"
#include "CSV.h"
#include <thrust/device_vector.h>
#include <vector>
 
namespace graph {
    class Graph {
    public:
        Graph(int resolution, writer::CSV& store);
 
        void Place(producer::Sine pointproducer, int x, int y);
        void Run(int epochs, int stepsize);
    private:
        std::vector<producer::Sine> producers;
        std::vector<int> positions;
        thrust::device_vector<float> grid; <-- here is the error
        writer::CSV store;
        int resolution;
        float stepsize;
    };
}
#endif

Here is the build output:

Build started...
1>------ Build started: Project: GPUelectromagneticsim, Configuration: Debug Win32 ------
1>GPUelectromagneticsim.cpp
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(87,42): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void **,size_t)' to 'thrust::system::cuda::detail::allocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(87,42): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(87,54): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void *)' to 'thrust::system::cuda::detail::deallocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(87,54): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(90,69): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void *)' to 'thrust::system::cuda::detail::deallocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(90,69): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(93,42): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void **,size_t)' to 'thrust::system::cuda::detail::allocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(93,42): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(93,58): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void *)' to 'thrust::system::cuda::detail::deallocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(93,58): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): error C2440: 'specialization': cannot convert from 'int' to 'thrust::system::cuda::detail::allocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): message : Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): message : see reference to class template instantiation 'thrust::system::cuda::detail::cuda_memory_resource<0,0,thrust::pointer<void,thrust::cuda_cub::tag,thrust::tagged_reference<void,thrust::cuda_cub::tag>,thrust::use_default>>' being compiled
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\mr\validator.h(33): message : see reference to class template instantiation 'thrust::device_ptr_memory_resource<thrust::device_memory_resource>' being compiled
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\mr\allocator.h(54): message : see reference to class template instantiation 'thrust::mr::validator<MR>' being compiled
1>        with
1>        [
1>            MR=thrust::device_ptr_memory_resource<thrust::device_memory_resource>
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\mr\allocator.h(204): message : see reference to class template instantiation 'thrust::mr::allocator<T,Upstream>' being compiled
1>        with
1>        [
1>            T=float,
1>            Upstream=thrust::device_ptr_memory_resource<thrust::device_memory_resource>
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(97): message : see reference to class template instantiation 'thrust::mr::stateless_resource_allocator<T,thrust::device_ptr_memory_resource<thrust::device_memory_resource>>' being compiled
1>        with
1>        [
1>            T=float
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\detail\allocator\allocator_traits.h(244): message : see reference to class template instantiation 'thrust::device_allocator<T>' being compiled
1>        with
1>        [
1>            T=float
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\detail\contiguous_storage.h(41): message : see reference to class template instantiation 'thrust::detail::allocator_traits<Alloc>' being compiled
1>        with
1>        [
1>            Alloc=thrust::device_allocator<float>
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\detail\vector_base.h(46): message : see reference to class template instantiation 'thrust::detail::contiguous_storage<T,Alloc>' being compiled
1>        with
1>        [
1>            T=float,
1>            Alloc=thrust::device_allocator<float>
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_vector.h(55): message : see reference to class template instantiation 'thrust::detail::vector_base<T,Alloc>' being compiled
1>        with
1>        [
1>            T=float,
1>            Alloc=thrust::device_allocator<float>
1>        ]
1>A:\GPUprac\GPUelectromagneticsim\GPUelectromagneticsim\Graph.h(19): message : see reference to class template instantiation 'thrust::device_vector<float,thrust::device_allocator<T>>' being compiled
1>        with
1>        [
1>            T=float
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50,1): error C2973: 'thrust::system::cuda::detail::cuda_memory_resource': invalid template argument 'int'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(49): message : see declaration of 'thrust::system::cuda::detail::cuda_memory_resource'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): error C2440: 'specialization': cannot convert from 'int' to 'thrust::system::cuda::detail::deallocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): message : Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>A:\GPUprac\GPUelectromagneticsim\GPUelectromagneticsim\GPUelectromagneticsim.cpp(10,14): warning C4305: 'argument': truncation from 'double' to 'float'
1>A:\GPUprac\GPUelectromagneticsim\GPUelectromagneticsim\GPUelectromagneticsim.cpp(14,14): warning C4244: 'argument': conversion from 'double' to 'int', possible loss of data
1>Graph.cpp
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(87,42): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void **,size_t)' to 'thrust::system::cuda::detail::allocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(87,42): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(87,54): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void *)' to 'thrust::system::cuda::detail::deallocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(87,54): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(90,69): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void *)' to 'thrust::system::cuda::detail::deallocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(90,69): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(93,42): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void **,size_t)' to 'thrust::system::cuda::detail::allocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(93,42): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(93,58): error C2440: 'specialization': cannot convert from 'cudaError_t (__stdcall *)(void *)' to 'thrust::system::cuda::detail::deallocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(93,58): message : None of the functions with this name in scope match the target type
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): error C2440: 'specialization': cannot convert from 'int' to 'thrust::system::cuda::detail::allocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): message : Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): message : see reference to class template instantiation 'thrust::system::cuda::detail::cuda_memory_resource<0,0,thrust::pointer<void,thrust::cuda_cub::tag,thrust::tagged_reference<void,thrust::cuda_cub::tag>,thrust::use_default>>' being compiled
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\mr\validator.h(33): message : see reference to class template instantiation 'thrust::device_ptr_memory_resource<thrust::device_memory_resource>' being compiled
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\mr\allocator.h(54): message : see reference to class template instantiation 'thrust::mr::validator<MR>' being compiled
1>        with
1>        [
1>            MR=thrust::device_ptr_memory_resource<thrust::device_memory_resource>
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\mr\allocator.h(204): message : see reference to class template instantiation 'thrust::mr::allocator<T,Upstream>' being compiled
1>        with
1>        [
1>            T=float,
1>            Upstream=thrust::device_ptr_memory_resource<thrust::device_memory_resource>
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(97): message : see reference to class template instantiation 'thrust::mr::stateless_resource_allocator<T,thrust::device_ptr_memory_resource<thrust::device_memory_resource>>' being compiled
1>        with
1>        [
1>            T=float
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\detail\allocator\allocator_traits.h(244): message : see reference to class template instantiation 'thrust::device_allocator<T>' being compiled
1>        with
1>        [
1>            T=float
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\detail\contiguous_storage.h(41): message : see reference to class template instantiation 'thrust::detail::allocator_traits<Alloc>' being compiled
1>        with
1>        [
1>            Alloc=thrust::device_allocator<float>
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\detail\vector_base.h(46): message : see reference to class template instantiation 'thrust::detail::contiguous_storage<T,Alloc>' being compiled
1>        with
1>        [
1>            T=float,
1>            Alloc=thrust::device_allocator<float>
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_vector.h(55): message : see reference to class template instantiation 'thrust::detail::vector_base<T,Alloc>' being compiled
1>        with
1>        [
1>            T=float,
1>            Alloc=thrust::device_allocator<float>
1>        ]
1>A:\GPUprac\GPUelectromagneticsim\GPUelectromagneticsim\Graph.h(19): message : see reference to class template instantiation 'thrust::device_vector<float,thrust::device_allocator<T>>' being compiled
1>        with
1>        [
1>            T=float
1>        ]
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50,1): error C2973: 'thrust::system::cuda::detail::cuda_memory_resource': invalid template argument 'int'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\system\cuda\memory_resource.h(49): message : see declaration of 'thrust::system::cuda::detail::cuda_memory_resource'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): error C2440: 'specialization': cannot convert from 'int' to 'thrust::system::cuda::detail::deallocation_fn'
1>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.5\include\thrust\device_allocator.h(50): message : Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>A:\GPUprac\GPUelectromagneticsim\GPUelectromagneticsim\Graph.cpp(24,20): warning C4244: '=': conversion from 'int' to 'float', possible loss of data
1>A:\GPUprac\GPUelectromagneticsim\GPUelectromagneticsim\Graph.cpp(28,4): warning C4018: '<': signed/unsigned mismatch
1>A:\GPUprac\GPUelectromagneticsim\GPUelectromagneticsim\Graph.cpp(31,29): warning C4244: 'argument': conversion from 'int' to 'const float', possible loss of data
1>Generating Code...
1>Done building project "GPUelectromagneticsim.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I am completely confused why there is an error here, and I have searched and found no one else with the same issue (I wasn't even sure what to search).

Is it just not possible to store a device_vector in a class, that's the only reason I could think of? (though I am unsure why that would be).

EDIT:

In the gist it seems I put the build output from when I tried changing datatype, I have changed it now.

EDIT2:

Apologies for not adding full code, here it is

0

There are 0 answers