1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements.  See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership.  The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License.  You may obtain a copy of the License at
8 //
9 //   http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied.  See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #include "arrow/gpu/cuda_internal.h"
19 
20 #include <sstream>
21 #include <string>
22 
23 #include "arrow/util/logging.h"
24 
25 namespace arrow {
26 namespace cuda {
27 namespace internal {
28 
CudaErrorDescription(CUresult err)29 std::string CudaErrorDescription(CUresult err) {
30   DCHECK_NE(err, CUDA_SUCCESS);
31   std::stringstream ss;
32 
33   const char* name = nullptr;
34   auto err_result = cuGetErrorName(err, &name);
35   if (err_result == CUDA_SUCCESS) {
36     DCHECK_NE(name, nullptr);
37     ss << "[" << name << "] ";
38   }
39 
40   const char* str = nullptr;
41   err_result = cuGetErrorString(err, &str);
42   if (err_result == CUDA_SUCCESS) {
43     DCHECK_NE(str, nullptr);
44     ss << str;
45   } else {
46     ss << "unknown error";
47   }
48   return ss.str();
49 }
50 
StatusFromCuda(CUresult res,const char * function_name)51 Status StatusFromCuda(CUresult res, const char* function_name) {
52   if (res == CUDA_SUCCESS) {
53     return Status::OK();
54   }
55   std::stringstream ss;
56   ss << "Cuda error " << res;
57   if (function_name != nullptr) {
58     ss << " in function '" << function_name << "'";
59   }
60   ss << ": " << CudaErrorDescription(res);
61   return Status::IOError(ss.str());
62 }
63 
64 }  // namespace internal
65 }  // namespace cuda
66 }  // namespace arrow
67