Skip to content

Update sycl interface library to use SYCL 2020 exceptions #628

Closed

Description

@oleksandr-pavlyk
// a.cpp
#include <CL/sycl.hpp>
#include <iostream>

int main(void) {
  sycl::device d;

  try {
     sycl::device pd = d.get_info<sycl::info::device::parent_device>();
  } catch (const sycl::runtime_error &re) {
     std::cerr << "No parent" << std::endl;
  }
  return 0;
}

Compiling this with clang++ -fsycl a.cpp generates lots of SYCL_2020 deprecation warnings.

A way to change this code to conform to SYCL 2020 spec is as follows:

// a_sycl2020_conformant.cpp
#include <CL/sycl.hpp>
#include <iostream>

int main(void) {
  sycl::device d;

  try {
     sycl::device pd = d.get_info<sycl::info::device::parent_device>();
  } catch (const sycl::exception &e) {
     if (e.category() == sycl::sycl_category() && e.code() == sycl::errc::runtime) {
        std::cerr << "No parent" << std::endl;
     } else {
        std::cerr << "Unknown exception occurred: " << ex.what() << std::endl;
        std::terminate();
     }
  }
  return 0;
}

Activity

  1. oleksandr-pavlyk commented on Oct 13, 2021

    @oleksandr-pavlyk
    ContributorAuthor

    This is consistent with example code snippet from SYCL-2020 spec repo, https://github.com/KhronosGroup/SYCL-Docs/blob/SYCL-2020/master/adoc/code/handlingException.cpp

  2. oleksandr-pavlyk commented on Dec 4, 2021

    @oleksandr-pavlyk
    ContributorAuthor

    This is done via #683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions