我正嘗試使用CHOLMOD
和SuiteSparse 4.4.4
中的CUDA
加速。我根據用戶指南進行編譯,我可以在Demo
文件夾下成功運行gpu.sh
,這表明GPU正在完成部分工作。但是,當我嘗試使用CHOLMOD
來運行我自己的代碼時,我發現GPU調用的數量始終爲0.我將Common->useGPU
設置爲1,環境變量CHOLMOD_USE_GPU
也設置爲1.我的Makefile如下所示。庫路徑是正確的。對我有何建議?不能在我自己的代碼中使用帶有CUDA加速的CHOLMOD
其實我應該提到我只是運行一個最簡單的測試用例來解決線性系統問題。
我試過了UF Sparse Matrix Collection的幾個矩陣,但nvprof
顯示沒有CUDA
應用程序被剖析。
一些我試過矩陣:
bmw7st_1:http://www.cise.ufl.edu/research/sparse/matrices/GHS_psdef/bmw7st_1.html
nd6k: http://www.cise.ufl.edu/research/sparse/matrices/ND/nd6k.html
nd24k: http://www.cise.ufl.edu/research/sparse/matrices/ND/nd24k.html
代碼:
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#include <sys/time.h>
#include "cholmod.h"
int main (void)
{
struct timeval t1, t2;
double elapsedTime;
const char* matFile = "../bmw7st_1.mtx";
FILE* fp = fopen(matFile, "r");
assert(fp != NULL);
cholmod_sparse *A ;
cholmod_dense *x, *b;
cholmod_factor *L ;
cholmod_common* c = (cholmod_common*)malloc(sizeof(cholmod_common));
cholmod_start (c) ; /* start CHOLMOD */
c->useGPU = 1;
c->supernodal = CHOLMOD_SUPERNODAL;
A = cholmod_read_sparse (fp, c) ; /* read in a matrix */
cholmod_print_sparse (A, "A", c) ; /* print the matrix */
fclose(fp);
if (A == NULL || A->stype == 0) /* A must be symmetric */
{
cholmod_free_sparse (&A, c) ;
cholmod_finish (c) ;
return (0) ;
}
b = cholmod_ones (A->nrow, 1, A->xtype, c) ; /* b = ones(n,1) */
gettimeofday(&t1, NULL);
L = cholmod_analyze (A, c) ; /* analyze */
cholmod_factorize (A, L, c) ; /* factorize */
x = cholmod_solve (CHOLMOD_A, L, b, c) ; /* solve Ax=b */
gettimeofday(&t2, NULL);
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
elapsedTime += (t2.tv_usec - t1.tv_usec)/1000.0;
printf("Time: %.4f ms\n", elapsedTime);
cholmod_free_factor (&L, c) ; /* free matrices */
cholmod_free_sparse (&A, c) ;
cholmod_free_dense (&x, c) ;
cholmod_free_dense (&b, c) ;
cholmod_finish (c) ; /* finish CHOLMOD */
return (0) ;
}
生成文件:
CC = gcc
CFLAGS = -g -Wall -O2 \
-lrt -lgfortran \
-gdwarf-2
LIBS = $(CHOLMOD)/Lib/libcholmod.a \
$(AMD)/Lib/libamd.a \
$(COLAMD)/Lib/libcolamd.a \
$(LAPACK)/liblapack.a \
$(OPENBLAS)/lib/libopenblas.so \
$(XERBLA)/libcerbla.a \
$(METIS)/libmetis.a \
$(CAMD)/Lib/libcamd.a \
$(CCOLAMD)/Lib/libccolamd.a \
$(SUITESPARSE)/SuiteSparse_config/libsuitesparseconfig.a \
$(CUDART_LIB) \
$(CUBLAS_LIB)
HEADER_DIR = $(CHOLMOD)/Include
CONFIG_HEADER_DIR = $(SUITESPARSE)/SuiteSparse_config
OBJ_DIR = .
BIN_DIR = .
INCLUDES = -I$(HEADER_DIR) \
-I$(CONFIG_HEADER_DIR)
SRCS = $(shell ls *.c)
OBJS = $(SRCS:.c=.o)
OBJS_BUILD = $(shell ls $(OBJ_DIR)/*.o)
APP = prog
RM = rm -f
all: $(APP)
$(APP): $(OBJS)
$(CC) $(CFLAGS) -o $(BIN_DIR)/$(APP) $(OBJS_BUILD) $(LIBS)
%.o: %.c $(HEADER_DIR)/*.h $(CONFIG_HEADER_DIR)/*.h
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $(OBJ_DIR)/[email protected]
clean:
$(RM) $(OBJS_BUILD) $(APP)
實際上你應該提供一個完整的測試用例,而不僅僅是一個makefile。 –
@RobertCrovella對不起,添加了測試用例。 –
好吧,我想沒有矩陣文件的話,沒人會嘗試你的測試用例。你可以使用某人可以抓取的標準矩陣文件嗎?矩陣有多大?我很確定CHOLMOD(即SuiteSparse)能夠對是否使用GPU做出明智的決定。小型測試用例可能不會使用GPU。 –