Added error message colors and updated Eigen and Python definition macros

main
Kenneth Jao 2 years ago
commit 63409cd6ac
  1. 1
      docs/source/core.rst
  2. 22
      include/Array.h
  3. 23
      include/Macros.h

@ -43,6 +43,7 @@ Compilation Options
------------------- -------------------
.. doxygendefine:: CUDATOOLS_ARRAY_MAX_AXES .. doxygendefine:: CUDATOOLS_ARRAY_MAX_AXES
.. doxygendefine:: CUDATOOLS_USE_EIGEN .. doxygendefine:: CUDATOOLS_USE_EIGEN
.. doxygendefine:: CUDATOOLS_USE_PYTHON
Macro Functions Macro Functions
=============== ===============

@ -16,6 +16,12 @@
#include <Eigen/Dense> #include <Eigen/Dense>
#endif #endif
#ifdef CUDATOOLS_USE_PYTHON
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
namespace py = pybind11;
#endif
#ifdef DEVICE #ifdef DEVICE
#define POINTER pDevice #define POINTER pDevice
#else #else
@ -750,6 +756,22 @@ template <typename T> class Array {
CT_ERROR(mIsSlice, "Cannot update device copy on a slice"); CT_ERROR(mIsSlice, "Cannot update device copy on a slice");
return CudaTools::copy(pHost, pDevice, mShape.items() * sizeof(T), stream); return CudaTools::copy(pHost, pDevice, mShape.items() * sizeof(T), stream);
}; };
#ifdef CUDATOOLS_USE_PYTHON
/**
* Returns a py::array for making an Array available as a Python numpy array.
*/
py::array pyArray() const {
std::vector<py::ssize_t> dims, strides;
for (uint iAxis = 0; iAxis < mShape.axes(); ++iAxis) {
dims.push_back(static_cast<py::ssize_t>(mShape.dim(iAxis)));
strides.push_back(sizeof(T) * static_cast<py::ssize_t>(mShape.stride(iAxis)));
}
return py::array_t<T, py::array::f_style>(
py::buffer_info((void*)pHost, sizeof(T), py::format_descriptor<T>::format(),
static_cast<py::ssize_t>(mShape.axes()), dims, strides));
};
#endif
}; };
template <typename T> template <typename T>

@ -55,6 +55,12 @@
*/ */
#define CUDATOOLS_USE_EIGEN #define CUDATOOLS_USE_EIGEN
/**
* \def CUDATOOLS_USE_PYTHON
* Compile the CudaTools library with Python support.
*/
#define CUDATOOLS_USE_PYTHON
/** /**
* \def KERNEL(call, settings, ...) * \def KERNEL(call, settings, ...)
* Used to call a CUDA kernel. * Used to call a CUDA kernel.
@ -224,12 +230,13 @@
#ifdef DEVICE #ifdef DEVICE
#define CT_ERROR_IF(a, op, b, msg) \ #define CT_ERROR_IF(a, op, b, msg) \
if (a op b) { \ if (a op b) { \
printf("[ERROR] %s:%d\n | %s: (" #a ") " #op " (" #b ").\n", __FILE__, __LINE__, msg); \ printf("\033[1;31m[CudaTools]\033[0m %s:%d\n | %s: (" #a ") " #op " (" #b ").\n", \
__FILE__, __LINE__, msg); \
} }
#define CT_ERROR(a, msg) \ #define CT_ERROR(a, msg) \
if (a) { \ if (a) { \
printf("[ERROR] %s:%d\n | %s: " #a ".\n", __FILE__, __LINE__, msg); \ printf("\033[1;31m[CudaTools]\033[0m %s:%d\n | %s: " #a ".\n", __FILE__, __LINE__, msg); \
} }
#else #else
@ -239,14 +246,14 @@
std::ostringstream os_b; \ std::ostringstream os_b; \
os_a << a; \ os_a << a; \
os_b << b; \ os_b << b; \
printf("[ERROR] %s:%d\n | %s: (" #a ")%s " #op " (" #b ")%s.\n", __FILE__, __LINE__, msg, \ printf("\033[1;31m[CudaTools]\033[0m %s:%d\n | %s: (" #a ")%s " #op " (" #b ")%s.\n", \
os_a.str().c_str(), os_b.str().c_str()); \ __FILE__, __LINE__, msg, os_a.str().c_str(), os_b.str().c_str()); \
throw std::exception(); \ throw std::exception(); \
} }
#define CT_ERROR(a, msg) \ #define CT_ERROR(a, msg) \
if (a) { \ if (a) { \
printf("[ERROR] %s:%d\n | %s: " #a ".\n", __FILE__, __LINE__, msg); \ printf("\033[1;31m[CudaTools]\033[0m %s:%d\n | %s: " #a ".\n", __FILE__, __LINE__, msg); \
throw std::exception(); \ throw std::exception(); \
} }
#endif #endif
@ -259,7 +266,8 @@
do { \ do { \
cudaError_t err = (call); \ cudaError_t err = (call); \
if (err != cudaSuccess) { \ if (err != cudaSuccess) { \
printf("[CUDA] %s:%d\n | %s\n", __FILE__, __LINE__, cudaGetErrorString(err)); \ printf("\033[1;31m[CUDA]\033[0m %s:%d\n | %s\n", __FILE__, __LINE__, \
cudaGetErrorString(err)); \
throw std::exception(); \ throw std::exception(); \
} \ } \
} while (0) } while (0)
@ -268,7 +276,8 @@
do { \ do { \
cublasStatus_t err = (call); \ cublasStatus_t err = (call); \
if (err != CUBLAS_STATUS_SUCCESS) { \ if (err != CUBLAS_STATUS_SUCCESS) { \
printf("[cuBLAS] %s:%d\n | %s\n", __FILE__, __LINE__, cublasGetStatusName(err)); \ printf("\033[1;31m[cuBLAS]\033[0m %s:%d\n | %s\n", __FILE__, __LINE__, \
cublasGetStatusName(err)); \
throw std::exception(); \ throw std::exception(); \
} \ } \
} while (0) } while (0)

Loading…
Cancel
Save