Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointers from function argument as host data (memory allocation) #30

Open
ghost opened this issue Nov 6, 2016 · 0 comments
Open

Pointers from function argument as host data (memory allocation) #30

ghost opened this issue Nov 6, 2016 · 0 comments

Comments

@ghost
Copy link

ghost commented Nov 6, 2016

Say I want to add two vectors as in example two. In the example, memory space is allocated and host data is created inside the code:

    float*       h_a = (float*) calloc(LENGTH, sizeof(float));       // a vector
    float*       h_b = (float*) calloc(LENGTH, sizeof(float));  // a vector
     int i = 0;
     int count = LENGTH;
     for(i = 0; i < count; i++){
        h_a[i] = rand() / (float)RAND_MAX;
        h_b[i] = rand() / (float)RAND_MAX;
    }

I'm trying to pass vectors a and b from R. They are passed as arguments to the main function as: vadd(double *a, double *b, int *n) (in RI have to change mainfor some other name like vadd). I allocate memory and I dereference the arguments as:

int i = 0;
    int count = LENGTH;
    for(i = 0; i < count; i++){
        h_a[i] = a[i];
        h_b[i] = b[i];
    }

This dereferencing procedure is taking too much time. Is there a way so that these pointers passed as arguments to the function are set as host data directly without the loop? Something like:

h_a = *a; h_b = *b;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants