本文整理汇总了C++中cusparseCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ cusparseCreate函数的具体用法?C++ cusparseCreate怎么用?C++ cusparseCreate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cusparseCreate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: CUDA_CHECK
void Caffe::SetDevice(const int device_id) {
int current_device;
CUDA_CHECK(cudaGetDevice(¤t_device));
if (current_device == device_id) {
return;
}
// The call to cudaSetDevice must come before any calls to Get, which
// may perform initialization using the GPU.
CUDA_CHECK(cudaSetDevice(device_id));
if (Get().cublas_handle_) CUBLAS_CHECK(cublasDestroy(Get().cublas_handle_));
if (Get().cusparse_descr_)CUSPARSE_CHECK(cusparseDestroyMatDescr(Get().cusparse_descr_));
if (Get().cusparse_handle_)CUSPARSE_CHECK(cusparseDestroy(Get().cusparse_handle_));
if (Get().curand_generator_) {
CURAND_CHECK(curandDestroyGenerator(Get().curand_generator_));
}
CUSPARSE_CHECK(cusparseCreate(&Get().cusparse_handle_));
CUSPARSE_CHECK(cusparseCreateMatDescr(&Get().cusparse_descr_));
// cusparseSetMatType(cusparse_descr_,CUSPARSE_MATRIX_TYPE_GENERAL);
// cusparseSetMatIndexBase(cusparse_descr_,CUSPARSE_INDEX_BASE_ZERO);
LOG(INFO)<<"set descr";
CUBLAS_CHECK(cublasCreate(&Get().cublas_handle_));
CURAND_CHECK(curandCreateGenerator(&Get().curand_generator_,
CURAND_RNG_PSEUDO_DEFAULT));
CURAND_CHECK(curandSetPseudoRandomGeneratorSeed(Get().curand_generator_,
cluster_seedgen()));
}
开发者ID:ZhouYuSong,项目名称:caffe-pruned,代码行数:26,代码来源:common.cpp
示例2: fprintf
// initialize CUDA
ssp_cuda *ssp_init_cuda() {
ssp_cuda *cudaHandle = (ssp_cuda*)malloc(sizeof(ssp_cuda));
if (!cudaHandle) {
fprintf(stderr,"ssp_init_cuda: cudaHandle memory allocation failed.\n");
return NULL;
}
cudaHandle->cusparse_handle = 0;
cudaHandle->cusparse_matDescr = 0;
cusparseStatus_t status = cusparseCreate(&cudaHandle->cusparse_handle);
if (status != CUSPARSE_STATUS_SUCCESS) {
ssp_finalize_cuda(cudaHandle);
fprintf(stderr,"ssp_init_cuda: cusparse initialization failed.\n");
return NULL;
}
status = cusparseCreateMatDescr(&cudaHandle->cusparse_matDescr);
if (status != CUSPARSE_STATUS_SUCCESS) {
ssp_finalize_cuda(cudaHandle);
fprintf(stderr,"ssp_init_cuda: cusparse matrix setup failed.\n");
return NULL;
}
cusparseSetMatType(cudaHandle->cusparse_matDescr,CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(cudaHandle->cusparse_matDescr,CUSPARSE_INDEX_BASE_ZERO);
return cudaHandle;
}
开发者ID:nefan,项目名称:ssparse,代码行数:32,代码来源:ssp_cuda.cpp
示例3: CudaSparseSingleton
CudaSparseSingleton()
{
cusparseCreate( & handle );
cusparseCreateMatDescr( & descra );
cusparseSetMatType( descra , CUSPARSE_MATRIX_TYPE_GENERAL );
cusparseSetMatIndexBase( descra , CUSPARSE_INDEX_BASE_ZERO );
}
开发者ID:ProgramFan,项目名称:kokkos,代码行数:7,代码来源:SparseLinearSystem.hpp
示例4: cublas_handle_
Caffe::Caffe()
: cublas_handle_(NULL),cusparse_handle_(NULL),cusparse_descr_(NULL),curand_generator_(NULL),random_generator_(),mode_(Caffe::CPU), solver_count_(1), root_solver_(true){
// Try to create a cublas handler, and report an error if failed (but we will
// keep the program running as one might just want to run CPU code).
LOG(INFO)<<"caffe init.";
if (cublasCreate(&cublas_handle_) != CUBLAS_STATUS_SUCCESS) {
LOG(ERROR) << "Cannot create Cublas handle. Cublas won't be available.";
}
//add cusparse handler
if (cusparseCreate(&cusparse_handle_)!=CUSPARSE_STATUS_SUCCESS){
LOG(ERROR) << "cannot create Cusparse handle,Cusparse won't be available.";
}
if(cusparseCreateMatDescr(&cusparse_descr_)!=CUSPARSE_STATUS_SUCCESS){
LOG(ERROR) << "cannot create Cusparse descr,descr won't be available.";
}else{
cusparseSetMatType(cusparse_descr_,CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(cusparse_descr_,CUSPARSE_INDEX_BASE_ZERO);
LOG(INFO)<<"init descr";
}
// Try to create a curand handler.
if (curandCreateGenerator(&curand_generator_, CURAND_RNG_PSEUDO_DEFAULT)
!= CURAND_STATUS_SUCCESS ||
curandSetPseudoRandomGeneratorSeed(curand_generator_, cluster_seedgen())
!= CURAND_STATUS_SUCCESS) {
LOG(ERROR) << "Cannot create Curand generator. Curand won't be available.";
}
LOG(INFO)<<"caffe finish";
}
开发者ID:ZhouYuSong,项目名称:caffe-pruned,代码行数:28,代码来源:common.cpp
示例5: magma_dapplycuicc_l
magma_int_t
magma_dapplycuicc_l( magma_d_vector b, magma_d_vector *x,
magma_d_preconditioner *precond ){
double one = MAGMA_D_MAKE( 1.0, 0.0);
// CUSPARSE context //
cusparseHandle_t cusparseHandle;
cusparseStatus_t cusparseStatus;
cusparseStatus = cusparseCreate(&cusparseHandle);
if(cusparseStatus != 0) printf("error in Handle.\n");
cusparseMatDescr_t descrL;
cusparseStatus = cusparseCreateMatDescr(&descrL);
if(cusparseStatus != 0) printf("error in MatrDescr.\n");
cusparseStatus =
cusparseSetMatType(descrL,CUSPARSE_MATRIX_TYPE_TRIANGULAR);
if(cusparseStatus != 0) printf("error in MatrType.\n");
cusparseStatus =
cusparseSetMatDiagType (descrL, CUSPARSE_DIAG_TYPE_NON_UNIT);
if(cusparseStatus != 0) printf("error in DiagType.\n");
cusparseStatus =
cusparseSetMatFillMode(descrL,CUSPARSE_FILL_MODE_LOWER);
if(cusparseStatus != 0) printf("error in fillmode.\n");
cusparseStatus =
cusparseSetMatIndexBase(descrL,CUSPARSE_INDEX_BASE_ZERO);
if(cusparseStatus != 0) printf("error in IndexBase.\n");
// end CUSPARSE context //
cusparseStatus =
cusparseDcsrsv_solve( cusparseHandle,
CUSPARSE_OPERATION_NON_TRANSPOSE,
precond->M.num_rows, &one,
descrL,
precond->M.val,
precond->M.row,
precond->M.col,
precond->cuinfoL,
b.val,
x->val );
if(cusparseStatus != 0) printf("error in L triangular solve:%p.\n", precond->cuinfoL );
cusparseDestroyMatDescr( descrL );
cusparseDestroy( cusparseHandle );
magma_device_sync();
return MAGMA_SUCCESS;
}
开发者ID:XapaJIaMnu,项目名称:magma,代码行数:58,代码来源:dcuilu.cpp
示例6: handle
TxMatrixOptimizationDataCU::TxMatrixOptimizationDataCU()
: handle(0), matDescr(0), localMatrix(0), gsContext(0), f2c(0),
workvector(0) {
cusparseStatus_t err = cusparseCreate(&handle);
CHKCUSPARSEERR(err);
#ifndef HPCG_NOMPI
elementsToSend = 0;
#endif
}
开发者ID:NobodyInAmerica,项目名称:libTxHPCG,代码行数:9,代码来源:TxMatrixOptimizationDataCU.cpp
示例7: cuSparseHandleType
cuSparseHandleType(bool transposeA, bool transposeB){
cusparseStatus_t status;
status= cusparseCreate(&handle);
if (status != CUSPARSE_STATUS_SUCCESS) {
std::cerr << ("cusparseCreate ERROR") << std::endl;
return;
}
cusparseSetPointerMode(handle, CUSPARSE_POINTER_MODE_HOST);
if (transposeA){
transA = CUSPARSE_OPERATION_TRANSPOSE;
}
else {
transA = CUSPARSE_OPERATION_NON_TRANSPOSE;
}
if (transposeB){
transB = CUSPARSE_OPERATION_TRANSPOSE;
}
else {
transB = CUSPARSE_OPERATION_NON_TRANSPOSE;
}
status = cusparseCreateMatDescr(&a_descr);
if (status != CUSPARSE_STATUS_SUCCESS) {
std::cerr << "cusparseCreateMatDescr a_descr ERROR" << std::endl;
return;
}
cusparseSetMatType(a_descr,CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(a_descr,CUSPARSE_INDEX_BASE_ZERO);
status = cusparseCreateMatDescr(&b_descr);
if (status != CUSPARSE_STATUS_SUCCESS) {
std::cerr << ("cusparseCreateMatDescr b_descr ERROR") << std::endl;
return;
}
cusparseSetMatType(b_descr,CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(b_descr,CUSPARSE_INDEX_BASE_ZERO);
status = cusparseCreateMatDescr(&c_descr);
if (status != CUSPARSE_STATUS_SUCCESS) {
std::cerr << ("cusparseCreateMatDescr c_descr ERROR") << std::endl;
return;
}
cusparseSetMatType(c_descr,CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(c_descr,CUSPARSE_INDEX_BASE_ZERO);
}
开发者ID:crtrott,项目名称:Trilinos,代码行数:47,代码来源:KokkosKernels_SPGEMMHandle.hpp
示例8: CudaSparseSingleton
CudaSparseSingleton()
{
status = cusparseCreate(&handle);
if(status != CUSPARSE_STATUS_SUCCESS)
{
throw std::runtime_error( std::string("ERROR - CUSPARSE Library Initialization failed" ) );
}
status = cusparseCreateMatDescr(&descra);
if(status != CUSPARSE_STATUS_SUCCESS)
{
throw std::runtime_error( std::string("ERROR - CUSPARSE Library Matrix descriptor failed" ) );
}
cusparseSetMatType(descra , CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(descra , CUSPARSE_INDEX_BASE_ZERO);
}
开发者ID:gitter-badger,项目名称:quinoa,代码行数:17,代码来源:Stokhos_Cuda_CrsMatrix.hpp
示例9: cuda_safe_call
void cuda_running_configuration::update_parameters()
{
cuda_safe_call(cudaDriverGetVersion(&driver_version));
cuda_safe_call(cudaRuntimeGetVersion(&runtime_version));
int device_count;
cuda_safe_call(cudaGetDeviceCount(&device_count));
if (device_count <= 0)
throw neural_network_exception("No CUDA capable devices are found");
if (device_id >= device_count)
throw neural_network_exception((boost::format("Device ID %1% specified while %2% devices are available") % device_id % device_count).str());
cudaDeviceProp device_prop;
cuda_safe_call(cudaGetDeviceProperties(&device_prop, device_id));
device_name = device_prop.name;
compute_capability_major = device_prop.major;
compute_capability_minor = device_prop.minor;
clock_rate = device_prop.clockRate;
memory_clock_rate = device_prop.memoryClockRate;
memory_bus_width = device_prop.memoryBusWidth;
global_memory_size = device_prop.totalGlobalMem;
ecc_enabled = (device_prop.ECCEnabled != 0);
l2_cache_size = device_prop.l2CacheSize;
multiprocessor_count = device_prop.multiProcessorCount;
smem_per_block = device_prop.sharedMemPerBlock;
max_threads_per_multiprocessor = device_prop.maxThreadsPerMultiProcessor;
max_threads_per_block = device_prop.maxThreadsPerBlock;
for(int i = 0; i < sizeof(max_threads_dim) / sizeof(max_threads_dim[0]); ++i)
max_threads_dim[i] = device_prop.maxThreadsDim[i];
for(int i = 0; i < sizeof(max_grid_size) / sizeof(max_grid_size[0]); ++i)
max_grid_size[i] = device_prop.maxGridSize[i];
max_texture_1d_linear = device_prop.maxTexture1DLinear;
texture_alignment = device_prop.textureAlignment;
pci_bus_id = device_prop.pciBusID;
pci_device_id = device_prop.pciDeviceID;
#ifdef _WIN32
tcc_mode = (device_prop.tccDriver != 0);
#endif
cuda_safe_call(cudaSetDevice(device_id));
cublas_safe_call(cublasCreate(&cublas_handle));
cusparse_safe_call(cusparseCreate(&cusparse_handle));
}
开发者ID:yzxyzh,项目名称:nnForge,代码行数:46,代码来源:cuda_running_configuration.cpp
示例10: magma_capplycumicc_l
extern "C" magma_int_t
magma_capplycumicc_l(
magma_c_matrix b,
magma_c_matrix *x,
magma_c_preconditioner *precond,
magma_queue_t queue )
{
magma_int_t info = 0;
cusparseHandle_t cusparseHandle=NULL;
cusparseMatDescr_t descrL=NULL;
magmaFloatComplex one = MAGMA_C_MAKE( 1.0, 0.0);
// CUSPARSE context //
CHECK_CUSPARSE( cusparseCreate( &cusparseHandle ));
CHECK_CUSPARSE( cusparseSetStream( cusparseHandle, queue ));
CHECK_CUSPARSE( cusparseCreateMatDescr( &descrL ));
CHECK_CUSPARSE( cusparseSetMatType( descrL, CUSPARSE_MATRIX_TYPE_TRIANGULAR ));
CHECK_CUSPARSE( cusparseSetMatDiagType( descrL, CUSPARSE_DIAG_TYPE_NON_UNIT ));
CHECK_CUSPARSE( cusparseSetMatFillMode( descrL, CUSPARSE_FILL_MODE_LOWER ));
CHECK_CUSPARSE( cusparseSetMatIndexBase( descrL, CUSPARSE_INDEX_BASE_ZERO ));
CHECK_CUSPARSE( cusparseCcsrsm_solve( cusparseHandle,
CUSPARSE_OPERATION_NON_TRANSPOSE,
precond->M.num_rows,
b.num_rows*b.num_cols/precond->M.num_rows,
&one,
descrL,
precond->M.dval,
precond->M.drow,
precond->M.dcol,
precond->cuinfoL,
b.dval,
precond->M.num_rows,
x->dval,
precond->M.num_rows ));
magma_device_sync();
cleanup:
cusparseDestroyMatDescr( descrL );
cusparseDestroy( cusparseHandle );
return info;
}
开发者ID:cjy7117,项目名称:FT-MAGMA,代码行数:44,代码来源:ccumilu.cpp
示例11: cusparse_handle
inline cusparseHandle_t cusparse_handle(const command_queue &q) {
typedef std::shared_ptr<std::remove_pointer<cusparseHandle_t>::type> smart_handle;
typedef vex::detail::object_cache<vex::detail::index_by_context, smart_handle> cache_type;
static cache_type cache;
auto h = cache.find(q);
if (h == cache.end()) {
select_context(q);
cusparseHandle_t handle;
cuda_check( cusparseCreate(&handle) );
cuda_check( cusparseSetStream(handle, q.raw()) );
h = cache.insert(q, smart_handle(handle, detail::deleter()));
}
return h->second.get();
}
开发者ID:mariomulansky,项目名称:vexcl,代码行数:19,代码来源:cusparse.hpp
示例12: THCState_reserveDeviceSparseHandles
void THCState_reserveDeviceSparseHandles(THCState* state, int device, int numSparseHandles)
{
int prevDev = -1;
THCCudaResourcesPerDevice* res = THCState_getDeviceResourcePtr(state, device);
if (numSparseHandles <= res->numSparseHandles) {
return;
}
THCudaCheck(cudaGetDevice(&prevDev));
THCudaCheck(cudaSetDevice(device));
size_t size = numSparseHandles * sizeof(cusparseHandle_t);
cusparseHandle_t* handles = (cusparseHandle_t*) realloc(res->sparseHandles, size);
for (int i = res->numSparseHandles; i < numSparseHandles; ++i) {
handles[i] = NULL;
THCusparseCheck(cusparseCreate(&handles[i]));
}
res->sparseHandles = handles;
res->numSparseHandles = numSparseHandles;
THCudaCheck(cudaSetDevice(prevDev));
}
开发者ID:HustlehardInc,项目名称:pytorch,代码行数:22,代码来源:THCGeneral.cpp
示例13: main
int main(int argc, char **argv)
{
int N = 0, nz = 0, *I = NULL, *J = NULL;
float *val = NULL;
const float tol = 1e-5f;
const int max_iter = 10000;
float *x;
float *rhs;
float a, b, na, r0, r1;
float dot;
float *r, *p, *Ax;
int k;
float alpha, beta, alpham1;
printf("Starting [%s]...\n", sSDKname);
// This will pick the best possible CUDA capable device
cudaDeviceProp deviceProp;
int devID = findCudaDevice(argc, (const char **)argv);
checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID));
#if defined(__APPLE__) || defined(MACOSX)
fprintf(stderr, "Unified Memory not currently supported on OS X\n");
cudaDeviceReset();
exit(EXIT_WAIVED);
#endif
if (sizeof(void *) != 8)
{
fprintf(stderr, "Unified Memory requires compiling for a 64-bit system.\n");
cudaDeviceReset();
exit(EXIT_WAIVED);
}
if (((deviceProp.major << 4) + deviceProp.minor) < 0x30)
{
fprintf(stderr, "%s requires Compute Capability of SM 3.0 or higher to run.\nexiting...\n", argv[0]);
cudaDeviceReset();
exit(EXIT_WAIVED);
}
// Statistics about the GPU device
printf("> GPU device has %d Multi-Processors, SM %d.%d compute capabilities\n\n",
deviceProp.multiProcessorCount, deviceProp.major, deviceProp.minor);
/* Generate a random tridiagonal symmetric matrix in CSR format */
N = 1048576;
nz = (N-2)*3 + 4;
cudaMallocManaged((void **)&I, sizeof(int)*(N+1));
cudaMallocManaged((void **)&J, sizeof(int)*nz);
cudaMallocManaged((void **)&val, sizeof(float)*nz);
genTridiag(I, J, val, N, nz);
cudaMallocManaged((void **)&x, sizeof(float)*N);
cudaMallocManaged((void **)&rhs, sizeof(float)*N);
for (int i = 0; i < N; i++)
{
rhs[i] = 1.0;
x[i] = 0.0;
}
/* Get handle to the CUBLAS context */
cublasHandle_t cublasHandle = 0;
cublasStatus_t cublasStatus;
cublasStatus = cublasCreate(&cublasHandle);
checkCudaErrors(cublasStatus);
/* Get handle to the CUSPARSE context */
cusparseHandle_t cusparseHandle = 0;
cusparseStatus_t cusparseStatus;
cusparseStatus = cusparseCreate(&cusparseHandle);
checkCudaErrors(cusparseStatus);
cusparseMatDescr_t descr = 0;
cusparseStatus = cusparseCreateMatDescr(&descr);
checkCudaErrors(cusparseStatus);
cusparseSetMatType(descr,CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(descr,CUSPARSE_INDEX_BASE_ZERO);
// temp memory for CG
checkCudaErrors(cudaMallocManaged((void **)&r, N*sizeof(float)));
checkCudaErrors(cudaMallocManaged((void **)&p, N*sizeof(float)));
checkCudaErrors(cudaMallocManaged((void **)&Ax, N*sizeof(float)));
cudaDeviceSynchronize();
for (int i=0; i < N; i++)
{
r[i] = rhs[i];
}
alpha = 1.0;
//.........这里部分代码省略.........
开发者ID:ziyuhe,项目名称:cuda_project,代码行数:101,代码来源:main.cpp
示例14: main
/* Solve Ax=b using the conjugate gradient method a) without any preconditioning, b) using an Incomplete Cholesky preconditioner and c) using an ILU0 preconditioner. */
int main(int argc, char **argv)
{
const int max_iter = 1000;
int k, M = 0, N = 0, nz = 0, *I = NULL, *J = NULL;
int *d_col, *d_row;
int qatest = 0;
const float tol = 1e-12f;
float *x, *rhs;
float r0, r1, alpha, beta;
float *d_val, *d_x;
float *d_zm1, *d_zm2, *d_rm2;
float *d_r, *d_p, *d_omega, *d_y;
float *val = NULL;
float *d_valsILU0;
float *valsILU0;
float rsum, diff, err = 0.0;
float qaerr1, qaerr2 = 0.0;
float dot, numerator, denominator, nalpha;
const float floatone = 1.0;
const float floatzero = 0.0;
int nErrors = 0;
printf("conjugateGradientPrecond starting...\n");
/* QA testing mode */
if (checkCmdLineFlag(argc, (const char **)argv, "qatest"))
{
qatest = 1;
}
/* This will pick the best possible CUDA capable device */
cudaDeviceProp deviceProp;
int devID = findCudaDevice(argc, (const char **)argv);
printf("GPU selected Device ID = %d \n", devID);
if (devID < 0)
{
printf("Invalid GPU device %d selected, exiting...\n", devID);
exit(EXIT_SUCCESS);
}
checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID));
/* Statistics about the GPU device */
printf("> GPU device has %d Multi-Processors, SM %d.%d compute capabilities\n\n",
deviceProp.multiProcessorCount, deviceProp.major, deviceProp.minor);
int version = (deviceProp.major * 0x10 + deviceProp.minor);
if (version < 0x11)
{
printf("%s: requires a minimum CUDA compute 1.1 capability\n", sSDKname);
// cudaDeviceReset causes the driver to clean up all state. While
// not mandatory in normal operation, it is good practice. It is also
// needed to ensure correct operation when the application is being
// profiled. Calling cudaDeviceReset causes all profile data to be
// flushed before the application exits
cudaDeviceReset();
exit(EXIT_SUCCESS);
}
/* Generate a random tridiagonal symmetric matrix in CSR (Compressed Sparse Row) format */
M = N = 16384;
nz = 5*N-4*(int)sqrt((double)N);
I = (int *)malloc(sizeof(int)*(N+1)); // csr row pointers for matrix A
J = (int *)malloc(sizeof(int)*nz); // csr column indices for matrix A
val = (float *)malloc(sizeof(float)*nz); // csr values for matrix A
x = (float *)malloc(sizeof(float)*N);
rhs = (float *)malloc(sizeof(float)*N);
for (int i = 0; i < N; i++)
{
rhs[i] = 0.0; // Initialize RHS
x[i] = 0.0; // Initial approximation of solution
}
genLaplace(I, J, val, M, N, nz, rhs);
/* Create CUBLAS context */
cublasHandle_t cublasHandle = 0;
cublasStatus_t cublasStatus;
cublasStatus = cublasCreate(&cublasHandle);
checkCudaErrors(cublasStatus);
/* Create CUSPARSE context */
cusparseHandle_t cusparseHandle = 0;
cusparseStatus_t cusparseStatus;
cusparseStatus = cusparseCreate(&cusparseHandle);
checkCudaErrors(cusparseStatus);
/* Description of the A matrix*/
cusparseMatDescr_t descr = 0;
cusparseStatus = cusparseCreateMatDescr(&descr);
checkCudaErrors(cusparseStatus);
//.........这里部分代码省略.........
开发者ID:drolfe00,项目名称:CUDAVerificationkernels,代码行数:101,代码来源:main.cpp
示例15: magma_d_spmv
extern "C" magma_int_t
magma_d_spmv(
double alpha,
magma_d_matrix A,
magma_d_matrix x,
double beta,
magma_d_matrix y,
magma_queue_t queue )
{
magma_int_t info = 0;
magma_d_matrix x2={Magma_CSR};
cusparseHandle_t cusparseHandle = 0;
cusparseMatDescr_t descr = 0;
// make sure RHS is a dense matrix
if ( x.storage_type != Magma_DENSE ) {
printf("error: only dense vectors are supported for SpMV.\n");
info = MAGMA_ERR_NOT_SUPPORTED;
goto cleanup;
}
if ( A.memory_location != x.memory_location ||
x.memory_location != y.memory_location ) {
printf("error: linear algebra objects are not located in same memory!\n");
printf("memory locations are: %d %d %d\n",
A.memory_location, x.memory_location, y.memory_location );
info = MAGMA_ERR_INVALID_PTR;
goto cleanup;
}
// DEV case
if ( A.memory_location == Magma_DEV ) {
if ( A.num_cols == x.num_rows && x.num_cols == 1 ) {
if ( A.storage_type == Magma_CSR || A.storage_type == Magma_CUCSR
|| A.storage_type == Magma_CSRL
|| A.storage_type == Magma_CSRU ) {
CHECK_CUSPARSE( cusparseCreate( &cusparseHandle ));
CHECK_CUSPARSE( cusparseSetStream( cusparseHandle, queue->cuda_stream() ));
CHECK_CUSPARSE( cusparseCreateMatDescr( &descr ));
CHECK_CUSPARSE( cusparseSetMatType( descr, CUSPARSE_MATRIX_TYPE_GENERAL ));
CHECK_CUSPARSE( cusparseSetMatIndexBase( descr, CUSPARSE_INDEX_BASE_ZERO ));
cusparseDcsrmv( cusparseHandle,CUSPARSE_OPERATION_NON_TRANSPOSE,
A.num_rows, A.num_cols, A.nnz, &alpha, descr,
A.dval, A.drow, A.dcol, x.dval, &beta, y.dval );
}
else if ( A.storage_type == Magma_ELL ) {
//printf("using ELLPACKT kernel for SpMV: ");
CHECK( magma_dgeelltmv( MagmaNoTrans, A.num_rows, A.num_cols,
A.max_nnz_row, alpha, A.dval, A.dcol, x.dval, beta,
y.dval, queue ));
//printf("done.\n");
}
else if ( A.storage_type == Magma_ELLPACKT ) {
//printf("using ELL kernel for SpMV: ");
CHECK( magma_dgeellmv( MagmaNoTrans, A.num_rows, A.num_cols,
A.max_nnz_row, alpha, A.dval, A.dcol, x.dval, beta,
y.dval, queue ));
//printf("done.\n");
}
else if ( A.storage_type == Magma_ELLRT ) {
//printf("using ELLRT kernel for SpMV: ");
CHECK( magma_dgeellrtmv( MagmaNoTrans, A.num_rows, A.num_cols,
A.max_nnz_row, alpha, A.dval, A.dcol, A.drow, x.dval,
beta, y.dval, A.alignment, A.blocksize, queue ));
//printf("done.\n");
}
else if ( A.storage_type == Magma_SELLP ) {
//printf("using SELLP kernel for SpMV: ");
CHECK( magma_dgesellpmv( MagmaNoTrans, A.num_rows, A.num_cols,
A.blocksize, A.numblocks, A.alignment,
alpha, A.dval, A.dcol, A.drow, x.dval, beta, y.dval, queue ));
//printf("done.\n");
}
else if ( A.storage_type == Magma_DENSE ) {
//printf("using DENSE kernel for SpMV: ");
magmablas_dgemv( MagmaNoTrans, A.num_rows, A.num_cols, alpha,
A.dval, A.num_rows, x.dval, 1, beta, y.dval,
1, queue );
//printf("done.\n");
}
else if ( A.storage_type == Magma_SPMVFUNCTION ) {
//printf("using DENSE kernel for SpMV: ");
CHECK( magma_dcustomspmv( alpha, x, beta, y, queue ));
//printf("done.\n");
}
else if ( A.storage_type == Magma_BCSR ) {
//printf("using CUSPARSE BCSR kernel for SpMV: ");
// CUSPARSE context //
cusparseDirection_t dirA = CUSPARSE_DIRECTION_ROW;
int mb = magma_ceildiv( A.num_rows, A.blocksize );
int nb = magma_ceildiv( A.num_cols, A.blocksize );
CHECK_CUSPARSE( cusparseCreate( &cusparseHandle ));
CHECK_CUSPARSE( cusparseSetStream( cusparseHandle, queue->cuda_stream() ));
CHECK_CUSPARSE( cusparseCreateMatDescr( &descr ));
cusparseDbsrmv( cusparseHandle, dirA,
CUSPARSE_OPERATION_NON_TRANSPOSE, mb, nb, A.numblocks,
//.........这里部分代码省略.........
开发者ID:xulunfan,项目名称:magma,代码行数:101,代码来源:magma_d_blaswrapper.cpp
示例16: main
//.........这里部分代码省略.........
printf("\n");
// int* rowmIndex=(int*)calloc(m+1,sizeof(int));
printf("\n Fine till here");
printf("\n");
//int rowmIndex[5]={1,2,3,4,5};
/* for(i=0;i<m+1;i++)
{
rowmIndex[i]=G.rowIndex[i];
printf(" %d", rowmIndex[i]);
}
*/
cerr<<"Solving Equations "<<endl;
double r1, b, alpha, alpham1, beta, r0, a, na;
const double tol = 0.1;
const int max_iter = 1000000;
int *d_col, *d_row;
double *d_val, *d_x, dot;
double *d_r, *d_p, *d_Ax;
int k;
cublasHandle_t cublasHandle = 0;
cublasStatus_t cublasStatus;
cublasStatus = cublasCreate(&cublasHandle);
checkCudaErrors(cublasStatus);
/* Get handle to the CUSPARSE context */
cusparseHandle_t cusparseHandle = 0;
cusparseStatus_t cusparseStatus;
cusparseStatus = cusparseCreate(&cusparseHandle);
checkCudaErrors(cusparseStatus);
cusparseMatDescr_t descr = 0;
cusparseStatus = cusparseCreateMatDescr(&descr);
checkCudaErrors(cusparseStatus);
cusparseSetMatType(descr,CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatIndexBase(descr,CUSPARSE_INDEX_BASE_ZERO);
checkCudaErrors(cudaMalloc((void **)&d_col, G.nonzero*sizeof(int)));
checkCudaErrors(cudaMalloc((void **)&d_row, (m+n+1)*sizeof(int)));
checkCudaErrors(cudaMalloc((void **)&d_val, G.nonzero*sizeof(double)));
checkCudaErrors(cudaMalloc((void **)&d_x, (m+n)*sizeof(double)));
checkCudaErrors(cudaMalloc((void **)&d_r, (m+n)*sizeof(double)));
checkCudaErrors(cudaMalloc((void **)&d_p, (m+n)*sizeof(double)));
checkCudaErrors(cudaMalloc((void **)&d_Ax, (m+n)*sizeof(double)));
cudaMemcpy(d_col, G.columns, G.nonzero*sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(d_row, G.rowIndex, (m+n+1)*sizeof(int), cudaMemcpyHostToDevice);
cudaMemcpy(d_val, G.Mat_val, G.nonzero*sizeof(double), cudaMemcpyHostToDevice);
cudaMemcpy(d_x, G.x, (m+n)*sizeof(double), cudaMemcpyHostToDevice);
cudaMemcpy(d_r, G.b, (m+n)*sizeof(double), cudaMemcpyHostToDevice);
alpha = 1.0;
alpham1 = -1.0;
beta = 0.0;
r0 = 0.;
printf("\n Data transferred\n");
开发者ID:gcoe-iitb,项目名称:MNA-based-power-grid-solver,代码行数:66,代码来源:main.cpp
示例17: main
//.........这里部分代码省略.........
// convert to SELLP and copy to GPU
TESTING_CHECK( magma_smconvert( hA, &hA_SELLP, Magma_CSR, Magma_SELLP, queue ));
TESTING_CHECK( magma_smtransfer( hA_SELLP, &dA_SELLP, Magma_CPU, Magma_DEV, queue ));
magma_smfree(&hA_SELLP, queue );
magma_smfree( &dy, queue );
TESTING_CHECK( magma_svinit( &dy, Magma_DEV, dx.num_rows, dx.num_cols, c_zero, queue ));
// SpMV on GPU (SELLP)
start = magma_sync_wtime( queue );
for (j=0; j < 10; j++) {
TESTING_CHECK( magma_s_spmv( c_one, dA_SELLP, dx, c_zero, dy, queue ));
}
end = magma_sync_wtime( queue );
printf( " > MAGMA: %.2e seconds %.2e GFLOP/s (SELLP).\n",
(end-start)/10, FLOPS*10.*n/(end-start) );
TESTING_CHECK( magma_smtransfer( dy, &hcheck , Magma_DEV, Magma_CPU, queue ));
res = 0.0;
for(magma_int_t k=0; k < hA.num_rows; k++ ) {
res=res + MAGMA_S_REAL(hcheck.val[k]) - MAGMA_S_REAL(hrefvec.val[k]);
}
printf("%% |x-y|_F = %8.2e\n", res);
if ( res < accuracy )
printf("%% tester spmm SELL-P: ok\n");
else
printf("%% tester spmm SELL-P: failed\n");
magma_smfree( &hcheck, queue );
magma_smfree(&dA_SELLP, queue );
// SpMV on GPU (CUSPARSE - CSR)
// CUSPARSE context //
magma_smfree( &dy, queue );
TESTING_CHECK( magma_svinit( &dy, Magma_DEV, dx.num_rows, dx.num_cols, c_zero, queue ));
//#ifdef PRECISION_d
start = magma_sync_wtime( queue );
TESTING_CHECK( cusparseCreate( &cusparseHandle ));
TESTING_CHECK( cusparseSetStream( cusparseHandle, magma_queue_get_cuda_stream(queue) ));
TESTING_CHECK( cusparseCreateMatDescr( &descr ));
TESTING_CHECK( cusparseSetMatType( descr, CUSPARSE_MATRIX_TYPE_GENERAL ));
TESTING_CHECK( cusparseSetMatIndexBase( descr, CUSPARSE_INDEX_BASE_ZERO ));
float alpha = c_one;
float beta = c_zero;
// copy matrix to GPU
TESTING_CHECK( magma_smtransfer( hA, &dA, Magma_CPU, Magma_DEV, queue) );
for (j=0; j < 10; j++) {
cusparseScsrmm(cusparseHandle,
CUSPARSE_OPERATION_NON_TRANSPOSE,
dA.num_rows, n, dA.num_cols, dA.nnz,
&alpha, descr, dA.dval, dA.drow, dA.dcol,
dx.dval, dA.num_cols, &beta, dy.dval, dA.num_cols);
}
end = magma_sync_wtime( queue );
printf( " > CUSPARSE: %.2e seconds %.2e GFLOP/s (CSR).\n",
(end-start)/10, FLOPS*10*n/(end-start) );
TESTING_CHECK( magma_smtransfer( dy, &hcheck , Magma_DEV, Magma_CPU, queue ));
res = 0.0;
for(magma_int_t k=0; k < hA.num_rows; k++ ) {
res = res + MAGMA_S_REAL(hcheck.val[k]) - MAGMA_S_REAL(hrefvec.val[k]);
}
printf("%% |x-y|_F = %8.2e\n", res);
if ( res < accuracy )
printf("%% tester spmm cuSPARSE: ok\n");
else
printf("%% tester spmm cuSPARSE: failed\n");
magma_smfree( &hcheck, queue );
cusparseDestroyMatDescr( descr );
cusparseDestroy( cusparseHandle );
descr = NULL;
cusparseHandle = NULL;
//#endif
printf("\n\n");
// free CPU memory
magma_smfree( &hA, queue );
magma_smfree( &hx, queue );
magma_smfree( &hy, queue );
magma_smfree( &hrefvec, queue );
// free GPU memory
magma_smfree( &dx, queue );
magma_smfree( &dy, queue );
magma_smfree( &dA, queue);
#ifdef MAGMA_WITH_MKL
magma_free_cpu( pntre );
#endif
i++;
}
magma_queue_destroy( queue );
TESTING_CHECK( magma_finalize() );
return info;
}
开发者ID:maxhutch,项目名称:magma,代码行数:101,代码来源:testing_sspmm.cpp
示例18: magma_cmtransposeconjugate
extern "C" magma_int_t
magma_cmtransposeconjugate(
magma_c_matrix A,
magma_c_matrix *B,
magma_queue_t queue )
{
// for symmetric matrices: convert to csc using cusparse
magma_int_t info = 0;
cusparseHandle_t handle=NULL;
cusparseMatDescr_t descrA=NULL;
cusparseMatDescr_t descrB=NULL;
magma_c_matrix ACSR={Magma_CSR}, BCSR={Magma_CSR};
magma_c_matrix A_d={Magma_CSR}, B_d={Magma_CSR};
if( A.storage_type == Magma_CSR && A.memory_location == Magma_DEV ) {
// fill in information for B
B->storage_type = A.storage_type;
B->diagorder_type = A.diagorder_type;
B->memory_location = Magma_DEV;
B->num_rows = A.num_cols; // transposed
B->num_cols = A.num_rows; // transposed
B->nnz = A.nnz;
B->true_nnz = A.true_nnz;
if ( A.fill_mode == MagmaFull ) {
B->fill_mode = MagmaFull;
}
else if ( A.fill_mode == MagmaLower ) {
B->fill_mode = MagmaUpper;
}
else if ( A.fill_mode == MagmaUpper ) {
B->fill_mode = MagmaLower;
}
B->dval = NULL;
B->drow = NULL;
B->dcol = NULL;
// memory allocation
CHECK( magma_cmalloc( &B->dval, B->nnz ));
CHECK( magma_index_malloc( &B->drow, B->num_rows + 1 ));
CHECK( magma_index_malloc( &B->dcol, B->nnz ));
// CUSPARSE context //
CHECK_CUSPARSE( cusparseCreate( &handle ));
CHECK_CUSPARSE( cusparseSetStream( handle, queue->cuda_stream() ));
CHECK_CUSPARSE( cusparseCreateMatDescr( &descrA ));
CHECK_CUSPARSE( cusparseCreateMatDescr( &descrB ));
CHECK_CUSPARSE( cusparseSetMatType( descrA, CUSPARSE_MATRIX_TYPE_GENERAL ));
CHECK_CUSPARSE( cusparseSetMatType( descrB, CUSPARSE_MATRIX_TYPE_GENERAL ));
CHECK_CUSPARSE( cusparseSetMatIndexBase( descrA, CUSPARSE_INDEX_BASE_ZERO ));
CHECK_CUSPARSE( cusparseSetMatIndexBase( descrB, CUSPARSE_INDEX_BASE_ZERO ));
CHECK_CUSPARSE(
cusparseCcsr2csc( handle, A.num_rows, A.num_cols, A.nnz,
A.dval, A.drow, A.dcol, B->dval, B->dcol, B->drow,
CUSPARSE_ACTION_NUMERIC,
CUSPARSE_INDEX_BASE_ZERO) );
CHECK( magma_cmconjugate( B, queue ));
} else if ( A.memory_location == Magma_CPU ){
CHECK( magma_cmtransfer( A, &A_d, A.memory_location, Magma_DEV, queue ));
CHECK( magma_cmtransposeconjugate( A_d, &B_d, queue ));
CHECK( magma_cmtransfer( B_d, B, Magma_DEV, A.memory_location, queue ));
} else {
CHECK( magma_cmconvert( A, &ACSR, A.storage_type, Magma_CSR, queue ));
CHECK( magma_cmtransposeconjugate( ACSR, &BCSR, queue ));
CHECK( magma_cmconvert( BCSR, B, Magma_CSR, A.storage_type, queue ));
}
cleanup:
cusparseDestroyMatDescr( descrA );
cusparseDestroyMatDescr( descrB );
cusparseDestroy( handle );
magma_cmfree( &A_d, queue );
magma_cmfree( &B_d, queue );
magma_cmfree( &ACSR, queue );
magma_cmfree( &BCSR, queue );
if( info != 0 ){
magma_cmfree( B, queue );
}
return info;
}
开发者ID:xulunfan,项目名称:magma,代码行数:79,代码来源:magma_cmtranspose.cpp
示例19: magma_ccustomicsetup
magma_int_t
magma_ccustomicsetup(
magma_c_matrix A,
magma_c_matrix b,
magma_c_preconditioner *precond,
magma_queue_t queue )
{
magma_int_t info = 0;
cusparseHandle_t cusparseHandle=NULL;
cusparseMatDescr_t descrL=NULL;
cusparseMatDescr_t descrU=NULL;
magma_c_matrix hA={Magma_CSR};
char preconditionermatrix[255];
snprintf( preconditionermatrix, sizeof(preconditionermatrix),
"/Users/hanzt0114cl306/work/matrices/ani/ani7_crop_ichol.mtx" );
CHECK( magma_c_csr_mtx( &hA, preconditionermatrix , queue) );
// for CUSPARSE
CHECK( magma_cmtransfer( hA, &precond->M, Magma_CPU, Magma_DEV , queue ));
// copy the matrix to precond->L and (transposed) to precond->U
CHECK( magma_cmtransfer(precond->M, &(precond->L), Magma_DEV, Magma_DEV, queue ));
CHECK( magma_cmtranspose( precond->L, &(precond->U), queue ));
// extract the diagonal of L into precond->d
CHECK( magma_cjacobisetup_diagscal( precond->L, &precond->d, queue ));
CHECK( magma_cvinit( &precond->work1, Magma_DEV, hA.num_rows, 1, MAGMA_C_ZERO, queue ));
// extract the diagonal of U into precond->d2
CHECK( magma_cjacobisetup_diagscal( precond->U, &precond->d2, queue ));
CHECK( magma_cvinit( &precond->work2, Magma_DEV, hA.num_rows, 1, MAGMA_C_ZERO, queue ));
// CUSPARSE context //
CHECK_CUSPARSE( cusparseCreate( &cusparseHandle ));
CHECK_CUSPARSE( cusparseCreateMatDescr( &descrL ));
CHECK_CUSPARSE( cusparseSetMatType( descrL, CUSPARSE_MATRIX_TYPE_TRIANGULAR ));
CHECK_CUSPARSE( cusparseSetMatDiagType( descrL, CUSPARSE_DIAG_TYPE_NON_UNIT ));
CHECK_CUSPARSE( cusparseSetMatIndexBase( descrL, CUSPARSE_INDEX_BASE_ZERO ));
CHECK_CUSPARSE( cusparseSetMatFillMode( descrL, CUSPARSE_FILL_MODE_LOWER ));
CHECK_CUSPARSE( cusparseCreateSolveAnalysisInfo( &precond->cuinfoL ));
CHECK_CUSPARSE( cusparseCcsrsv_analysis( cusparseHandle,
CUSPARSE_OPERATION_NON_TRANSPOSE, precond->M.num_rows,
precond->M.nnz, descrL,
precond->M.val, precond->M.row, precond->M.col, precond->cuinfoL ));
CHECK_CUSPARSE( cusparseCreateMatDescr( &descrU ));
CHECK_CUSPARSE( cusparseSetMatType( descrU, CUSPARSE_MATRIX_TYPE_TRIANGULAR ));
CHECK_CUSPARSE( cuspars
|
请发表评论