小编joã*_*.f.的帖子

在Delphi程序中使用CUDA调用运行C函数

我的目标是有一个Delphi(或freepascal)代码,它将像这样调用C函数func:

C/Cuda文件:

/* this is the "progcuda.cu" file */
#include <stdio.h>

__global__ void foo(int *a, int *b, int *c, int n){
    /*
    add all the vector's element
    */
}


void func(int *a, int *b, int *c,int n){
    int *da,*db,*dc;
    cudaMalloc(&da, n*sizeof(int));
    cudaMalloc(&db, n*sizeof(int));
    cudaMalloc(&dc, n*sizeof(int));

    cudaMemcpy(da,a,sizeof(int)*n,cudaMemcpyHostToDevice);
    cudaMemcpy(db,b,sizeof(int)*n,cudaMemcpyHostToDevice);
    cudaMemcpy(dc,c,sizeof(int)*n,cudaMemcpyHostToDevice);

    foo<<<1,256>>>(da,db,dc);
    cudaMemcpy(c,dc,sizeof(int),cudaMemcpyDeviceToHost);

    /* do other stuff and call another Host and Device functions*/

    return;
}
Run Code Online (Sandbox Code Playgroud)

pascal主文件:

// this is the "progpas.pas" file
program progpas;
{$mode objfpc}{$H+}
uses unitpas;

var
    ... …
Run Code Online (Sandbox Code Playgroud)

c cuda freepascal

3
推荐指数
1
解决办法
388
查看次数

标签 统计

c ×1

cuda ×1

freepascal ×1