Hi all,
I have been working on this code for 2 days. I have tried everything I can, but still have the same error. At first I thought it is because I used global vars, but now I have moved all of them to function parameters. The problem still cannot be solved. Could you please help :[ ~~
The error I got:
Error 1 error LNK2019: unresolved external symbol __Znaj referenced in function _Z5runSWPcS SW2D.obj
Error 2 fatal error LNK1120: 1 unresolved externals …/…/bin/win32/Debug/SW2D.exe
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cutil.h>
// includes, kernels
#include <SW2D_kernel.cu>
#include <SM2D.h>
////////////////////////////////////////////////////////////////////////////////
// declaration, forward
/*struct matrix
{
int **p;
int row;
int cols;
};
*/
int getAntiDiagnolSize(int,int,int);
char *getAntiDiagnolArray(int,int,int,int distance[MAXLENGTH][MAXLENGTH]);
//void UpdateMatrix(int,char*,int,int,int,int,int distance[MAXLENGTH][MAXLENGTH],int trace[MAXLENGTH][MAXLENGTH]);
void TraceBack(char*,char*,int,int,int,int,int trace[MAXLENGTH][MAXLENGTH]);
void runSW(char*,char*);
//matrix* func_struc(int,int);
int main(int,char**);
////////////////////////////////////////////////////
//Program main
int main(int argc, char** argv){
//printf("Target DNA: %s\n",Y);
//printf("Query DNA: %s\n\n", X);
char Y[MAXLENGTH];
char X[MAXLENGTH];
printf("Enter the target DNA sequence :");
scanf("%c",&Y);
printf("\nEnter the query DNA sequence :");
scanf("%c",&X);
runSW(X,Y);
CUT_EXIT(argc, argv);
}
////////////////////////////////////////////////////
////////////////////////////////////////////////////
void runSW(char* X,char* Y){
/* check how long Y is */
int n=0;
while(Y[n] != 0) n++;
/* check length of X */
int m=0;
while(X[m] != 0) m++;
int i=0,j=0;
int minMN = min(m,n);
int distance[MAXLENGTH][MAXLENGTH],trace[MAXLENGTH][MAXLENGTH];
//matrix *distance1=func_struc(n,m),*trace1=func_struc(n,m);
int gMaxValue[3],hMaxValue[3];
unsigned int hTimer;
double timerValue;
const int DATA_N = 100000000;
const int DATA_SIZE = DATA_N * sizeof(unsigned char);
CUT_DEVICE_INIT();
CUT_SAFE_CALL( cutCreateTimer(&hTimer) );
m=(m==0?1:m);
n=(n==0?1:n);
char* gX = new char[m];
char* gY = new char[n];
int maxI=0,maxJ=0,maxValue=0;
printf("Allocating GPU memory for two DNA sequence arrays...\n");
CUDA_SAFE_CALL(cudaMalloc((void**)&gX,sizeof(char)*m));
CUDA_SAFE_CALL(cudaMalloc((void**)&gY,sizeof(char)*n));
printf("Copying these two DNA sequence arrays to GPU memory...\n");
CUDA_SAFE_CALL(cudaMemcpy(gX,X,sizeof(char)*m,cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpy(gY,Y,sizeof(char)*n,cudaMemcpyHostToDevice));
printf("Starting running calculations on GPU recursively...\n");
/* CPU control the loop for GPU */
for(i=0; i<m+n-1; i++){
int size = 0;
printf(" Preparing k-2 diagonal array...\n");
//Prepare 'a' array for input,size is the length of k-2 anti-diagonal
size = getAntiDiagnolSize(i-2,m,n);
int x = size;
// put the values to a
char* a = new char;
a = getAntiDiagnolArray(i-2,m,n,distance);
char* aD = new char;
size = size*sizeof(char);
CUDA_SAFE_CALL(cudaMalloc((void**)&aD, size));
CUDA_SAFE_CALL(cudaMemcpy(aD,a,size,cudaMemcpyHostToDevice));
printf(" Preparing k-1 diagonal array...\n");
//Prepare 'b' array for input, size is the length of k-1 anti-diagonal
size = getAntiDiagnolSize(i-1,m,n);
int y = size;
// put the values to b
char* b = new char;
b = getAntiDiagnolArray(i-1,m,n,distance);
char* bD = new char;
size = size*sizeof(char);
CUDA_SAFE_CALL(cudaMalloc((void**)&bD,size));
CUDA_SAFE_CALL(cudaMemcpy(bD,b,size,cudaMemcpyHostToDevice));
printf(" Preparing k diagonal array...\n");
/*
Prepare 'c' array for input, c is a 1D array, which the 1st 'size' number of elements
are the score, the 2nd 'size' number of elements are the direction, size is the length of k anti-diagonal
*/
size = getAntiDiagnolSize(i,m,n);
int z = size;
char* c = new char;
for(i=0; i<size*2; i++){
c[i] = '0';
}
char* cD = new char;
CUDA_SAFE_CALL(cudaMalloc((void**)&cD,size*sizeof(char)*2));
CUDA_SAFE_CALL(cudaMemcpy(cD,c,size*2,cudaMemcpyHostToDevice));
printf(" Preparing maximum value, maxI & maxJ...\n");
hMaxValue[0] = maxValue;
hMaxValue[1] = maxI;
hMaxValue[2] = maxJ;
CUDA_SAFE_CALL(cudaMalloc((void**)&gMaxValue,sizeof(int)*3));
// CUDA_SAFE_CALL(cudaMemcpyToSymbol(gMaxValue,hMaxValue,sizeof(int)*3));
CUDA_SAFE_CALL(cudaMemcpy(gMaxValue,hMaxValue,sizeof(hMaxValue),cudaMemcpyHostToDevice));
// CUDA_SAFE_CALL(cudaMemcpy(gMaxI,maxI,sizeof(maxI),cudaMemcpyHostToDevice));
// CUDA_SAFE_CALL(cudaMemcpy(gMaxJ,maxJ,sizeof(maxJ),cudaMemcpyHostToDevice));
dim3 dimBlock(BLOCK_SIZE);
dim3 dimGrid(size/BLOCK_SIZE);
CUT_SAFE_CALL( cutStartTimer(hTimer) );
printf(" Call GPU to calculate one anti-diagonal values...\n");
//SWOnDevice<<<dimGrid,dimBlock>>>(aD,x,bD,y,cD,z,i,m,n,gX,gY);
SWOnDevice<<<dimGrid,dimBlock>>>(aD,x,bD,y,cD,z,i,m,n,gX,gY,gMaxValue);
CUT_SAFE_CALL( cutStopTimer(hTimer) );
timerValue = cutGetTimerValue(hTimer);
printf(" gpu() time : %f msec //%f MB/sec\n", timerValue, DATA_SIZE / (1048576.0 * timerValue * 0.001));
printf(" Copy k diagonal, maxValue, maxI & maxJ back to CPU...\n");
CUDA_SAFE_CALL(cudaMemcpy(c,cD, size*2, cudaMemcpyHostToDevice));
CUDA_SAFE_CALL(cudaMemcpy(hMaxValue, gMaxValue, sizeof(gMaxValue), cudaMemcpyHostToDevice));
printf(" Update distance and trace matrixs...\n");
if(0<=i<minMN){
for(j=0;j<size;j++){
distance[minMN-1-j][j] = c[j];
trace[minMN-size-j][j] = c;
}
}else if(minMN<=i<m+n-1){
if(m<=n){
for(j=0;j<size;j++) {
distance[minMN-j-1][i-minMN+i+1] = c[j];
trace[minMN-j-1][i-minMN+j+1] = c;
}
}else for(j=0;j<size;j++){
distance[i-j][j] = c[j];
trace[minMN-j-1][j] = c[i*2+i];
}
}
printf(" Free memories of three arrays in GPU...\n");
cudaFree(aD);
cudaFree(bD);
cudaFree(cD);
printf("-------------------------------------------------\n");
}
printf("Trace back trace matrix...\n");
TraceBack(X,Y,m,n,hMaxValue[1],hMaxValue[2],trace);
}
int getAntiDiagnolSize(int position,int m,int n){
int size = 0;
int minMN = min(m,n);
int maxMN = max(m,n);
if(position==-2) size=1;
else if(position==-1) size=2;
else if(position>=0){
if(position<minMN) size = position+1;
else if(position>m+n-minMN-1)
//size = maxMN-distMN-(position-minMN);
size = m+n-1-position;
else size = maxMN-maxMN+minMN;
}
return size;
}
char *getAntiDiagnolArray(int loop,int m,int n,int distance[MAXLENGTH][MAXLENGTH]){
int i=0;
int minMN = min(m,n);
int l = getAntiDiagnolSize(loop,m,n);
char *res = new char[l];
if(loop==-2) res[0] = 0;
else if(loop==-1) res[0]=res[1]=0;
else if(loop>=0){
if(loop<minMN){
for(i=0;i<l;i++){
res[i] = distance[minMN-1-i][i];
}
}else if(minMN<=loop<m+n-1){
if(m<=n){
for(i=0;i<l;i++) res[i]=distance[minMN-i-1][loop-minMN+i+1];
}else
for(i=0;i<l;i++) res[i]=distance[loop-i][i];
}
}
return res;
}
Thousands of thanks!!!