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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:25:08+00:00 2026-05-27T16:25:08+00:00

I am using Cuda SDK 4.0 and am encountering an issue which has taken

  • 0

I am using Cuda SDK 4.0 and am encountering an issue which has taken me 2 days to whittle down into the following code.

#include <cuda.h>
#include <cuda_runtime.h>
void main (int argc, char ** argv) {

    int* test;
    cudaError_t err;

    err = cudaSetDevice(   1   ); err = cudaMallocHost(&test, 1024*sizeof(int));    
    err = cudaSetDevice(   0   ); err = cudaFreeHost(test);    
} 

This throws the following error when calling cudaFreeHost:

First-chance exception at 0x000007fefd96aa7d in Test.exe: Microsoft C++ exception: cudaError_enum at memory location 0x0022f958..

The err value is cudaErrorInvalidValue

The same error occurs for this variation:

err = cudaSetDevice(   0   ); err = cudaMallocHost(&test, 1024*sizeof(int));    
err = cudaSetDevice(   1   ); err = cudaFreeHost(test);

The following variations dont throw the error:

err = cudaSetDevice(   0   ); err = cudaMallocHost(&test, 1024*sizeof(int));    
err = cudaSetDevice(   0   ); err = cudaFreeHost(test);

and

err = cudaSetDevice(   1   ); err = cudaMallocHost(&test, 1024*sizeof(int));    
err = cudaSetDevice(   1   ); err = cudaFreeHost(test);

I was under the impression you only needed to call cudaSetDevice if you want to allocate memory on a specific GPU. In the above example I am only allocating pinned memory on the CPU.

Is this a bug or did I miss something in the manual?

  • 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-27T16:25:09+00:00Added an answer on May 27, 2026 at 4:25 pm

    I found the problem. cudaHostAlloc and cudaMallocHost ARE NOT THE SAME.

    For anyone who encounters this problem the solution is to use

    cudaHostAlloc(&test, 1024*sizeof(int),cudaHostAllocPortable);
    

    instead of

    cudaMallocHost(&test, 1024*sizeof(int));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the CUDA .rules file which comes with the CUDA SDK for custom
I am using Tesla C2050, which has a compute capability 2.0 and has 48KB
I'm going to attempt to optimize some code written in MATLAB, by using CUDA.
I am a CUDA beginner who has successfully compiled and run several code samples
I want to manipulate a texture which I use in opengl using CUDA. Knowing
I'm trying to compile a code written using CUDA 3.2 on RHEL 5.6. The
Is someone aware of a method to highlight CUDA code while using Qt Creator?
I'm using a custom random number function rand48 in CUDA. The function does not
I'm attempting to install the following Haskell package on Windows using Cygwin: HaskellCuda You
I am interested in using CUDA to program a multi-GPU application. As far as

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.