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_USE_EIGEN
.. doxygendefine:: CUDATOOLS_USE_PYTHON
Macro Functions
===============

@ -16,6 +16,12 @@
#include <Eigen/Dense>
#endif
#ifdef CUDATOOLS_USE_PYTHON
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
namespace py = pybind11;
#endif
#ifdef DEVICE
#define POINTER pDevice
#else
@ -750,6 +756,22 @@ template <typename T> class Array {
CT_ERROR(mIsSlice, "Cannot update device copy on a slice");
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>

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

Loading…
Cancel
Save