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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:13:25+00:00 2026-06-14T23:13:25+00:00

From online documentation: cudaError_t cudaMemset (void * devPtr, int value, size_t count ) Fills

  • 0

From online documentation:

cudaError_t cudaMemset (void * devPtr, int value, size_t count )

Fills the first count bytes of the memory area pointed to by devPtr with the constant byte value value.

Parameters:
devPtr – Pointer to device memory
value – Value to set for each byte of specified memory
count – Size in bytes to set

This description doesn’t appear to be correct as:

int *dJunk;
cudaMalloc((void**)&dJunk, 32*(sizeof(int));
cudaMemset(dJunk, 0x12, 32);

will set all 32 integers to 0x12, not 0x12121212. (Int vs Byte)

The description talks about setting bytes. Count and Value are described in terms of bytes. Notice count is of type size_t, and value is of type int. i.e. Set a byte-size to an int-value.

cudaMemset() is not mentioned in the prog guide.
I have to assume the behavior I am seeing is correct, and the documentation is bad.

Is there a better documentation source out there? (Where?)
Are other types supported? i.e. Would float *dJunk; work? Others?

  • 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-14T23:13:27+00:00Added an answer on June 14, 2026 at 11:13 pm

    The documentation is correct, and your interpretation of what cudaMemset does is wrong. The function really does set byte values. Your example sets the first 32 bytes to 0x12, not all 32 integers to 0x12, viz:

    #include <cstdio>
    
    int main(void)
    {
        const int n = 32;
        const size_t sz = size_t(n) * sizeof(int);
        int *dJunk;
        cudaMalloc((void**)&dJunk, sz);
        cudaMemset(dJunk, 0, sz);
        cudaMemset(dJunk, 0x12, 32);
    
        int *Junk = new int[n];
    
        cudaMemcpy(Junk, dJunk, sz, cudaMemcpyDeviceToHost);
    
        for(int i=0; i<n; i++) {
            fprintf(stdout, "%d %x\n", i, Junk[i]);
        }
    
        cudaDeviceReset();
        return 0;
    }
    

    produces

    $ nvcc memset.cu 
    $ ./a.out 
    
    0 12121212
    1 12121212
    2 12121212
    3 12121212
    4 12121212
    5 12121212
    6 12121212
    7 12121212
    8 0
    9 0
    10 0
    11 0
    12 0
    13 0
    14 0
    15 0
    16 0
    17 0
    18 0
    19 0
    20 0
    21 0
    22 0
    23 0
    24 0
    25 0
    26 0
    27 0
    28 0
    29 0
    30 0
    31 0
    

    ie. all 128 bytes set to 0, then first 32 bytes set to 0x12. Exactly as described by the documentation.

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

Sidebar

Related Questions

I'm wondering how Android's implementation of SQLite handles long Strings. Reading from online documentation
The documentation online implies that data can be downloaded from the development server (just
I have this old question but no answer works for me from online, the
From the online bar chart guide : qplot(factor(cyl), data=mtcars, geom=bar, fill=factor(gear)) How do I
So I know from various online sources that it is generally a no-no to
I am learning object orientated programming from the online Stanford courses there is a
My list view is parsed from a online resource, but i cant get the
I'm downloading the images from the online image for cache when offline. When I
Recently I developed a piece of software that downloads logfiles from our online production
I've been trying to implement a bash script that reads from wordnet's online database

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.