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

  • Home
  • SEARCH
  • 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 8725549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:03:50+00:00 2026-06-13T08:03:50+00:00

#include <cuda.h> #include <cuda_runtime.h> #include <iostream> #include <vector> using namespace std; __global__ void kernel(vector

  • 0
#include <cuda.h>
#include <cuda_runtime.h>
#include <iostream>
#include <vector>
using namespace std;

__global__ void kernel(vector <int> *a,vector <int> *b, vector <int> *c)
{
    int index=threadIdx.x;
    c[index]=a[index]+b[index];
};

int main ()
{
    //Paar constanten initializeren
    int N=3;
    vector <int> a (3,1);
    vector <int> b (3,1);
    vector <int> c (3,0);
    int size=N*sizeof(vector <int>);
    //Device variabelen
    vector <int> d_a;
    vector <int> d_b;
    vector <int> d_c;

    //<size> bytes device-geheugen vrijmaken op locatie &a
    cudaMalloc( (void **) &a, size);
    cudaMalloc ( (void **) &b, size);
    cudaMalloc ( (void **) &c, size);

    //Kopieer inputs van &a naar &d_a
    cudaMemcpy(&d_a,&a,size,cudaMemcpyHostToDevice);
    cudaMemcpy(&d_b,&b,size,cudaMemcpyHostToDevice);

    printf( (char *) a[1]);
    printf( (char *) c[1]);
    //Voer kernel uit

    kernel<<<N,1>>>(&d_a,&d_b,&d_c);

    //Kopieer resultaat terug naar host 
    cudaMemcpy(&c,&d_c,size,cudaMemcpyDeviceToHost);

    printf( (char *) c[1]);

    return 0;
};

So this is my basic C++ vector addition program, though it won’t compile because it doesn’t know what to do with the “+” when adding indexes (“no operator “+” matches these operands”). Anyone have an idea why this doesn’t work inside the kernel? I think it may have to do with the fact that it’s a host function or something like that, though I wouldn’t know how to get around that problem.

Greetings and 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-13T08:03:51+00:00Added an answer on June 13, 2026 at 8:03 am

    You can’t use the STL in device code … you’re going to have to use an array or some other CUDA construct like the Thrust Library.

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

Sidebar

Related Questions

#include <iostream> using namespace std; int main() { int a, b, c, max; cout<<a=;
#include <iostream> #include <string.h> using namespace std; int main() { int e=0; int b=0;
#include <iostream> #include <string> using namespace std; string crash() { } int noCrash() {
#include <iostream> #include <tuple> int main(){ auto bt=std::make_tuple(std::tuple<>(),std::tuple<std::tuple<>>()); //Line 1 auto bt2=std::make_tuple(std::tuple<>(),std::tuple<>()); //Line 2
#include <iostream> #include <cassert> #include <vector> #include <ctime> #include <cstdlib> #include <Windows.h> using namespace
#include<cuda_runtime.h> #include<stdio.h> #include<cuda.h> #include<stdlib.h> __global__ void setVal(char **c){ c[(blockIdx.y * gridDim.x) + blockIdx.x] =
#include<stdio.h> #include<stdlib.h> char* re() { char *p = hello; return p; } int main()
#include <list> using std::list; class foo { ... class bar : public foo {
I tried to compile following program (main.cu) with the nvcc (CUDA 5.0 RC): #include
For using atomic operations in CUDA, is it necessary to include some CUDA header

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.