]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add AssertCusparse macro to check that a cuSPARSE routine was successful
authorBruno Turcksin <bruno.turcksin@gmail.com>
Mon, 29 Jan 2018 15:44:59 +0000 (10:44 -0500)
committerBruno Turcksin <bruno.turcksin@gmail.com>
Wed, 31 Jan 2018 02:09:08 +0000 (21:09 -0500)
include/deal.II/base/exceptions.h
source/base/exceptions.cc

index d16fa3412516e74a01ebac95d1e1a6fcfb4edf2c..b5c9d3e030e56ddc1f51b10dc7455b2711dde60a 100644 (file)
 #include <string>
 #include <ostream>
 
+#ifdef DEAL_II_WITH_CUDA
+#include <cusparse.h>
+#endif
+
+
 DEAL_II_NAMESPACE_OPEN
 
 
@@ -314,6 +319,13 @@ namespace deal_II_exceptions
                               const char       *cond,
                               const char       *exc_name,
                               ExceptionBase     e) noexcept;
+#ifdef DEAL_II_WITH_CUDA
+    /**
+     * Return a string given an error code. This is similar to the cudaGetErrorString
+     * function but there is no equivalent function for cuSPARSE.
+     */
+    std::string get_cusparse_error_string(const cusparseStatus_t error_code);
+#endif
   } /*namespace internals*/
 
 } /*namespace deal_II_exceptions*/
@@ -1131,6 +1143,13 @@ namespace StandardExceptions
   DeclException1 (ExcCudaError,
                   char *,
                   << arg1);
+  /**
+   * This exception is raised if an error happened in a cuSPARSE function.
+   */
+  DeclException1 (ExcCusparseError,
+                  std::string,
+                  << "There was an error in a cuSPARSE function: "
+                  << arg1);
 #endif
 //@}
 
@@ -1246,6 +1265,18 @@ namespace StandardExceptions
  */
 #define AssertCuda(error_code) Assert(error_code == cudaSuccess, \
                                       dealii::ExcCudaError(cudaGetErrorString(error_code)))
+
+/**
+ * An assertion that checks that the error code produced by calling a cuSPARSE
+ * routine is equal to CUSPARSE_STATUS_SUCCESS.
+ *
+ * @ingroup Exceptions
+ * @author Bruno Turcksin, 2018
+ */
+#define AssertCusparse(error_code) Assert(error_code == CUSPARSE_STATUS_SUCCESS, \
+                                          dealii::ExcCusparseError( \
+                                              dealii::deal_II_exceptions::internals:: \
+                                              get_cusparse_error_string(error_code)))
 #endif
 
 using namespace StandardExceptions;
index 52c23a70c0c108d30ba4cbe0759c8e9c8cd304fc..64f8f31425d9770952abb4b5bdbe084eb02e2aa8 100644 (file)
@@ -484,6 +484,53 @@ namespace deal_II_exceptions
         }
     }
 
+
+
+#ifdef DEAL_II_WITH_CUDA
+    std::string get_cusparse_error_string(const cusparseStatus_t error_code)
+    {
+      switch (error_code)
+        {
+        case CUSPARSE_STATUS_NOT_INITIALIZED:
+        {
+          return "The cuSPARSE library was not initialized";
+        }
+        case CUSPARSE_STATUS_ALLOC_FAILED:
+        {
+          return "Resource allocation failed inside the cuSPARSE library";
+        }
+        case CUSPARSE_STATUS_INVALID_VALUE:
+        {
+          return "An unsupported value of parameter was passed to the function";
+        }
+        case CUSPARSE_STATUS_ARCH_MISMATCH:
+        {
+          return "The function requires a feature absent from the device architecture";
+        }
+        case CUSPARSE_STATUS_MAPPING_ERROR:
+        {
+          return "An access to GPU memory space failed";
+        }
+        case CUSPARSE_STATUS_EXECUTION_FAILED:
+        {
+          return "The GPU program failed to execute";
+        }
+        case CUSPARSE_STATUS_INTERNAL_ERROR:
+        {
+          return "An internal cuSPARSE operation failed";
+        }
+        case CUSPARSE_STATUS_MATRIX_TYPE_NOT_SUPPORTED:
+        {
+          return "The matrix type is not supported by this function";
+        }
+        default:
+        {
+          return "Unknown error";
+        }
+        }
+    }
+#endif
+
   } /*namespace internals*/
 } /*namespace deal_II_exceptions*/
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.