Skip to content

Commit daaec1a

Browse files
author
Diptorup Deb
committed
Initial stubs for the error handling overhaul.
1 parent 49ded41 commit daaec1a

File tree

4 files changed

+183
-2
lines changed

4 files changed

+183
-2
lines changed

dpctl-capi/include/dpctl_error_handler_type.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@
3232
* @param err_code Error code extracted from an SYCL asynchronous
3333
* error.
3434
*/
35-
typedef void error_handler_callback(int err_code);
35+
typedef void error_handler_callback(int err_code) __attribute__((
36+
deprecated("the function does not allow passing in an error string, use "
37+
"'error_handler_callback_fn' instead!!!")));
38+
39+
/*!
40+
* @brief Type signature required for an error handler callback function.
41+
*
42+
* @param err_code My Param doc
43+
* @param err_msg My Param doc
44+
*/
45+
typedef void (*error_handler_callback_fn)(int err_code, const char *err_msg);
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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
38+
*
39+
*/
40+
typedef struct DpctlExecutionState *DpctlExecState;
41+
42+
/*!
43+
* @brief
44+
*
45+
* @param handler My Param doc
46+
* @return {return} My Param doc
47+
*/
48+
__dpctl_give DpctlExecState
49+
dpctl_exec_state_create(const error_handler_callback_fn handler);
50+
51+
/*!
52+
* @brief
53+
*
54+
* @return {return} My Param doc
55+
*/
56+
__dpctl_give DpctlExecState dpctl_exec_state_create_default();
57+
58+
/*!
59+
* @brief
60+
*
61+
* @param DpctlExecState My Param doc
62+
*/
63+
void dpctl_exec_state_delete(__dpctl_take DpctlExecState state);
64+
65+
DPCTL_C_EXTERN_C_END

dpctl-capi/include/dpctl_service.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
//===----------------------------------------------------------------------===//
2020
///
2121
/// \file
22-
/// This header defines dpctl service functions.
22+
/// This header declares dpctl service functions.
2323
///
2424
//===----------------------------------------------------------------------===//
2525

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//===- dpctl_exec_state.cpp - Implements C API for sycl::context ---==//
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+
/// This file implements the data types and functions declared in
23+
/// dpctl_exec_state.h.
24+
///
25+
//===----------------------------------------------------------------------===//
26+
27+
#include "dpctl_exec_state.h"
28+
#include "Support/CBindingWrapping.h"
29+
#include <iostream>
30+
31+
namespace
32+
{
33+
34+
/*!
35+
* @brief
36+
*
37+
* @param err_code My Param doc
38+
* @param err_msg My Param doc
39+
*/
40+
void default_handler(int err_code, const char *err_msg)
41+
{
42+
std::cerr << "DPCTL-ERROR (" << err_code << ") " << err_msg;
43+
}
44+
45+
/*!
46+
* @brief
47+
*
48+
*/
49+
class ExecutionState
50+
{
51+
const error_handler_callback_fn handler_;
52+
53+
public:
54+
ExecutionState() : handler_(default_handler){};
55+
ExecutionState(const error_handler_callback_fn handler) : handler_(handler)
56+
{
57+
}
58+
};
59+
60+
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionState, DpctlExecState);
61+
62+
} // namespace
63+
64+
/*!
65+
* @brief
66+
*
67+
* @param handler My Param doc
68+
* @return {return} My Param doc
69+
*/
70+
__dpctl_give DpctlExecState
71+
dpctl_exec_state_create(const error_handler_callback_fn handler)
72+
{
73+
try {
74+
ExecutionState *state = new ExecutionState(handler);
75+
return wrap(state);
76+
} catch (std::bad_alloc const &ba) {
77+
std::cerr << ba.what() << '\n';
78+
std::terminate();
79+
}
80+
}
81+
82+
/*!
83+
* @brief
84+
*
85+
* @return {return} My Param doc
86+
*/
87+
__dpctl_give DpctlExecState dpctl_exec_state_create_default()
88+
{
89+
try {
90+
ExecutionState *state = new ExecutionState();
91+
return wrap(state);
92+
} catch (std::bad_alloc const &ba) {
93+
std::cerr << ba.what() << '\n';
94+
std::terminate();
95+
}
96+
}
97+
98+
/*!
99+
* @brief
100+
*
101+
* @param DpctlExecState My Param doc
102+
*/
103+
void dpctl_exec_state_delete(__dpctl_take DpctlExecState state)
104+
{
105+
delete unwrap(state);
106+
}

0 commit comments

Comments
 (0)