Skip to content

Commit

Permalink
user platform / device configuration; sycl exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Dec 14, 2023
1 parent cecd313 commit 1cce5b8
Show file tree
Hide file tree
Showing 21 changed files with 1,116 additions and 147 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add_library(simsycl
include/CL/sycl.hpp
include/simsycl/sycl.hh
include/simsycl/detail/allocation.hh
include/simsycl/detail/async_handler.hh
include/simsycl/detail/check.hh
include/simsycl/detail/config.hh
include/simsycl/detail/coordinate.hh
Expand All @@ -53,6 +54,7 @@ add_library(simsycl
include/simsycl/sycl/atomic_ref.hh
include/simsycl/sycl/backend.hh
include/simsycl/sycl/buffer.hh
include/simsycl/sycl/bundle.hh
include/simsycl/sycl/concepts.hh
include/simsycl/sycl/context.hh
include/simsycl/sycl/device.hh
Expand Down Expand Up @@ -82,8 +84,14 @@ add_library(simsycl
include/simsycl/sycl/type_traits.hh
include/simsycl/sycl/usm.hh
include/simsycl/sycl/vec.hh
include/simsycl/system.hh
include/simsycl/templates.hh
"${CMAKE_CURRENT_BINARY_DIR}/include/simsycl/config.hh"
src/simsycl/simsycl.cc
src/simsycl/context.cc
src/simsycl/device.cc
src/simsycl/platform.cc
src/simsycl/system.cc
src/simsycl/templates.cc
)
target_link_libraries(simsycl Boost::context)
target_include_directories(simsycl PUBLIC
Expand Down
2 changes: 2 additions & 0 deletions include/simsycl/detail/reference_type.hh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "check.hh"

#include <memory>

namespace simsycl::detail {
Expand Down
33 changes: 0 additions & 33 deletions include/simsycl/detail/system.hh

This file was deleted.

1 change: 1 addition & 0 deletions include/simsycl/sycl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "sycl/atomic_ref.hh"
#include "sycl/backend.hh"
#include "sycl/buffer.hh"
#include "sycl/bundle.hh"
#include "sycl/context.hh"
#include "sycl/device.hh"
#include "sycl/enums.hh"
Expand Down
28 changes: 28 additions & 0 deletions include/simsycl/sycl/async_handler.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <exception>
#include <functional>
#include <vector>


namespace simsycl::sycl {

class exception_list : private std::vector<std::exception_ptr> {
// Used as a container for a list of asynchronous exceptions
public:
using value_type = std::exception_ptr;
using reference = value_type &;
using const_reference = const value_type &;
using size_type = std::size_t;

using std::vector<std::exception_ptr>::const_iterator;
using iterator = const_iterator;

using std::vector<std::exception_ptr>::size;
iterator begin() const { return std::vector<std::exception_ptr>::begin(); }
iterator end() const { return std::vector<std::exception_ptr>::end(); }
};

using async_handler = std::function<void(sycl::exception_list)>;

}
99 changes: 99 additions & 0 deletions include/simsycl/sycl/bundle.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#pragma once

#include "enums.hh"
#include "forward.hh"
#include "property.hh"

#include <vector>


namespace simsycl::sycl {

class kernel_id { /* ... */
};

template<bundle_state State>
class kernel_bundle { /* ... */
};

template<typename KernelName>
kernel_id get_kernel_id();

std::vector<kernel_id> get_kernel_ids();

template<bundle_state State>
kernel_bundle<State> get_kernel_bundle(const context &ctxt);

template<bundle_state State>
kernel_bundle<State> get_kernel_bundle(const context &ctxt, const std::vector<kernel_id> &kernel_ids);

template<typename KernelName, bundle_state State>
kernel_bundle<State> get_kernel_bundle(const context &ctxt);

template<bundle_state State>
kernel_bundle<State> get_kernel_bundle(const context &ctxt, const std::vector<device> &devs);

template<bundle_state State>
kernel_bundle<State> get_kernel_bundle(
const context &ctxt, const std::vector<device> &devs, const std::vector<kernel_id> &kernel_ids);

template<typename KernelName, bundle_state State>
kernel_bundle<State> get_kernel_bundle(const context &ctxt, const std::vector<device> &devs);

template<bundle_state State, typename Selector>
kernel_bundle<State> get_kernel_bundle(const context &ctxt, Selector selector);

template<bundle_state State, typename Selector>
kernel_bundle<State> get_kernel_bundle(const context &ctxt, const std::vector<device> &devs, Selector selector);

template<bundle_state State>
bool has_kernel_bundle(const context &ctxt);

template<bundle_state State>
bool has_kernel_bundle(const context &ctxt, const std::vector<kernel_id> &kernel_ids);

template<typename KernelName, bundle_state State>
bool has_kernel_bundle(const context &ctxt);

template<bundle_state State>
bool has_kernel_bundle(const context &ctxt, const std::vector<device> &devs);

template<bundle_state State>
bool has_kernel_bundle(const context &ctxt, const std::vector<device> &devs, const std::vector<kernel_id> &kernel_ids);

template<typename KernelName, bundle_state State>
bool has_kernel_bundle(const context &ctxt, const std::vector<device> &devs);

bool is_compatible(const std::vector<kernel_id> &kernel_ids, const device &dev);

template<typename KernelName>
bool is_compatible(const device &dev);

template<bundle_state State>
kernel_bundle<State> join(const std::vector<kernel_bundle<State>> &bundles);

kernel_bundle<bundle_state::object> compile(
const kernel_bundle<bundle_state::input> &input_bundle, const property_list &prop_list = {});

kernel_bundle<bundle_state::object> compile(const kernel_bundle<bundle_state::input> &input_bundle,
const std::vector<device> &devs, const property_list &prop_list = {});

kernel_bundle<bundle_state::executable> link(
const kernel_bundle<bundle_state::object> &object_bundle, const property_list &prop_list = {});

kernel_bundle<bundle_state::executable> link(
const std::vector<kernel_bundle<bundle_state::object>> &object_bundles, const property_list &prop_list = {});

kernel_bundle<bundle_state::executable> link(const kernel_bundle<bundle_state::object> &object_bundle,
const std::vector<device> &devs, const property_list &prop_list = {});

kernel_bundle<bundle_state::executable> link(const std::vector<kernel_bundle<bundle_state::object>> &object_bundles,
const std::vector<device> &devs, const property_list &prop_list = {});

kernel_bundle<bundle_state::executable> build(
const kernel_bundle<bundle_state::input> &input_bundle, const property_list &prop_list = {});

kernel_bundle<bundle_state::executable> build(const kernel_bundle<bundle_state::input> &input_bundle,
const std::vector<device> &devs, const property_list &prop_list = {});

} // namespace simsycl::sycl
6 changes: 3 additions & 3 deletions include/simsycl/sycl/context.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "exception.hh"
#include "async_handler.hh"
#include "forward.hh"
#include "property.hh"

Expand All @@ -9,13 +9,13 @@

namespace simsycl::detail {

struct context_state {};
struct context_state;

} // namespace simsycl::detail

namespace simsycl::sycl {

class context : public detail::reference_type<context, detail::context_state>, public detail::property_interface {
class context final : public detail::reference_type<context, detail::context_state>, public detail::property_interface {
private:
using reference_type = detail::reference_type<context, detail::context_state>;
using property_compatibilty
Expand Down
43 changes: 19 additions & 24 deletions include/simsycl/sycl/device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
#include "enums.hh"
#include "forward.hh"
#include "info.hh"
#include "platform.hh"

#include "../detail/reference_type.hh"

#include <string>
#include <vector>


namespace simsycl::detail {
namespace simsycl {

struct device_config;

// forward
void setup();
sycl::device create_device(sycl::platform &platform, const device_config &config);

template<typename DeviceSelector>
sycl::device select_device(const DeviceSelector &selector);
}

namespace simsycl::detail {

struct default_selector {
int operator()(const sycl::device & /* TODO */) const { return 0; }
Expand All @@ -26,9 +27,7 @@ struct cpu_selector : public default_selector {}; // TODO
struct gpu_selector : public default_selector {}; // TODO
struct accelerator_selector : public default_selector {}; // TODO

struct device_state {
sycl::platform platform;
};
struct device_state;

} // namespace simsycl::detail

Expand All @@ -55,33 +54,29 @@ auto aspect_selector(AspectList... aspect_list);
template<aspect... AspectList>
auto aspect_selector();

class device : public detail::reference_type<device, detail::device_state> {
class device final : public detail::reference_type<device, detail::device_state> {
private:
using reference_type = detail::reference_type<device, detail::device_state>;

public:
device() : device(default_selector_v) {}
device();

template<typename DeviceSelector>
explicit device(const DeviceSelector &device_selector) : device(select_device(device_selector)) {}
explicit device(const DeviceSelector &device_selector);

bool is_cpu() const;
bool is_cpu() const { return has(aspect::cpu); }

bool is_gpu() const;
bool is_gpu() const { return has(aspect::gpu); }

bool is_accelerator() const;
bool is_accelerator() const { return has(aspect::accelerator); }

platform get_platform() const { return state().platform; }
platform get_platform() const;

template<typename Param>
typename Param::return_type get_info() const {
return {};
}
typename Param::return_type get_info() const;

template<typename Param>
typename Param::return_type get_backend_info() const {
return {};
}
typename Param::return_type get_backend_info() const;

bool has(aspect asp) const;

Expand All @@ -102,9 +97,9 @@ class device : public detail::reference_type<device, detail::device_state> {
static std::vector<device> get_devices(info::device_type device_type = info::device_type::all);

private:
friend void detail::setup();
friend device simsycl::create_device(sycl::platform &platform, const device_config &config);

device(detail::device_state state) : reference_type(std::in_place, std::move(state)) {}
device(detail::device_state state);
};

template<aspect Aspect>
Expand Down
2 changes: 1 addition & 1 deletion include/simsycl/sycl/enums.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum class aspect {
usm_system_allocations
};

enum class backend {};
enum class backend { simsycl };

enum class bundle_state { input, object, executable };

Expand Down
Loading

0 comments on commit 1cce5b8

Please sign in to comment.