Skip to content

Commit

Permalink
context, queue constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Dec 14, 2023
1 parent 1cce5b8 commit 5570aea
Show file tree
Hide file tree
Showing 22 changed files with 438 additions and 121 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ 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 @@ -51,6 +50,7 @@ add_library(simsycl
include/simsycl/detail/utils.hh
include/simsycl/sycl/accessor.hh
include/simsycl/sycl/allocator.hh
include/simsycl/sycl/async_handler.hh
include/simsycl/sycl/atomic_ref.hh
include/simsycl/sycl/backend.hh
include/simsycl/sycl/buffer.hh
Expand Down Expand Up @@ -90,6 +90,7 @@ add_library(simsycl
src/simsycl/context.cc
src/simsycl/device.cc
src/simsycl/platform.cc
src/simsycl/queue.cc
src/simsycl/system.cc
src/simsycl/templates.cc
)
Expand Down
26 changes: 26 additions & 0 deletions include/simsycl/detail/reference_type.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ struct std::hash<simsycl::detail::reference_type<Derived, State>> {

namespace simsycl::detail {

template<typename Derived, typename State>
class weak_ref {
public:
weak_ref() = default;

weak_ref(std::weak_ptr<State> &&state) : m_state(std::move(state)) {}

Derived lock() const { return Derived(m_state.lock()); }

private:
std::weak_ptr<State> m_state;
};

template<typename Derived, typename State>
class reference_type {
public:
Expand All @@ -29,6 +42,10 @@ class reference_type {

reference_type() = default;

reference_type(std::shared_ptr<state_type> &&state) : m_state(std::move(state)) {
SIMSYCL_CHECK(m_state != nullptr);
}

template<typename... CtorParams>
explicit reference_type(std::in_place_t /* tag */, CtorParams &&...ctor_args)
: m_state(std::make_shared<State>(std::forward<CtorParams>(ctor_args)...)) {
Expand All @@ -45,8 +62,17 @@ class reference_type {
return *m_state;
}

detail::weak_ref<Derived, State> weak_ref() {
SIMSYCL_CHECK(m_state != nullptr);
return detail::weak_ref<Derived, State>(std::weak_ptr<state_type>(m_state));
}

private:
friend struct std::hash<reference_type<Derived, State>>;

template<typename, typename>
friend class weak_ref;

std::shared_ptr<state_type> m_state;
};

Expand Down
17 changes: 11 additions & 6 deletions include/simsycl/sycl/accessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <limits>


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // access::placeholder, access_mode::atomic


namespace simsycl::detail {

template<simsycl::sycl::access_mode AccessMode, simsycl::sycl::target Target>
Expand Down Expand Up @@ -311,11 +315,8 @@ class accessor : public simsycl::detail::property_interface {
return m_buffer[detail::get_linear_index(m_access_range, index)];
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated]] atomic<DataT, access::address_space::global_space> operator[](id<Dimensions> index) const
requires(AccessMode == access_mode::atomic);
#pragma GCC diagnostic pop

decltype(auto) operator[](size_t index) const
requires(Dimensions > 1)
Expand Down Expand Up @@ -535,11 +536,8 @@ class accessor<DataT, 0, AccessMode, AccessTarget, IsPlaceholder> : public simsy
return *this;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated]] operator atomic<DataT, access::address_space::global_space>() const
requires(AccessMode == access_mode::atomic);
#pragma GCC diagnostic pop

std::add_pointer_t<value_type> get_pointer() const noexcept {
SIMSYCL_CHECK(m_buffer != nullptr);
Expand Down Expand Up @@ -932,6 +930,9 @@ class host_accessor<DataT, 0, AccessMode> : public simsycl::detail::property_int

bool empty() const noexcept { return false; }

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" // access_mode::atomic

operator reference() const
requires(AccessMode != access_mode::atomic)
{
Expand All @@ -955,6 +956,8 @@ class host_accessor<DataT, 0, AccessMode> : public simsycl::detail::property_int
return *this;
}

#pragma GCC diagnostic pop

std::add_pointer_t<value_type> get_pointer() const noexcept {
SIMSYCL_CHECK(m_buffer != nullptr);
return m_buffer;
Expand Down Expand Up @@ -982,4 +985,6 @@ class host_accessor<DataT, 0, AccessMode> : public simsycl::detail::property_int
DataT *m_buffer = nullptr;
};

#pragma GCC diagnostic pop

} // namespace simsycl::sycl
8 changes: 8 additions & 0 deletions include/simsycl/sycl/async_handler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ class exception_list : private std::vector<std::exception_ptr> {
using async_handler = std::function<void(sycl::exception_list)>;

}

namespace simsycl::detail {

[[noreturn]] void default_async_handler(sycl::exception_list exceptions);

void call_async_handler(const sycl::async_handler &handler_opt, sycl::exception_list exceptions);

}
15 changes: 9 additions & 6 deletions include/simsycl/sycl/buffer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -198,19 +198,22 @@ class buffer final
template<access_mode Mode = access_mode::read_write, target Targ = target::device>
accessor<T, Dimensions, Mode, Targ> get_access(handler &command_group_handler);

// Deprecated
template<access_mode Mode>
accessor<T, Dimensions, Mode, target::host_buffer> get_access();

template<access_mode Mode = access_mode::read_write, target Targ = target::device>
accessor<T, Dimensions, Mode, Targ> get_access(
handler &command_group_handler, range<Dimensions> access_range, id<Dimensions> access_offset = {});

// Deprecated
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"

template<access_mode Mode>
[[deprecated]] accessor<T, Dimensions, Mode, target::host_buffer> get_access();

template<access_mode Mode>
accessor<T, Dimensions, Mode, target::host_buffer> get_access(
[[deprecated]] accessor<T, Dimensions, Mode, target::host_buffer> get_access(
range<Dimensions> access_range, id<Dimensions> access_offset = {});

#pragma GCC diagnostic pop

template<typename... Ts>
auto get_access(Ts...);

Expand Down
20 changes: 12 additions & 8 deletions include/simsycl/sycl/context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

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

#include <vector>


namespace simsycl::detail {

Expand All @@ -18,7 +20,7 @@ namespace simsycl::sycl {
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
using property_compatibility
= detail::property_compatibility_with<context /* apparently no compatible properties? */>;

public:
Expand All @@ -35,21 +37,23 @@ class context final : public detail::reference_type<context, detail::context_sta
explicit context(
const std::vector<device> &device_list, async_handler async_handler, const property_list &prop_list = {});

backend get_backend() const noexcept;
backend get_backend() const noexcept { return backend::simsycl; }

platform get_platform() const;

std::vector<device> get_devices() 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;

private:
struct internal_t {
} inline static constexpr internal{};

explicit context(internal_t, const std::vector<device> &devices, const async_handler &async_handler, const property_list &prop_list);
};

} // namespace simsycl::sycl
23 changes: 17 additions & 6 deletions include/simsycl/sycl/device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

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

#include <functional>
#include <string>
#include <vector>

Expand All @@ -16,16 +17,25 @@ struct device_config;

sycl::device create_device(sycl::platform &platform, const device_config &config);

}
} // namespace simsycl

namespace simsycl::detail {

struct default_selector {
int operator()(const sycl::device & /* TODO */) const { return 0; }
int operator()(const sycl::device &device) const;
};

struct cpu_selector {
int operator()(const sycl::device &device) const;
};

struct gpu_selector {
int operator()(const sycl::device &device) const;
};

struct accelerator_selector {
int operator()(const sycl::device &device) const;
};
struct cpu_selector : public default_selector {}; // TODO
struct gpu_selector : public default_selector {}; // TODO
struct accelerator_selector : public default_selector {}; // TODO

struct device_state;

Expand Down Expand Up @@ -62,7 +72,7 @@ class device final : public detail::reference_type<device, detail::device_state>
device();

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

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

Expand Down Expand Up @@ -100,6 +110,7 @@ class device final : public detail::reference_type<device, detail::device_state>
friend device simsycl::create_device(sycl::platform &platform, const device_config &config);

device(detail::device_state state);
device(const detail::device_selector &selector);
};

template<aspect Aspect>
Expand Down
39 changes: 14 additions & 25 deletions include/simsycl/sycl/enums.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ enum class access_mode {
read,
write,
read_write,
discard_write, // Deprecated in SYCL 2020
discard_read_write, // Deprecated in SYCL 2020
atomic // Deprecated in SYCL 2020
discard_write [[deprecated]],
discard_read_write [[deprecated]],
atomic [[deprecated]]
};

enum class aspect {
Expand All @@ -42,7 +42,7 @@ enum class aspect {
usm_atomic_host_allocations,
usm_shared_allocations,
usm_atomic_shared_allocations,
usm_system_allocations
usm_system_allocations,
};

enum class backend { simsycl };
Expand All @@ -64,7 +64,7 @@ enum class errc {
profiling,
feature_not_supported,
kernel_not_supported,
backend_mismatch
backend_mismatch,
};

enum class image_format {
Expand Down Expand Up @@ -114,42 +114,31 @@ enum class stream_manipulator {
fixed,
scientific,
hexfloat,
defaultfloat
defaultfloat,
};

enum class target {
device,
host_task,
constant_buffer, // Deprecated
local, // Deprecated
host_buffer, // Deprecated
global_buffer = device // Deprecated
constant_buffer [[deprecated]],
local [[deprecated]],
host_buffer [[deprecated]],
global_buffer [[deprecated]] = device,
};

} // namespace simsycl::sycl

namespace simsycl::sycl::access {

enum class address_space {
global_space,
local_space,
constant_space, // Deprecated in SYCL 2020
private_space,
generic_space
};
enum class address_space { global_space, local_space, constant_space [[deprecated]], private_space, generic_space };

enum class decorated { no, yes, legacy };

// The legacy type "access::mode" is deprecated.
using mode = sycl::access_mode;
using mode [[deprecated]] = sycl::access_mode;

// The legacy type "access::target" is deprecated.
using sycl::target;
using target [[deprecated]] = sycl::target;

enum class placeholder { // Deprecated
false_t,
true_t
};
enum class [[deprecated]] placeholder { false_t, true_t };

enum class fence_space { local_space, global_space, global_and_local };

Expand Down
1 change: 1 addition & 0 deletions include/simsycl/sycl/event.hh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "forward.hh"
#include "info.hh"
#include "type_traits.hh"

#include "../detail/reference_type.hh"
Expand Down
Loading

0 comments on commit 5570aea

Please sign in to comment.