Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dpctl/_backend.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,11 @@ cdef extern from "dpctl_sycl_platform_interface.h":
cdef extern from "dpctl_sycl_context_interface.h":
cdef DPCTLSyclContextRef DPCTLContext_Create(
const DPCTLSyclDeviceRef DRef,
error_handler_callback *error_handler,
error_handler_callback *handler,
int properties)
cdef DPCTLSyclContextRef DPCTLContext_CreateFromDevices(
const DPCTLDeviceVectorRef DVRef,
error_handler_callback *error_handler,
error_handler_callback *handler,
int properties)
cdef DPCTLSyclContextRef DPCTLContext_Copy(
const DPCTLSyclContextRef CRef)
Expand Down Expand Up @@ -323,7 +323,7 @@ cdef extern from "dpctl_sycl_queue_interface.h":
cdef DPCTLSyclQueueRef DPCTLQueue_Create(
const DPCTLSyclContextRef CRef,
const DPCTLSyclDeviceRef DRef,
error_handler_callback *error_handler,
error_handler_callback *handler,
int properties)
cdef DPCTLSyclQueueRef DPCTLQueue_CreateForDevice(
const DPCTLSyclDeviceRef dRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,22 @@ class DPCTL_API DPCTL_AsyncErrorHandler

void operator()(const cl::sycl::exception_list &exceptions);
};

enum error_level : int
{
none = 0,
error = 1,
warning = 2
};

void error_handler(const std::exception &e,
const char *file_name,
const char *func_name,
int line_num,
error_level error_type = error_level::error);

void error_handler(const std::string &what,
const char *file_name,
const char *func_name,
int line_num,
error_level error_type = error_level::warning);
6 changes: 3 additions & 3 deletions libsyclinterface/helper/include/dpctl_string_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/// \file
/// Helper function to convert a C++ string to a C string.
//===----------------------------------------------------------------------===//
#include "../helper/include/dpctl_error_handlers.h"
#include <cstring>
#include <iostream>
#include <string>
Expand Down Expand Up @@ -55,9 +56,8 @@ cstring_from_string(const std::string &str)
// to be null-terminated and the copy function is asked to
// copy enough characters to include that null-character.
cstr[cstr_len - 1] = '\0';
} catch (std::bad_alloc const &ba) {
// \todo log error
std::cerr << ba.what() << '\n';
} catch (std::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
}

return cstr;
Expand Down
42 changes: 0 additions & 42 deletions libsyclinterface/helper/source/dpctl_async_error_handler.cpp

This file was deleted.

89 changes: 89 additions & 0 deletions libsyclinterface/helper/source/dpctl_error_handlers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//===-- dpctl_async_error_handler.h - An async error handler -*-C++-*- ===//
//
// Data Parallel Control (dpctl)
//
// Copyright 2020-2021 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//===----------------------------------------------------------------------===//
///
/// \file
/// A functor to use for passing an error handler callback function to sycl
/// context and queue contructors.
//===----------------------------------------------------------------------===//

#include "dpctl_error_handlers.h"
#include <cstring>

void DPCTL_AsyncErrorHandler::operator()(
const cl::sycl::exception_list &exceptions)
{
for (std::exception_ptr const &e : exceptions) {
try {
std::rethrow_exception(e);
} catch (sycl::exception const &e) {
error_handler(e, __FILE__, __func__, __LINE__);
auto err_code = e.get_cl_code();
handler_(static_cast<int>(err_code));
}
}
}

inline int get_requested_level(void)
{
int requested_level = 0;

const char *verbose = std::getenv("DPCTL_VERBOSITY");

if (verbose) {
if (!strncmp(verbose, "none", 4))
requested_level = error_level::none;
else if (!strncmp(verbose, "error", 5))
requested_level = error_level::error;
else if (!strncmp(verbose, "warning", 7))
requested_level = error_level::warning;
}

return requested_level;
}

void error_handler(const std::exception &e,
const char *file_name,
const char *func_name,
int line_num,
error_level error_type)
{
int requested_level = get_requested_level();
int error_level = static_cast<int>(error_type);

if (requested_level <= error_level) {
std::cerr << e.what() << " in " << func_name << " at " << file_name
<< ":" << line_num << std::endl;
}
}

void error_handler(const std::string &what,
const char *file_name,
const char *func_name,
int line_num,
error_level error_type)
{
int error_level = static_cast<int>(error_type);
int requested_level = get_requested_level();

if (requested_level <= error_level) {
std::cerr << what << " In " << func_name << " at " << file_name << ":"
<< line_num << std::endl;
}
}
8 changes: 4 additions & 4 deletions libsyclinterface/include/dpctl_sycl_context_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ DPCTL_C_EXTERN_C_BEGIN
* optional async error handler and properties bit flags.
*
* @param DRef Opaque pointer to a SYCL device.
* @param error_handler A callback function that will be invoked by the
* @param handler A callback function that will be invoked by the
* async_handler used during context creation. Can be
* NULL if no async_handler is needed.
* @param properties An optional combination of bit flags to define
Expand All @@ -58,7 +58,7 @@ DPCTL_C_EXTERN_C_BEGIN
DPCTL_API
__dpctl_give DPCTLSyclContextRef
DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef,
error_handler_callback *error_handler,
error_handler_callback *handler,
int properties);

/*!
Expand All @@ -67,7 +67,7 @@ DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef,
*
* @param DVRef An opaque pointer to a std::vector of
* DPCTLSyclDeviceRef opaque pointers.
* @param error_handler A callback function that will be invoked by the
* @param handler A callback function that will be invoked by the
* async_handler used during context creation. Can be
* NULL if no async_handler is needed.
* @param properties An optional combination of bit flags to define
Expand All @@ -79,7 +79,7 @@ DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef,
DPCTL_API
__dpctl_give DPCTLSyclContextRef
DPCTLContext_CreateFromDevices(__dpctl_keep const DPCTLDeviceVectorRef DVRef,
error_handler_callback *error_handler,
error_handler_callback *handler,
int properties);

/*!
Expand Down
8 changes: 4 additions & 4 deletions libsyclinterface/include/dpctl_sycl_queue_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DPCTL_C_EXTERN_C_BEGIN
*
* @param CRef An opaque pointer to a sycl::context.
* @param DRef An opaque pointer to a sycl::device
* @param error_handler A callback function that will be invoked by the
* @param handler A callback function that will be invoked by the
* async_handler used during queue creation. Can be
* NULL if no async_handler is needed.
* @param properties A combination of bit flags using the values defined
Expand All @@ -62,7 +62,7 @@ DPCTL_API
__dpctl_give DPCTLSyclQueueRef
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
__dpctl_keep const DPCTLSyclDeviceRef DRef,
error_handler_callback *error_handler,
error_handler_callback *handler,
int properties);

/*!
Expand All @@ -86,7 +86,7 @@ DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
* function begaves the same way as the SYCL constructor.
*
* @param dRef An opaque pointer to a ``sycl::device``.
* @param error_handler A callback function that will be invoked by the
* @param handler A callback function that will be invoked by the
* async_handler used during queue creation. Can be
* NULL if no async_handler is needed.
* @param properties A combination of bit flags using the values defined
Expand All @@ -101,7 +101,7 @@ DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
DPCTL_API
__dpctl_give DPCTLSyclQueueRef
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef dRef,
error_handler_callback *error_handler,
error_handler_callback *handler,
int properties);

/*!
Expand Down
Loading