#include <config.h>

#include <primitiv/cuda_utils.h>

namespace primitiv {
namespace cuda {

std::string cublasGetErrorString(::cublasStatus_t err) {
#define MESSAGE(status) if (err == status) return #status
  MESSAGE(CUBLAS_STATUS_SUCCESS);
  MESSAGE(CUBLAS_STATUS_NOT_INITIALIZED);
  MESSAGE(CUBLAS_STATUS_ALLOC_FAILED);
  MESSAGE(CUBLAS_STATUS_INVALID_VALUE);
  MESSAGE(CUBLAS_STATUS_ARCH_MISMATCH);
  MESSAGE(CUBLAS_STATUS_MAPPING_ERROR);
  MESSAGE(CUBLAS_STATUS_EXECUTION_FAILED);
  MESSAGE(CUBLAS_STATUS_INTERNAL_ERROR);
  MESSAGE(CUBLAS_STATUS_NOT_SUPPORTED);
  MESSAGE(CUBLAS_STATUS_LICENSE_ERROR);
#undef MESSAGE
  return "Unknown cublasStatus_t value.";
}

std::string curandGetErrorString(::curandStatus_t err) {
#define MESSAGE(status) if (err == status) return #status
  MESSAGE(CURAND_STATUS_SUCCESS);
  MESSAGE(CURAND_STATUS_VERSION_MISMATCH);
  MESSAGE(CURAND_STATUS_NOT_INITIALIZED);
  MESSAGE(CURAND_STATUS_ALLOCATION_FAILED);
  MESSAGE(CURAND_STATUS_TYPE_ERROR);
  MESSAGE(CURAND_STATUS_OUT_OF_RANGE);
  MESSAGE(CURAND_STATUS_LENGTH_NOT_MULTIPLE);
  MESSAGE(CURAND_STATUS_DOUBLE_PRECISION_REQUIRED);
  MESSAGE(CURAND_STATUS_LAUNCH_FAILURE);
  MESSAGE(CURAND_STATUS_PREEXISTING_FAILURE);
  MESSAGE(CURAND_STATUS_INITIALIZATION_FAILED);
  MESSAGE(CURAND_STATUS_ARCH_MISMATCH);
  MESSAGE(CURAND_STATUS_INTERNAL_ERROR);
#undef MESSAGE
  return "Unknown curandStatus_t value.";
}

}  // namespace cuda
}  // namespace primitiv
