/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/common/validation_helpers.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/common/validation_helpers.hpp Source File#

2 min read time

Applies to Linux

rocCV: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/common/validation_helpers.hpp Source File
validation_helpers.hpp
Go to the documentation of this file.
1 
22 #pragma once
23 
24 #include <algorithm>
25 #include <vector>
26 
27 #include "core/tensor.hpp"
28 
33 #define CHECK_TENSOR_DEVICE(tensor, tensor_device) \
34  if (tensor.device() != tensor_device) { \
35  throw roccv::Exception("Invalid tensor " #tensor \
36  ": Ensure that this tensor is allocated on the proper device.", \
37  eStatusType::INVALID_OPERATION); \
38  }
39 
45 #define CHECK_TENSOR_LAYOUT(tensor, ...) \
46  do { \
47  std::vector<eTensorLayout> v{__VA_ARGS__}; \
48  if (std::find(v.begin(), v.end(), tensor.layout().elayout()) == v.end()) { \
49  throw roccv::Exception("Unsupported tensor layout: " #tensor, eStatusType::INVALID_COMBINATION); \
50  } \
51  } while (0);
52 
58 #define CHECK_TENSOR_DATATYPES(tensor, ...) \
59  do { \
60  std::vector<eDataType> v{__VA_ARGS__}; \
61  if (std::find(v.begin(), v.end(), tensor.dtype().etype()) == v.end()) { \
62  throw roccv::Exception("Unsupported data type: " #tensor, eStatusType::NOT_IMPLEMENTED); \
63  } \
64  } while (0);
65 
71 #define CHECK_TENSOR_COMPARISON(comparison) \
72  if (!(comparison)) { \
73  throw roccv::Exception("Tensor check failed: " #comparison, eStatusType::INVALID_COMBINATION); \
74  }
75 
80 #define CHECK_TENSOR_CHANNELS(tensor, ...) \
81  do { \
82  const std::vector<unsigned int> v{__VA_ARGS__}; \
83  if (std::find(v.begin(), v.end(), tensor.shape(tensor.layout().channels_index())) == v.end()) { \
84  throw roccv::Exception("Unsupported channel count: " #tensor, eStatusType::INVALID_COMBINATION); \
85  } \
86  } while (0);