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 1038581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:59:35+00:00 2026-05-16T14:59:35+00:00

I’ve written a small CUDA program on my macbook pro and now tried it

  • 0

I’ve written a small CUDA program on my macbook pro and now tried it out on my Linux box and get different results.

In order to ensure correctness, I wrote unit tests: An array of floats, which contains the values to check, is copied to the device and then back. Worst thing is that it sometimes returns different values on Linux (and very strange ones), but on my Mac it runs correctly every time.

I use CUDA 3.1 on both platforms on the mac however I have to compile it 32bit, because 64bit CUDA is not yet supported. The Linux machine is and x64 with Ubuntu 10.04 (gcc is 4.3.4) on the Mac the gcc version is i686-apple-darwin10-gcc-4.2.1.

The GPUs are on the Mac GeForce 9600M GT (Compute capability 1.1) and on the PC GeForce GTX 285 or a Telsa C1060 (Compute capability 1.3)

I’ve done a few more check and ensured that the data is read in completely, but so far I could not identify the problem any ideas how to figure out what is causing the trouble?

Update I couldn’t reproduce everything, but this example sometimes prints out just zeros and sometimes the correct results.. why?

#include <stdio.h>

__device__ void testFunc(float *ptr)
{
    *ptr = 3.4;
}

__global__ void testkernel(float* validation_data, int n)
{
    for(int i=0; i<100; i++)
        validation_data[i] = 666;

    float *ptr;
    testFunc(ptr);
    validation_data[0] = *ptr;
}

int main()
{  
    int n = 100;
    float *validation_data = (float*)malloc(sizeof(float)*100);
    float *validation_data_d;

    cudaMalloc((void**)&validation_data_d, sizeof(float)*n);

    testkernel <<<1,1>>> (validation_data_d, n);

    // Copy the array back again.
    cudaMemcpy(validation_data, validation_data_d, sizeof(float)*n,
        cudaMemcpyDeviceToHost);

    for(int i=0; i<n; i++)
        printf("%f ", validation_data[i]);
    printf("\n");
}
  • 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-05-16T14:59:35+00:00Added an answer on May 16, 2026 at 2:59 pm

    This is undefined behavior. You’re dereferencing an undefined pointer.

    float *ptr;
    testFunc(ptr);
    

    You could do the following instead:

    __device__ void testFunc(float &val)
    {
        val = 3.4;
    }
    
    ...
            float val;
            testFunc(&val);
            validation_data[0] = val;
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.