Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Kokkos_CUSPARSEOps.cpp
00001 #include "Kokkos_ConfigDefs.hpp"
00002 #include "Kokkos_CUSPARSEOps.hpp"
00003 
00004 Teuchos::RCP<cusparseHandle_t> Kokkos::CUSPARSEdetails::Session::session_handle_ = Teuchos::null;
00005 
00006 void Kokkos::CUSPARSEdetails::Session::init() 
00007 {
00008   if (session_handle_ == null) {
00009     cusparseHandle_t *hndl = new cusparseHandle_t;
00010     cusparseStatus_t status = cusparseCreate(hndl);
00011     TEUCHOS_TEST_FOR_EXCEPTION(status == CUSPARSE_STATUS_NOT_INITIALIZED, std::runtime_error, 
00012         "Kokkos::CUSPARSEdetails::init(): the CUDA Runtime initialization failed.")
00013     TEUCHOS_TEST_FOR_EXCEPTION(status == CUSPARSE_STATUS_ALLOC_FAILED, std::runtime_error, 
00014         "Kokkos::CUSPARSEdetails::init(): the resources could not be allocated.")
00015     TEUCHOS_TEST_FOR_EXCEPTION(status == CUSPARSE_STATUS_ARCH_MISMATCH, std::runtime_error, 
00016         "Kokkos::CUSPARSEdetails::init(): the device compute capability (CC) is less than 1.1.")
00017     TEUCHOS_TEST_FOR_EXCEPTION(status != CUSPARSE_STATUS_SUCCESS, std::runtime_error, 
00018         "Kokkos::CUSPARSEdetails::init(): unspecified error.")
00019     session_handle_ = Teuchos::rcpWithDealloc(hndl,CUSPARSESessionDestroyer(),true);
00020   }
00021 }
00022 
00023 Teuchos::RCP<const cusparseHandle_t> Kokkos::CUSPARSEdetails::Session::getHandle() {
00024   return session_handle_;
00025 }
00026 
00027 Teuchos::RCP<cusparseMatDescr_t> Kokkos::CUSPARSEdetails::createMatDescr() 
00028 {
00029   cusparseMatDescr_t *desc = new cusparseMatDescr_t;
00030   cusparseStatus_t status = cusparseCreateMatDescr(desc);
00031   TEUCHOS_TEST_FOR_EXCEPTION(status == CUSPARSE_STATUS_ALLOC_FAILED, std::runtime_error, 
00032       "Kokkos::CUSPARSEdetails::createMatDescr(): the resources could not be allocated.")
00033   TEUCHOS_TEST_FOR_EXCEPTION(status != CUSPARSE_STATUS_SUCCESS, std::runtime_error, 
00034       "Kokkos::CUSPARSEdetails::createMatDescr(): unspecified error.")
00035   return Teuchos::rcpWithDealloc(desc,CUSPARSEMatDescDestroyer(),true);
00036 }
00037 
00038 Teuchos::RCP<cusparseSolveAnalysisInfo_t> Kokkos::CUSPARSEdetails::createSolveAnalysisInfo()
00039 {
00040   cusparseSolveAnalysisInfo_t *info = new cusparseSolveAnalysisInfo_t;
00041   cusparseStatus_t status = cusparseCreateSolveAnalysisInfo(info);
00042   TEUCHOS_TEST_FOR_EXCEPTION(status == CUSPARSE_STATUS_ALLOC_FAILED, std::runtime_error, 
00043       "Kokkos::CUSPARSEdetails::createSolveAnalysisInfo(): the resources could not be allocated.")
00044   TEUCHOS_TEST_FOR_EXCEPTION(status != CUSPARSE_STATUS_SUCCESS, std::runtime_error, 
00045       "Kokkos::CUSPARSEdetails::createSolveAnalysisInfo(): unspecified error.")
00046   return Teuchos::rcpWithDealloc(info,CUSPARSESolveAnalysisDestroyer(),true);
00047 }
00048 
00050 Kokkos::CUSPARSEdetails::CUSPARSESessionDestroyer::CUSPARSESessionDestroyer() {}
00051 void Kokkos::CUSPARSEdetails::CUSPARSESessionDestroyer::free(cusparseHandle_t *ptr) 
00052 {
00053   cusparseStatus_t status = cusparseDestroy( *ptr );
00054   delete ptr;
00055   TEUCHOS_TEST_FOR_EXCEPTION(status != CUSPARSE_STATUS_SUCCESS, std::runtime_error,
00056       "Kokkos::CUSPARSEdetails::CUSPARSESessionDestroyer::free(): library was never initialized; we should not have been called.")
00057 }
00058 
00060 Kokkos::CUSPARSEdetails::CUSPARSEMatDescDestroyer::CUSPARSEMatDescDestroyer() {}
00061 void Kokkos::CUSPARSEdetails::CUSPARSEMatDescDestroyer::free(cusparseMatDescr_t *ptr) 
00062 {
00063   cusparseStatus_t status = cusparseDestroyMatDescr( *ptr );
00064   delete ptr;
00065   TEUCHOS_TEST_FOR_EXCEPTION(status != CUSPARSE_STATUS_SUCCESS, std::runtime_error,
00066       "Kokkos::CUSPARSEdetails::CUSPARSEMatDescDestroyer::free(): unknown error.")
00067 }
00068 
00070 Kokkos::CUSPARSEdetails::CUSPARSESolveAnalysisDestroyer::CUSPARSESolveAnalysisDestroyer() {}
00071 void Kokkos::CUSPARSEdetails::CUSPARSESolveAnalysisDestroyer::free(cusparseSolveAnalysisInfo_t *ptr) 
00072 {
00073   cusparseStatus_t status = cusparseDestroySolveAnalysisInfo( *ptr );
00074   delete ptr;
00075   TEUCHOS_TEST_FOR_EXCEPTION(status != CUSPARSE_STATUS_SUCCESS, std::runtime_error,
00076       "Kokkos::CUSPARSEdetails::CUSPARSESolveAnalysisDestroyer::free(): unknown error.")
00077 }
00078 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends