2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 ///////////////////////////////////////////////////////////////////////////////////////////////////
20 #include "api/C/cldnn.h"
21 #include "api/CPP/cldnn_defs.h"
27 #define API_CAST(api_type, impl_type) \
28 inline api_type api_cast(impl_type* value) { return reinterpret_cast<api_type>(value); } \
29 inline impl_type* api_cast(api_type value) { return reinterpret_cast<impl_type*>(value); }
33 /// @breif Sets the message of last error
34 void set_last_error_message(const std::string& msg) { _msg = msg; }
36 void set_last_exception(const std::exception& ex) { _msg = ex.what(); }
38 /// @breif Gets the message of last error
39 const std::string& get_last_error_message() { return _msg; }
40 static last_err& instance();
44 last_err() : _msg("Operation succeed") {}
47 // float <--> half convertors
48 float half_to_float(uint16_t value);
49 uint16_t float_to_half(float value);
53 T exception_handler(cldnn_status default_error,
55 const T& default_result,
56 std::function<T()> func) {
57 // NOTE for implementer: status should not be modified after successful func() call
60 *status = CLDNN_SUCCESS;
62 } catch (const cldnn::error& err) {
64 *status = err.status();
65 cldnn::last_err::instance().set_last_exception(err);
68 static_cast<void>(default_result);
71 } catch (const std::exception& err) {
73 *status = default_error;
74 cldnn::last_err::instance().set_last_exception(err);
77 static_cast<void>(default_result);
82 *status = default_error;
83 cldnn::last_err::instance().set_last_error_message("error unknown");
86 static_cast<void>(default_result);
92 return default_result;
96 inline void exception_handler(cldnn_status default_error, cldnn_status* status, std::function<void()> func) {
97 // NOTE for implementer: status should not be modified after successful func() call
100 *status = CLDNN_SUCCESS;
102 } catch (const cldnn::error& err) {
104 *status = err.status();
105 cldnn::last_err::instance().set_last_exception(err);
109 } catch (const std::exception& err) {
111 *status = default_error;
112 cldnn::last_err::instance().set_last_exception(err);
119 *status = default_error;
120 cldnn::last_err::instance().set_last_error_message("error unknown");