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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:43:03+00:00 2026-06-08T22:43:03+00:00

It is not a secret that on CUDA 4.x the first call to cudaMalloc

  • 0

It is not a secret that on CUDA 4.x the first call to cudaMalloc
can be ridiculously slow (which was reported several times), seemingly a bug in CUDA drivers.

Recently, I noticed weird behaviour: the running time of cudaMalloc
directly depends on how many 3rd-party CUDA libraries I linked to my program
(note that I do NOT use these libraries, just link my program with them)

I ran some tests using the following program:

int main() {
  cudaSetDevice(0);
  unsigned int *ptr = 0;
  cudaMalloc((void **)&ptr, 2000000 * sizeof(unsigned int));   
  cudaFree(ptr);
return 1;
}

the results are as follows:

  • Linked with: -lcudart -lnpp -lcufft -lcublas -lcusparse -lcurand
    running time: 5.852449

  • Linked with: -lcudart -lnpp -lcufft -lcublas running time: 1.425120

  • Linked with: -lcudart -lnpp -lcufft running time: 0.905424

  • Linked with: -lcudart running time: 0.394558

According to ‘gdb’, the time indeed goes into my cudaMalloc, so it’s not caused by some
library initialization routine..

I wonder if somebody has plausible explanation for this ?

  • 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-08T22:43:06+00:00Added an answer on June 8, 2026 at 10:43 pm

    In your example, the cudaMalloc call initiates lazy context establishment on the GPU. When runtime API libraries are included, their binary payloads have to be inspected and the GPU elf symbols and objects they contain merged into the context. The more libraries there are, the longer you can expect the process to take. Further, if there is an architecture mismatch in any of the cubins and you have a backwards compatible GPU, it can also trigger driver recompilation of device code for the target GPU. In a very extreme case, I have seen an old application linked with an old version of CUBLAS take 10s of seconds to load and initialise when run on a Fermi GPU.

    You can explicitly force lazy context establishment by issuing a cudaFree call like this:

    int main() {
        cudaSetDevice(0);
        cudaFree(0); // context establishment happens here
        unsigned int *ptr = 0;
        cudaMalloc((void **)&ptr, 2000000 * sizeof(unsigned int));   
        cudaFree(ptr);
      return 1;
    }
    

    If you profile or instrument this version with timers you should find that the first cudaFree call consumes most of the runtime and the cudaMalloc call becomes almost free.

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

Sidebar

Related Questions

My understanding is that a salt is not intended to be secret, it is
That's not a secret: Silverlight's DataGrid default style is beautiful while WPF's is poor.
I noticed that cherrypy session does not require a secret key configuration. On the
Writing a plugin for [top-secret] (not really :P) and I decided that one best
Not ever sure if it can be done, but is it possible to use
I'm not sure that I really understand how Sinatra works. I'd like to get
I've created a Facebook group that has the privacy set to secret. I'm wondering
I have a string in my code that I use as a secret when
Using Mercurial, how can I bundle all changesets not known to be in another
I know that Apple does not permit developers to read the phone number of

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.