1/* 2 * Copyright 2008-2013 NVIDIA Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 18#pragma once 19 20#include <thrust/system/cuda/error.h> 21#include <thrust/system/cuda/detail/guarded_cuda_runtime_api.h> 22 23namespace thrust 24{ 25 26namespace system 27{ 28 29 30error_code make_error_code(cuda_cub::errc::errc_t e) 31{ 32 return error_code(static_cast<int>(e), cuda_category()); 33} // end make_error_code() 34 35 36error_condition make_error_condition(cuda_cub::errc::errc_t e) 37{ 38 return error_condition(static_cast<int>(e), cuda_category()); 39} // end make_error_condition() 40 41 42namespace cuda_cub 43{ 44 45namespace detail 46{ 47 48 49class cuda_error_category 50 : public error_category 51{ 52 public: 53 inline cuda_error_category(void) {} 54 55 inline virtual const char *name(void) const 56 { 57 return "cuda"; 58 } 59 60 inline virtual std::string message(int ev) const 61 { 62 char const* const unknown_str = "unknown error"; 63 char const* const unknown_name = "cudaErrorUnknown"; 64 char const* c_str = ::cudaGetErrorString(static_cast<cudaError_t>(ev)); 65 char const* c_name = ::cudaGetErrorName(static_cast<cudaError_t>(ev)); 66 return std::string(c_name ? c_name : unknown_name) 67 + ": " + (c_str ? c_str : unknown_str); 68 } 69 70 inline virtual error_condition default_error_condition(int ev) const 71 { 72 using namespace cuda_cub::errc; 73 74 if(ev < ::cudaErrorApiFailureBase) 75 { 76 return make_error_condition(static_cast<errc_t>(ev)); 77 } 78 79 return system_category().default_error_condition(ev); 80 } 81}; // end cuda_error_category 82 83} // end detail 84 85} // end namespace cuda_cub 86 87 88const error_category &cuda_category(void) 89{ 90 static const thrust::system::cuda_cub::detail::cuda_error_category result; 91 return result; 92} 93 94 95} // end namespace system 96 97} // end namespace thrust 98 99