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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:59:36+00:00 2026-05-27T18:59:36+00:00

Is it possible that cudaMalloc fails to allocate because there is no free computer

  • 0

Is it possible that cudaMalloc fails to allocate because there is no free computer memory?
Although the GPU memory is available cudaMalloc fails when the RAM (computer memory) is full.
My code can be sumamrized in the following example code:

int main()
{
    size_t N=sizeof(int)*100000000;
    while(true)
    {
        int *d_a,*d_b;
        if ( cudaSuccess !=cudaMalloc(&d_a, N)) printf("Error Allocating GPU Memory");
        if ( cudaSuccess !=cudaMalloc(&d_b, N)) printf("Error Allocating GPU Memory"); 
        cudaMemset(d_a,1,N);
        cudaMemset(d_b,2,N);

        int *h_a= (int *)malloc(N);
        int *h_b=(int *)malloc(N);
        if(!h_a || !h_b)  printf("Error Allocating CPU Memory");
        cudaMemcpy(d_a,h_a, N, cudaMemcpyHostToDevice);
        cudaMemcpy(d_b,h_b, N, cudaMemcpyHostToDevice);

        cudaFree(d_a);
        cudaFree(d_b);
    }
    getch();
    return 1;
}

The following code fails to allocate GPU memory only when computer memory is full!
The error i get is Error Allocating GPU Memory instead of Error Allocating CPU Memory

  • 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-27T18:59:37+00:00Added an answer on May 27, 2026 at 6:59 pm

    You’re freeing GPU memory in every iteration so that will never be full. Operating System uses your hardisk as Virtual Memory when the RAM gets full so the code will slow down but it will keep on allocating memory on Host side. Maybe CUDA keeps the pointer to the Device memory on Host memory which might be causing problem when RAM fills up.

    An easy way to check this is to put a counter and see at which iteration the error comes. Then first run the program allocating memory on GPU alone and later on CPU alone, if the counter increases for both the cases then my assumption is correct.

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

Sidebar

Related Questions

Is it possible that a MySQL function/stored procedure returns a query result? Because I
It is possible that this problem doesn't display on your computer. A working example
Is it possible that Microsoft will be able to make F# programs, either at
How is it possible that .NET is finding the wrong MyType in this scenario?
Is it possible that using jQuery, I cancel/abort an Ajax request that I have
Is it possible that when you have a webpage, when you open the PDF,
It is quite possible that I may not have got the point, but I
is it possible that my mingw 3.4.5 installation is faulty? or is this provided
It's possible that I'm not really understanding how git works here, but I have
Is it possible that the html page loaded, cannot be refreshed or reloaded by

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.