-1

I am using Thrust vectors for cuda kernels and i have created my own struct so i can pass in all of the data together, when i initialise a host vector of my custom type i get a build error from thrust.

initialisation of the vector:

host_vector<PhysicsData> physicsDataVector(numPeople + 1, 0);

custom data type:

__device__ __host__ struct PhysicsData {
    vector3 position;
    vector3 velocity;
    vector3 acceleration;
    vector3 force;
    float massInvert = 1.f;
    float drag = 1.f;
    bool dead = false;

    __device__ __host__ PhysicsData(){
        massInvert = 1.f;
        drag = 1.f;
        dead = false;
        position = vector3();
        velocity = vector3();
        acceleration = vector3();
        force = vector3();
    };
};

Error:

Severity    Code    Description Project File    Line    Suppression State
Error   C2664   'void thrust::detail::vector_base<T,Alloc>::fill_init(unsigned __int64,const T &)': cannot convert argument 2 from 'IteratorOrIntegralType' to 'const T &'  DefinitelyNotGodzillaCuda   C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7\include\thrust\detail\vector_base.inl  208
3
  • 3
    There is no implicit conversion from int to PhysicsData. The problem has nothing to do with either Cuda or Thrust. (Also, look in the Output window instead of the Error List to see the entire error message.) Commented Nov 6, 2023 at 14:29
  • Side note: your constructor only repeats what the default initialization has already done. Commented Nov 6, 2023 at 14:31
  • FYI: While Thrust explicitly supports the use of custom types, this kind of usage will give you very bad performance due to strided memory access. For good coalescing of global memory accesses you want a struct-of-array (SoA) data layout, i.e. one vector for each data-member of PhysicsData or maybe even for each component of vector3. See also Using thrust to handle vectors in CUDA classes?. Commented Nov 6, 2023 at 14:45

1 Answer 1

1

The issue was I was using the wrong constructor for the vector, I for some reason had a , 0 in my constructor so changing it to this fixed it

physicsDataVector(numPeople + 1);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.