我是 打开cmd窗口——》 nvcc 代码文件 ——》出现了无法解析的外部符号,我是一个新手,目前不知道怎么解决,求助各位大佬,谢谢大家!!!
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include “cublas.h”
#include “cuda_runtime.h”
#include “cublas_v2.h”
#define DATA_SIZE 16
void InitVector(float* vec, int n, int down, int up)
{
int i;
srand((unsigned int)time(NULL));
for (i = 0; i < n; i++)
{
vec[i] = (float)(rand() % (up - down + 1) + down);
}
return;
}
void myIsamax(int n, float* x, int incx, int* result)
{
int i = 0;
result = 0;
for (i = 1; i < n; i += incx)
{
if (x[i] > x[result]) result = i;
}
}
int main(int argc, char argv)
{
cublasHandle_t cubhandle;
float h_datax, * h_datax2, * h_datax3, * h_datax4;
float* d_datax, * d_datax2, * d_datax3, * d_datax4;
int h_result;
int d_result1, d_result2;
float d_result3, d_result4, d_result5, d_result6, d_result7, d_result8, d_result9;
int data_size = DATA_SIZE;
float alpha = 2.0;
cublasCreate(&cubhandle);
h_datax = (float*)malloc(data_size * sizeof(float)); h_datax2 = (float*)malloc(data_size * sizeof(float)); h_datax3 = (float*)malloc(data_size * sizeof(float)); h_datax4 = (float*)malloc(data_size * sizeof(float));
cudaMalloc((void**)&d_datax, data_size * sizeof(float)); cudaMalloc((void**)&d_datax2, data_size * sizeof(float)); cudaMalloc((void**)&d_datax3, data_size * sizeof(float)); cudaMalloc((void**)&d_datax4, data_size * sizeof(float));
InitVector(h_datax, data_size, 0, 100); InitVector(h_datax2, data_size, 0, 10);
for (int i = 0; i < data_size; i++) {
printf("%4.1f ", h_datax[i]);
}
printf("\n");
for (int i = 0; i < data_size; i++) {
printf("%4.1f ", h_datax2[i]);
}
cublasSetVector(data_size, sizeof(float), h_datax, 1, d_datax, 1); cublasSetVector(data_size, sizeof(float), h_datax2, 1, d_datax2, 1);
cublasSasum(cubhandle, data_size, d_datax2, 1, &d_result4);printf("\ndevice : d_datax2sum=%.2f", d_result4);
cublasIsamax(cubhandle, data_size, d_datax, 1, &d_result1);
cublasIsamin(cubhandle, data_size, d_datax, 1, &d_result2);
cublasSasum(cubhandle, data_size, d_datax, 1, &d_result3);
cublasSdot(cubhandle, data_size, d_datax, 1, d_datax2, 1, &d_result6);
cublasSnrm2(cubhandle, data_size, d_datax2, 1, &d_result7);
cublasSaxpy(cubhandle, data_size, &alpha, d_datax, 1, d_datax2, 1);
cublasSasum(cubhandle, data_size, d_datax2, 1, &d_result5);
cublasScopy(cubhandle, data_size, d_datax, 1, d_datax3, 1);
cublasScopy(cubhandle, data_size, d_datax, 1, d_datax4, 1);
cublasSscal(cubhandle, data_size, &alpha, d_datax4, 1);
cublasGetVector(data_size,sizeof(float),d_datax3,1,h_datax3,1); cublasGetVector(data_size, sizeof(float), d_datax4, 1, h_datax4, 1);
myIsamax(data_size, h_datax, 1, &h_result);
printf("\nhost : h_dataxmax[%2d]=%.2f", h_result, h_datax[h_result]);
printf("\ndevice : d_dataxmax[%2d]=%.2f", d_result1 - 1, h_datax[d_result1 - 1]);
printf("\ndevice : d_dataxmin[%2d]=%.2f", d_result2 - 1, h_datax[d_result2 - 1]);
printf("\ndevice : d_dataxsum=%.2f", d_result3);
printf("\ndevice : d_datax2sum=%.2f", d_result5);
printf("\ndevice : d_dataxdot=%.2f", d_result6);
printf("\ndevice : d_datax2nrm=%.2f", d_result7);
printf("\ndevice: d_datax3\n");
for (int i = 0; i < data_size; i++) {
printf("%4.1f ", h_datax3[i]);
}
printf("\ndevice: d_datax4\n");
for (int i = 0; i < data_size; i++) {
printf("%4.1f ", h_datax4[i]);
}
cublasSswap(cubhandle, data_size, d_datax3, 1, d_datax4, 1);
cublasGetVector(data_size, sizeof(float), d_datax3, 1, h_datax3, 1); cublasGetVector(data_size, sizeof(float), d_datax4, 1, h_datax4, 1);
printf("\nswapdevice: d_datax3\n");
for (int i = 0; i < data_size; i++) {
printf("%4.1f ", h_datax3[i]);
}
printf("\nswapdevice: d_datax4\n");
for (int i = 0; i < data_size; i++) {
printf("%4.1f ", h_datax4[i]);
}
free(h_datax); h_datax = 0x0;
cudaFree(d_datax); d_datax = 0x0;
cublasDestroy(cubhandle);
return 0;
}