Ich brauche Call C-Funktion in Cuda (. Cu) -Datei von C-Datei (. C) gestellt. Ich habe eine Hierarchie, die so aussieht.Wie C-Funktion aufgerufen wird, die in .cu-Datei aus c-Datei platziert wird?
main.c
#include <stdio.h>
#include "dbgHelpers.h"
#include "arffReader.h"
#include "CPU_k_means.h"
#include "CUDA_k_means.h"
#include "defines.h"
int main() {
//actions
uint cudaTime = runCudaKMeans(h_objects, objectsNum, parametersNum, clustersNum, repeatesNum, streamsNum);
//actions
return 0;
}
CUDA_k_means.cu
#include "CUDA_k_means.h"
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
extern "C" {
#include "dbgHelpers.h"
}
__constant__ uint d_CLUST_NUM;
__constant__ uint d_OBJ_NUM;
__constant__ uint d_PARAMS_NUM;
__constant__ uint d_OBJ_PER_STREAM;
__constant__ uint d_OBJ_FOR_LAST_STREAM;
extern __shared__ uint sharedData[];
__global__ void calcDistances(ptype* d_objects, ptype* d_clustersCenters, ptype* d_distances)
{
//algorithm
}
__global__ void clusterize(ptype* d_distances, uint* d_clustersMap)
{
//algorithm
}
//and more kernels
uint runCudaKMeans(ptype* h_objects, uint objectsNum, uint parametersNum, uint clustersNum, uint repeatesNum, uint streamsNum) {
//algorithm
calcDistances<<32, 32>>();
//and so on
}
CUDA_k_means.h
#ifndef CUDA_K_MEANS_H_
#define CUDA_K_MEANS_H_
#include "defines.h"
uint runCudaKMeans(ptype* h_objects, uint objectsNum, uint parametersNum, uint clustersNum, uint repeatesNum, uint streamsNum);
#endif
Ich kann es nicht richtig verbinden. NSight gibt diesen Fehler zurück.
/usr/local/cuda-7.5/bin/nvcc --cudart static --relocatable-device-code=false -gencode arch=compute_20,code=compute_20 -gencode arch=compute_20,code=sm_21 -link -o "lab5" ./CPU_k_means.o ./CUDA_k_means.o ./arffReader.o ./dbgHelpers.o ./main.o
./main.o: In function `main':
main.c:(.text.startup+0x8c): undefined reference to `runCudaKMeans'
collect2: error: ld returned 1 exit status
make: *** [lab5] Error 1
Ich weiß nicht, was ich tun soll. Ich habe verschiedene Kombinationen von "extern C" ausprobiert, aber ohne Erfolg. Ist es überhaupt möglich?
Eine vollständige Erklärung finden Sie in der verknüpften Duplikat gefunden werden – talonmies