Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9181237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:14:25+00:00 2026-06-17T18:14:25+00:00

i am new to CUDA and is trying to learn the usage. can someone

  • 0

i am new to CUDA and is trying to learn the usage. can someone please help. i have the following in the main function (i am in visual studio and my source and header files are .cu and .cuh respectively)

 thrust::device_vector<float> d_vec(100);
 kernel<<<100,1>>>(d_vec);

and then in the kernel i have

    template <typename T> __global__ kernel(thrust::device_vector<T> d_vec)
    {  int tid = threadIdx.x + blockIdx.x*blockDim.x;
       T xxx = 3.0;
       d_vec[tid] = xxx;
     }

my objective is to call the kernel once with float and once with double. Also note that in this simple example i have variable xxx (which in my real case is some computation producing double or float numbers).

and i get two error:
1> calling a __host__ function (operator =) from a __global__ function is not allowed
2> calling a __host__ function (operator []) from a __global__ function is not allowed

so i guess “[]” and “=” in “d_vec[tid] = ..” is the problem. But my question is how do i access the device vector inside my kernel. Can someone please clarify what is the correct procedure and what i am doing wrong. thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:14:26+00:00Added an answer on June 17, 2026 at 6:14 pm

    thrust::device_vector objects/references can not be used as kernel parameters.
    You could use raw pointers to pass the device vector data.

    thrust::device_vector<float> d_vec(100);
    float* pd_vec = thrust::raw_pointer_cast(d_vec.data());
    kernel<<<100,1>>>(pd_vec);
    

    and here’s the prototype of the kernel

    template <typename T> __global__ kernel(T* pd_vec)
    

    You Q is similar to this one. how to cast thrust::device_vector<int> to raw pointer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to CUDA. I am trying to parallelize the following code. Right
I was trying to compile some CUDA codes under visual studio 2010 with CUDA
I'm really new to C(I have been learning Cuda and wanted to learn C
I'm new to CUDA C and I'm trying to parallelize the following piece of
I'm pretty new to CUDA. I use Microsoft Visual Studio 2010 where I don't
I'm new to CUDA, and I been trying to figure out what I'm doing
new to c#. I'm trying to make a simple system where I can search
I'm trying to write to CUDA host memory (which I created in my main
Can someone give a clear explanation of how the new and delete keywords would
I'm trying to replicate the behaviour of CUDA's __synchtreads() function in Ruby. Specifically, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.