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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:21:27+00:00 2026-05-27T00:21:27+00:00

If I try to send to my CUDA device a struct wich is heavier

  • 0

If I try to send to my CUDA device a struct wich is heavier than the size of memory available, will CUDA give me any kind of warning or error?

I’m asking that because my GPU has 1024 MBytes (1073414144 bytes) Total amount of global memory, but I don’t know how I should handle and eventual problem.

That’s my code:

#define VECSIZE 2250000
#define WIDTH 1500
#define HEIGHT 1500



// Matrices are stored in row-major order:
// M(row, col) = *(M.elements + row * M.width + col)
struct Matrix
{

    int width;
    int height;
    int* elements;

};


   int main()
   {


Matrix M;
M.width = WIDTH;
M.height = HEIGHT;
M.elements = (int *) calloc(VECSIZE,sizeof(int));   

int row, col;   


// define Matrix M
// Matrix generator:
for (int i = 0; i < M.height; i++)
    for(int j = 0; j < M.width; j++)
    {
    row = i;
    col = j; 

    if (i == j)
    M.elements[row * M.width + col] = INFINITY;
        else
        {
        M.elements[row * M.width + col] = (rand() % 2); // because 'rand() % 1' just does not seems to work ta all.
        if (M.elements[row * M.width + col] == 0)  // can't have zero weight.
            M.elements[row * M.width + col] = INFINITY;
            else if (M.elements[row * M.width + col] == 2)
                M.elements[row * M.width + col] = 1;    

        }

    }





// Declare & send device Matrix to Device.
Matrix d_M;
d_M.width = M.width;
d_M.height = M.height;
size_t size = M.width * M.height * sizeof(int);
cudaMalloc(&d_M.elements, size);
cudaMemcpy(d_M.elements, M.elements, size, cudaMemcpyHostToDevice);

int *d_k=  (int*) malloc(sizeof(int));
cudaMalloc((void**) &d_k, sizeof (int));



int *d_width=(int*)malloc(sizeof(int));
cudaMalloc((void**) &d_width, sizeof(int));
unsigned int *width=(unsigned int*)malloc(sizeof(unsigned int));
width[0] = M.width;
cudaMemcpy(d_width, width, sizeof(int), cudaMemcpyHostToDevice);

int *d_height=(int*)malloc(sizeof(int));
cudaMalloc((void**) &d_height, sizeof(int));
unsigned int *height=(unsigned int*)malloc(sizeof(unsigned int));
height[0] = M.height;   
cudaMemcpy(d_height, height, sizeof(int), cudaMemcpyHostToDevice);
    /*

        et cetera .. */
  • 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-27T00:21:28+00:00Added an answer on May 27, 2026 at 12:21 am

    While you may not currently be sending enough data to the GPU to max out it’s memory, when you do, your cudaMalloc will return the error code cudaErrorMemoryAllocation which as per the cuda api docs, signals that the memory allocation failed. I note that in your example code you are not checking the return values of the cuda calls. These return codes need to be checked to make sure your program is running correctly. The cuda api does not throw exceptions: you must check the return codes. See this article for info on checking the errors and getting meaningful messages about the errors

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

Sidebar

Related Questions

I try to send an e-mail from an app with an custom Content-Type. Any
I try to send gps longitude and latitude to the android emulator with eclipse,
I try to send a request to my server via GET, but qooxdoo sends
I've written this code to try and send a url as a post value
Im getting a connection refused when I try to send some data to my
i have downloaded Swift Mailer from their website and try to send simple email
I try to use PHPMailer to send registration, activation. etc mail to users: require(class.phpmailer.php);
I had try to implement the send me log feature into my apps but
I try send wap push message. I set datacoding 0xf5 and send submit sm
I try to send email from my application. Everything seems ok, mailmessage, credentials etc.

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.