|
| 1 | +//===- dpctl_exec_state.h - C API for service functions -*-C++-*- ===// |
| 2 | +// |
| 3 | +// Data Parallel Control (dpctl) |
| 4 | +// |
| 5 | +// Copyright 2020-2021 Intel Corporation |
| 6 | +// |
| 7 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +// you may not use this file except in compliance with the License. |
| 9 | +// You may obtain a copy of the License at |
| 10 | +// |
| 11 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +// |
| 13 | +// Unless required by applicable law or agreed to in writing, software |
| 14 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +// See the License for the specific language governing permissions and |
| 17 | +// limitations under the License. |
| 18 | +// |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | +/// |
| 21 | +/// \file |
| 22 | +/// The file declares a struct to store dpctl's error handler and other |
| 23 | +/// execution state configurations. |
| 24 | +/// |
| 25 | +//===----------------------------------------------------------------------===// |
| 26 | + |
| 27 | +#pragma once |
| 28 | + |
| 29 | +#include "Support/DllExport.h" |
| 30 | +#include "Support/ExternC.h" |
| 31 | +#include "Support/MemOwnershipAttrs.h" |
| 32 | +#include "dpctl_error_handler_type.h" |
| 33 | + |
| 34 | +DPCTL_C_EXTERN_C_BEGIN |
| 35 | + |
| 36 | +/*! |
| 37 | + * @brief An opaque type to represent an "execution state" for the dpctl |
| 38 | + * sycl interface library. |
| 39 | + * |
| 40 | + * The execution state controls the behavior of functions exposed by |
| 41 | + * libDPCTLSyclInterface. For now, only error handling is controlled by an |
| 42 | + * execution state. Using a custom execution state, users can define how |
| 43 | + * exceptions in the C++ code are handled and propagated to callers. A default |
| 44 | + * execution state where all exceptions are caught and the error messages |
| 45 | + * printed to ``std::cerr`` is included for convenience. |
| 46 | + * |
| 47 | + */ |
| 48 | +typedef struct DpctlExecutionState *DpctlExecState; |
| 49 | + |
| 50 | +/*! |
| 51 | + * @brief Create a new ``DpctlExecState`` object. |
| 52 | + * |
| 53 | + * @param handler An error handler function. |
| 54 | + * @return A ``DpctlExecState`` opaque pointer. |
| 55 | + */ |
| 56 | +__dpctl_give DpctlExecState |
| 57 | +dpctl_exec_state_create(error_handler_callback_fn handler); |
| 58 | + |
| 59 | +/*! |
| 60 | + * @brief Create a default execution state that prints the error message to |
| 61 | + * ``std::cerr``. |
| 62 | + * |
| 63 | + * @return A ``DpctlExecState`` opaque pointer. |
| 64 | + */ |
| 65 | +__dpctl_give DpctlExecState dpctl_exec_state_create_default(); |
| 66 | + |
| 67 | +/*! |
| 68 | + * @brief Delete an ``DpctlExecState`` opaque pointer. |
| 69 | + * |
| 70 | + * @param DpctlExecState A ``DpctlExecState`` opaque pointer to be freed. |
| 71 | + */ |
| 72 | +void dpctl_exec_state_delete(__dpctl_take DpctlExecState state); |
| 73 | + |
| 74 | +/*! |
| 75 | + * @brief Get the error handler defined in the ``DpctlExecState`` object. |
| 76 | + * |
| 77 | + * @param state An ``DpctlExecState`` object. |
| 78 | + * @return A error_handler_callback_fn function pointer that was stored inside |
| 79 | + * the DpctlExecState object. |
| 80 | + */ |
| 81 | +error_handler_callback_fn |
| 82 | +dpctl_exec_state_get_error_handler(__dpctl_keep DpctlExecState state); |
| 83 | + |
| 84 | +/*! |
| 85 | + * @brief Call the error handler defined in the ``DpctlExecState`` object. |
| 86 | + * |
| 87 | + * @param state An ``DpctlExecState`` object. |
| 88 | + * @param err_code An integer error code. |
| 89 | + * @param err_msg A C string corresponding to an error message. |
| 90 | + * @param file_name The file where the error occurred. |
| 91 | + * @param func_name The function name where the error occurred. |
| 92 | + * @param line_num The line number where the error occurred. |
| 93 | + */ |
| 94 | +void dpctl_exec_state_handle_error(__dpctl_keep DpctlExecState state, |
| 95 | + int err_code, |
| 96 | + __dpctl_keep const char *err_msg, |
| 97 | + __dpctl_keep const char *file_name, |
| 98 | + __dpctl_keep const char *func_name, |
| 99 | + int line_num); |
| 100 | + |
| 101 | +DPCTL_C_EXTERN_C_END |
0 commit comments