CUDA和LAPACK混編的MakeFile檔案
阿新 • • 發佈:2019-01-09
最近在寫CUDA和LAPACK混編的程式,貼出Makefile檔案和源程式檔案,供大家參考。
Makefile檔案
# Makefile for GPU program based on SU
# Home path
SU_HOME = /home/ry/su
SU_HOME1 = /home/ry/su/src/Complex
MPI_HOME = /home/ry/openmpi
CUDA_HOME = /home/ry/cuda9
LAPACK_HOME = /home/ry/Lapack/lapack-3.8.0
# CLAPACK_HOME = /home/ry/Clapack/CLAPAC
# Which compiler
NVCC = nvcc
# Include path
CFLAGS = -I$(SU_HOME)/include -I$(SU_HOME1)/include -I$(MPI_HOME)/include \
-I$(CUDA_HOME)/include -I$(LAPACK_HOME)/LAPACKE/include \
-I$(CLAPACK_HOME)/INCLUDE
# Lib path
LFLAGS = -L$(SU_HOME)/lib -L$(SU_HOME1)/lib -L$(MPI_HOME)/lib \
-L$(CUDA_HOME)/lib64
LD = -lsu -lpar -lcwp -lm -lcublas -lcurand -lcufft -lcusparse -llapack
CU_APPS= lapack_test
all: ${CU_APPS}
%: %.cu
-$(NVCC) -O2 -arch=sm_35 $(@F).cu -o [email protected] $(LD) $(LFLAGS) $(CFLAGS)
clean:
rm -f ${CU_APPS}
源程式檔案
#include "./common.h"
#include <stdio.h>
#include <stdlib.h>
#include <cusparse_v2.h>
#include <cusparse.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>
#include "time.h"
#include "par.h"
#include "su.h"
#include "segy.h"
#include "lapacke.h"
extern lapack_int LAPACKE_dgesv( int matrix_order, lapack_int n, lapack_int nrhs,
double* a, lapack_int lda, lapack_int* ipiv,
double* b, lapack_int ldb );
extern lapack_int LAPACKE_dgetrf(int nx, int nz );
int main(int argc, char **argv)
{
int A[5][5] = {3,2,0,1,0,
2,3,2,0,1,
0,2,3,2,0,
1,0,2,3,2,
0,1,0,2,3};
int nx;
int nz;
nx=5;
nz=5;
return 0;
}