Skip to content

Commit a592ba8

Browse files
author
Diptorup Deb
committed
Demonstrate how the new error handler is supposed to be used.
1 parent 9bff046 commit a592ba8

File tree

2 files changed

+41
-11
lines changed

2 files changed

+41
-11
lines changed

dpctl-capi/include/dpctl_sycl_device_interface.h

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,18 @@
3131
#include "Support/ExternC.h"
3232
#include "Support/MemOwnershipAttrs.h"
3333
#include "dpctl_data_types.h"
34+
#include "dpctl_exec_state.h"
3435
#include "dpctl_sycl_device_manager.h"
3536
#include "dpctl_sycl_enum_types.h"
3637
#include "dpctl_sycl_types.h"
3738

3839
DPCTL_C_EXTERN_C_BEGIN
3940

41+
#define DEPRACATION_NOTICE \
42+
"The function is deprecated to change the naming convention and " \
43+
"support the new DpctlExecState argument to improve error " \
44+
"handling and reporting."
45+
4046
/**
4147
* @defgroup DeviceInterface Device class C wrapper
4248
*/
@@ -49,20 +55,33 @@ DPCTL_C_EXTERN_C_BEGIN
4955
* DPCTLSyclDeviceRef object.
5056
* @ingroup DeviceInterface
5157
*/
58+
DPCTL_API __dpctl_give DPCTLSyclDeviceRef
59+
DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef)
60+
__attribute__((deprecated(DEPRACATION_NOTICE, "dpctl_device_copy")));
61+
62+
/*!
63+
* @brief Returns a copy of the DPCTLSyclDeviceRef object.
64+
*
65+
* @param ES The execution state object used for error handling.
66+
* @param DRef DPCTLSyclDeviceRef object to be copied.
67+
* @return A new DPCTLSyclDeviceRef created by copying the passed in
68+
* DPCTLSyclDeviceRef object.
69+
* @ingroup DeviceInterface
70+
*/
5271
DPCTL_API
5372
__dpctl_give DPCTLSyclDeviceRef
54-
DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef);
73+
dpctl_device_copy(__dpctl_keep const DPCTLSyclDeviceRef DRef,
74+
__dpctl_keep const DpctlExecState ES);
5575

5676
/*!
57-
* @brief Returns a new DPCTLSyclDeviceRef opaque object wrapping a SYCL device
58-
* instance as a host device.
77+
* @brief Returns a new DPCTLSyclDeviceRef opaque object wrapping a SYCL
78+
* device instance as a host device.
5979
*
60-
* @return An opaque pointer to a ``sycl::device`` created as an instance of
61-
* the host device.
80+
* @return An opaque pointer to a ``sycl::device`` created as an instance
81+
* of the host device.
6282
* @ingroup DeviceInterface
6383
*/
64-
DPCTL_API
65-
__dpctl_give DPCTLSyclDeviceRef DPCTLDevice_Create(void);
84+
DPCTL_API __dpctl_give DPCTLSyclDeviceRef DPCTLDevice_Create(void);
6685

6786
/*!
6887
* @brief Returns a new DPCTLSyclDeviceRef opaque object created using the

dpctl-capi/source/dpctl_sycl_device_interface.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
//===----------------------------------------------------------------------===//
2626

2727
#include "dpctl_sycl_device_interface.h"
28+
#include "../helper/include/dpctl_error_handlers.h"
2829
#include "../helper/include/dpctl_string_utils.hpp"
2930
#include "../helper/include/dpctl_utils_helper.h"
3031
#include "Support/CBindingWrapping.h"
@@ -44,23 +45,33 @@ DEFINE_SIMPLE_CONVERSION_FUNCTIONS(device_selector, DPCTLSyclDeviceSelectorRef)
4445
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(platform, DPCTLSyclPlatformRef)
4546
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(std::vector<DPCTLSyclDeviceRef>,
4647
DPCTLDeviceVectorRef)
47-
4848
} /* end of anonymous namespace */
4949

5050
__dpctl_give DPCTLSyclDeviceRef
5151
DPCTLDevice_Copy(__dpctl_keep const DPCTLSyclDeviceRef DRef)
5252
{
53+
return dpctl_device_copy(DRef, nullptr);
54+
}
55+
56+
__dpctl_give DPCTLSyclDeviceRef
57+
dpctl_device_copy(__dpctl_keep const DPCTLSyclDeviceRef DRef,
58+
__dpctl_keep const DpctlExecState ES)
59+
{
60+
auto handler = ES ? dpctl_exec_state_get_error_handler(ES)
61+
: &DefaultErrorHandler::handler;
62+
5363
auto Device = unwrap(DRef);
64+
5465
if (!Device) {
55-
std::cerr << "Cannot copy DPCTLSyclDeviceRef as input is a nullptr\n";
66+
handler(-1, "Cannot copy DPCTLSyclDeviceRef as input is a nullptr.",
67+
__FILE__, __func__, __LINE__);
5668
return nullptr;
5769
}
5870
try {
5971
auto CopiedDevice = new device(*Device);
6072
return wrap(CopiedDevice);
6173
} catch (std::bad_alloc const &ba) {
62-
// \todo log error
63-
std::cerr << ba.what() << '\n';
74+
handler(-1, ba.what(), __FILE__, __func__, __LINE__);
6475
return nullptr;
6576
}
6677
}

0 commit comments

Comments
 (0)