exceptions.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, 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 #pragma once
17 #include <exception>
18 
19 namespace raft_proto {
20 struct bad_cuda_call : std::exception {
21  bad_cuda_call() : bad_cuda_call("CUDA API call failed") {}
22  bad_cuda_call(char const* msg) : msg_{msg} {}
23  virtual char const* what() const noexcept { return msg_; }
24 
25  private:
26  char const* msg_;
27 };
28 
29 struct out_of_bounds : std::exception {
30  out_of_bounds() : out_of_bounds("Attempted out-of-bounds memory access") {}
31  out_of_bounds(char const* msg) : msg_{msg} {}
32  virtual char const* what() const noexcept { return msg_; }
33 
34  private:
35  char const* msg_;
36 };
37 
38 struct wrong_device_type : std::exception {
39  wrong_device_type() : wrong_device_type("Attempted to use host data on GPU or device data on CPU")
40  {
41  }
42  wrong_device_type(char const* msg) : msg_{msg} {}
43  virtual char const* what() const noexcept { return msg_; }
44 
45  private:
46  char const* msg_;
47 };
48 
49 struct mem_type_mismatch : std::exception {
50  mem_type_mismatch() : mem_type_mismatch("Memory type does not match expected type") {}
51  mem_type_mismatch(char const* msg) : msg_{msg} {}
52  virtual char const* what() const noexcept { return msg_; }
53 
54  private:
55  char const* msg_;
56 };
57 
58 struct wrong_device : std::exception {
59  wrong_device() : wrong_device("Attempted to use incorrect device") {}
60  wrong_device(char const* msg) : msg_{msg} {}
61  virtual char const* what() const noexcept { return msg_; }
62 
63  private:
64  char const* msg_;
65 };
66 
67 } // namespace raft_proto
Definition: buffer.hpp:35
Definition: exceptions.hpp:20
virtual char const * what() const noexcept
Definition: exceptions.hpp:23
bad_cuda_call(char const *msg)
Definition: exceptions.hpp:22
bad_cuda_call()
Definition: exceptions.hpp:21
Definition: exceptions.hpp:49
mem_type_mismatch(char const *msg)
Definition: exceptions.hpp:51
mem_type_mismatch()
Definition: exceptions.hpp:50
virtual char const * what() const noexcept
Definition: exceptions.hpp:52
Definition: exceptions.hpp:29
out_of_bounds(char const *msg)
Definition: exceptions.hpp:31
out_of_bounds()
Definition: exceptions.hpp:30
virtual char const * what() const noexcept
Definition: exceptions.hpp:32
Definition: exceptions.hpp:38
wrong_device_type()
Definition: exceptions.hpp:39
virtual char const * what() const noexcept
Definition: exceptions.hpp:43
wrong_device_type(char const *msg)
Definition: exceptions.hpp:42
Definition: exceptions.hpp:58
virtual char const * what() const noexcept
Definition: exceptions.hpp:61
wrong_device()
Definition: exceptions.hpp:59
wrong_device(char const *msg)
Definition: exceptions.hpp:60