134 #include <functional> 136 #include <type_traits> 141 #include "../C/cldnn.h" 150 template <typename T, typename = typename std::enable_if<!std::is_floating_point<T>::value>::type>
153 operator uint16_t()
const {
return _data; }
154 operator float()
const 158 if (status != CLDNN_SUCCESS)
159 throw std::runtime_error(
"Conversion from half failed");
166 if (status != CLDNN_SUCCESS)
167 throw std::runtime_error(
"Conversion to half failed");
175 #if defined HALF_HALF_HPP 191 class error :
public std::runtime_error
194 explicit error(
const std::string& _Message, status_t
status = CLDNN_ERROR)
195 : runtime_error(_Message)
200 explicit error(
const char* _Message, status_t
status = CLDNN_ERROR)
201 : runtime_error(_Message)
207 const status_t&
status()
const {
return _status; }
212 #define CLDNN_THROW(msg, status) throw cldnn::error(msg, status); 215 T check_status(std::string err_msg, std::function<T(status_t*)> func)
217 status_t status = CLDNN_SUCCESS;
218 auto result = func(&status);
219 if (status != CLDNN_SUCCESS)
225 inline void check_status<void>(std::string err_msg, std::function<void(status_t*)> func)
227 status_t status = CLDNN_SUCCESS;
229 if (status != CLDNN_SUCCESS)
243 return check_status<version_t>(
"get_version: fetching version information failed",
246 return ::cldnn_get_version(status);
257 #define CLDNN_API_CLASS(the_class) static_assert(std::is_standard_layout<the_class>::value, #the_class " has to be 'standart layout' class"); 261 typename std::enable_if<std::is_integral<T>::value, T>::type align_to(T size,
size_t align) {
262 return static_cast<T
>((size % align == 0) ? size : size - size % align + align);
266 typename std::enable_if<std::is_integral<T>::value, T>::type pad_to(T size,
size_t align) {
267 return static_cast<T
>((size % align == 0) ? 0 : align - size % align);
271 typename std::enable_if<std::is_integral<T>::value,
bool>::type is_aligned_to(T size,
size_t align)
273 return !(size % align);
290 template <
typename T1,
typename T2>
291 constexpr
auto ceil_div(T1 val, T2 divider)
292 ->
typename std::enable_if<std::is_integral<T1>::value && std::is_integral<T2>::value,
293 decltype(std::declval<
typename std::make_unsigned<T1>::type>() / std::declval<
typename std::make_unsigned<T2>::type>())>::type
295 typedef typename std::make_unsigned<T1>::type UT1;
296 typedef typename std::make_unsigned<T2>::type UT2;
297 typedef decltype(std::declval<UT1>() / std::declval<UT2>()) RetT;
299 return static_cast<RetT>((static_cast<UT1>(val) + static_cast<UT2>(divider) - 1U) / static_cast<UT2>(divider));
315 template <typename T1, typename T2>
316 constexpr auto round_up_to(T1 val, T2 rounding)
317 -> typename
std::enable_if<
std::is_integral<T1>::value &&
std::is_integral<T2>::value,
318 decltype(
std::declval<typename
std::make_unsigned<T1>::type>() /
std::declval<typename
std::make_unsigned<T2>::type>())>::type
320 typedef typename std::make_unsigned<T1>::type UT1;
321 typedef typename std::make_unsigned<T2>::type UT2;
322 typedef decltype(std::declval<UT1>() / std::declval<UT2>()) RetT;
324 return static_cast<RetT>(ceil_div(val, rounding) * static_cast<UT2>(rounding));
332 std::vector<float> result(arr.size);
333 for (
size_t i = 0; i < arr.size; i++)
335 result[i] = arr.data[i];
345 std::vector<uint16_t> result(arr.
size);
346 for (
size_t i = 0; i < arr.
size; i++)
348 result[i] = arr.
data[i];
357 inline cldnn_float_arr float_vector_to_arr(
const std::vector<float>& stor)
359 return { stor.
data(), stor.size() };
367 return{ stor.
data(), stor.size() };
373 inline cldnn_tensor_arr tensor_vector_to_arr(
const std::vector<cldnn_tensor>& stor)
Represents reference to an array of uint16_t.
CLDNN_API uint16_t cldnn_float_to_half(float, cldnn_status *)
converts float(32 bit) to half_t(fp16 bit)
const status_t & status() const
Returns clDNN status code.
const float * data
Pointer to float array.
Represents reference to an array of tensor.
Represents reference to an array of floats.
CLDNN_API const char * cldnn_get_last_error_message()
If cldnn function returns status different than CLDNN_SUCCESS, user call this function to get more de...
version_t get_version()
Get information about version of clDNN.
size_t size
Size (in uint16_t) of the array.
Provides input data to topology.
int32_t cldnn_status
Represents errors status for all API calls.
const cldnn_tensor * data
Pointer to tensor array.
clDNN specific exception type.
CLDNN_API float cldnn_half_to_float(uint16_t, cldnn_status *)
converts half_t(f16 bit) to float(32 bit)
const uint16_t * data
Pointer to uint16_t array.