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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:22:57+00:00 2026-05-25T14:22:57+00:00

I have made a Simple CUDA dll the code which I am displaying below.

  • 0

I have made a Simple CUDA dll the code which I am displaying below. The function adds some value to an array.

#include<stdio.h>
#include<stdlib.h>
#include<cuda.h>

//Cuda Kernel
__global__ void add_gpu(float *a)
{
int idx=blockIdx.x*blockDim.x+threadIdx.x;
a[idx]=a[idx]*2;
}


int cudasafe( cudaError_t error)
{
    if(error!=cudaSuccess) 
return 1;
else
return 0;
}


 extern "C" int __declspec(dllexport) __stdcall add_gpu_cu(float *a, int size,int    nblock, int nthread)
{

float* dev_a;
int flag;
flag=cudasafe(cudaMalloc((void**)&dev_a,size*sizeof(float)));
if(flag==1)
    return flag;
flag=cudasafe(cudaMemcpy(dev_a,a,size*sizeof(float),cudaMemcpyHostToDevice));
if(flag==1)
    return flag;
add_gpu<<<10,10>>>(dev_a);
flag=cudasafe(cudaMemcpy(a,dev_a,size*sizeof(float),cudaMemcpyDeviceToHost));
if(flag==1)
    return flag;
  }

The problem is I cant add the dll created as a reference to my c# project. It throws up an exception saying a reference to the file could not be added. Make sure the file is accessible, and that its a valid assembly or COM component.

Am i doing something wrong in creating the dll?

Please help

Regards

  • 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-25T14:22:57+00:00Added an answer on May 25, 2026 at 2:22 pm

    No, the DLL is a C++ DLL, and not a .NET DLL, so you can’t add a reference to it. You need to use interop to use it in C#.

    To do so, you need to include a .DEF file in your DLL (or the __declspec) to make the function exportable, then declare the definition in C# along the lines of:

    [DllImport("your_dll_name")]  public static extern int add_gpu_cu(IntPtr a, int size, int nblock, int ntrheac);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning java and I have made simple program that simply reads value from
So I have made this simple interface: package{ public interface GraphADT{ function addNode(newNode:Node):Boolean; }
I'm trying to disassemble a C/C++ DLL, and have made some progress, but I
i have made a very simple labview VI which has an activeX component in
I have made a simple installer application in Delphi, nothing fancy. Basically I include
I have made a simple script application which accepts radius as input from user
I have made a simple test application for the issue, two winforms each containing
I have made my own file type (.ddd) and I made a simple program
I have started using jQuery and rails. I have made a simple form that
I'm just playing around with WPF and MVVM, and I have made a simple

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.