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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:39:21+00:00 2026-06-12T16:39:21+00:00

I made a Dll file in visual C++ to compute modulus of an array

  • 0

I made a Dll file in visual C++ to compute modulus of an array of complex numbers in CUDA. The array is type of cufftComplex. I then called the Dll in LabVIEW to check the accuracy of the result. I’m receiving an incorrect result. Could anyone tell me what is wrong with the following code, please? I think there should be something wrong with my kernel function(the way I am retrieving the cufftComplex data should be incorrect).

#include <math.h>
#include <cstdlib>
#include <cuda_runtime.h>
#include <cufft.h>

extern "C" __declspec(dllexport) void Modulus(cufftComplex *digits,float *result);


__global__ void ModulusComputation(cufftComplex *a, int N, float *temp)
{
  int idx = blockIdx.x*blockDim.x + threadIdx.x;
  if (idx<N) 
    { 
      temp[idx] = sqrt((a[idx].x * a[idx].x) + (a[idx].y * a[idx].y));
    }

}



void Modulus(cufftComplex *digits,float *result)
{
  #define N 1024
  cufftComplex *d_data;
  float *temp;

  size_t size = sizeof(cufftComplex)*N;

  cudaMalloc((void**)&d_data, size);
  cudaMalloc((void**)&temp, sizeof(float)*N);

  cudaMemcpy(d_data, digits, size, cudaMemcpyHostToDevice);

  int blockSize = 16;
  int nBlocks = N/blockSize;
  if( N % blockSize != 0 )
      nBlocks++;

  ModulusComputation <<< nBlocks, blockSize >>> (d_data, N,temp);

  cudaMemcpy(result, temp, size, cudaMemcpyDeviceToHost);

  cudaFree(d_data);
  cudaFree(temp);

}
  • 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-12T16:39:22+00:00Added an answer on June 12, 2026 at 4:39 pm

    In the final cudaMemcpy in your code, you have:

     cudaMemcpy(result, temp, size, cudaMemcpyDeviceToHost); 
    

    It should be:

     cudaMemcpy(result, temp, sizeof(float)*N, cudaMemcpyDeviceToHost); 
    

    If you had included error checking for your cuda calls, you would have seen this cuda call (as originally written) throw an error.

    There’s other comments that could be made. For example your block size (16) should be an integral multiple of 32. But this does not prevent proper operation.

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

Sidebar

Related Questions

I made a dynamic library with compiled headers and compiled a DLL (using Visual
I made a dll in c# but i need to export the functions. Is
So I have made a .dll containing some methods that I wish to use
I have a DLL made in C#, this DLL contains some clases like Creator.
Here's my problem: I have an unmanaged dll that I made.I'm calling one of
How can I pass arguments to my lua dll function? I made a simple
Made a custom obj called Item with some string fields and one float. .h
I made an application that passes trough an XML file and extracts the entries
I encountered a strange issue while coding a .dll file in C with gcc
I have made an addin for Microsoft Word 2010 Beta using Visual Studio 2010

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.