Skip to content

Commit

Permalink
Configure simulated system via env SIMSYCL_CONFIG=system.json
Browse files Browse the repository at this point in the history
  • Loading branch information
fknorr committed Jan 2, 2024
1 parent 65d5e76 commit a223af9
Show file tree
Hide file tree
Showing 22 changed files with 813 additions and 269 deletions.
28 changes: 24 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
cmake_minimum_required(VERSION 3.13)
cmake_policy(SET CMP0135 NEW) # ExternalProject downloads will have archive timestamps

set(SIMSYCL_VERSION 0.1)
set(SIMSYCL_VERSION_MAJOR 0)
Expand Down Expand Up @@ -26,6 +27,23 @@ endif()

find_package(Boost 1.70 COMPONENTS context REQUIRED)

include(FetchContent)

set(LIBENVPP_INSTALL ON CACHE BOOL "" FORCE) # If installation is desired.
FetchContent_Declare(libenvpp
GIT_REPOSITORY https://github.com/ph3at/libenvpp.git
GIT_TAG v1.4.0
)
FetchContent_MakeAvailable(libenvpp)

set(JSON_BuildTests OFF CACHE INTERNAL "")
set(JSON_Install ON CACHE INTERNAL "")
FetchContent_Declare(nlohmann_json
URL https://github.com/nlohmann/json/releases/download/v3.11.3/json.tar.xz
URL_HASH SHA256=d6c65aca6b1ed68e7a182f4757257b107ae403032760ed6ef121c9d55e81757d
)
FetchContent_MakeAvailable(nlohmann_json)

include(CheckTypeSize)
check_type_size(_Float16 FLOAT16 BUILTIN_TYPES_ONLY LANGUAGE CXX)
if (HAVE_FLOAT16)
Expand Down Expand Up @@ -64,7 +82,6 @@ add_library(simsycl
include/simsycl/sycl.hh
include/simsycl/detail/allocation.hh
include/simsycl/detail/check.hh
include/simsycl/detail/config.hh
include/simsycl/detail/coordinate.hh
include/simsycl/detail/hash.hh
include/simsycl/detail/schedule.hh
Expand Down Expand Up @@ -115,7 +132,6 @@ add_library(simsycl
include/simsycl/sycl/usm.hh
include/simsycl/sycl/vec.hh
include/simsycl/system.hh
include/simsycl/templates.hh
${CONFIG_PATH}
src/simsycl/check.cc
src/simsycl/context.cc
Expand All @@ -124,9 +140,13 @@ add_library(simsycl
src/simsycl/platform.cc
src/simsycl/queue.cc
src/simsycl/system.cc
src/simsycl/templates.cc
src/simsycl/system_config.cc
)
target_link_libraries(simsycl PRIVATE
Boost::context
nlohmann_json::nlohmann_json
libenvpp::libenvpp
)
target_link_libraries(simsycl Boost::context)
target_include_directories(simsycl PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
Expand Down
2 changes: 2 additions & 0 deletions cmake/simsycl-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set(SIMSYCL_ORIGINAL_CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${SIMSYCL_CMAKE_DIR}")

find_dependency(Boost 1.70 COMPONENTS context REQUIRED)
find_dependency(nlohmann_json)
find_dependency(libenvpp)

include("${CMAKE_CURRENT_LIST_DIR}/simsycl-targets.cmake")

Expand Down
26 changes: 0 additions & 26 deletions include/simsycl/detail/config.hh

This file was deleted.

6 changes: 4 additions & 2 deletions include/simsycl/sycl/device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ namespace simsycl {

struct device_config;

sycl::device create_device(sycl::platform &platform, const device_config &config);
sycl::device make_device(sycl::platform &platform, const device_config &config);
void set_parent_device(sycl::device &device, const sycl::device &parent);

} // namespace simsycl

Expand Down Expand Up @@ -102,7 +103,8 @@ class device final : public detail::reference_type<device, detail::device_state>
template<typename>
friend class detail::weak_ref;

friend device simsycl::create_device(sycl::platform &platform, const device_config &config);
friend device simsycl::make_device(sycl::platform &platform, const device_config &config);
friend void simsycl::set_parent_device(sycl::device &device, const sycl::device &parent);

device(const detail::device_selector &selector);
device(std::shared_ptr<detail::device_state> &&state) : reference_type(std::move(state)) {}
Expand Down
4 changes: 2 additions & 2 deletions include/simsycl/sycl/forward.hh
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ struct concurrent_sub_group;

using device_selector = std::function<int(const sycl::device &)>;

sycl::sub_group make_sub_group(
const sycl::id<1> &, const sycl::range<1> &, const sycl::id<1> &, const sycl::range<1> &, concurrent_sub_group *);
sycl::sub_group make_sub_group(const sycl::id<1> &, const sycl::range<1> &, const sycl::range<1> &, const sycl::id<1> &,
const sycl::range<1> &, concurrent_sub_group *);

concurrent_sub_group &get_concurrent_group(const sycl::sub_group &g);
template<int Dimensions>
Expand Down
21 changes: 19 additions & 2 deletions include/simsycl/sycl/kernel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
namespace simsycl::detail {

struct kernel_state {};
struct kernel_id_state {};

struct kernel_id_state {
std::string name;
};

struct kernel_bundle_state {};

sycl::kernel_id make_kernel_id(std::string name);

} // namespace simsycl::detail


Expand Down Expand Up @@ -50,7 +56,12 @@ class kernel_id : public detail::reference_type<kernel_id, detail::kernel_id_sta
public:
kernel_id() = delete;

const char *get_name() const noexcept;
const char *get_name() const noexcept { return state().name.c_str(); }

private:
friend kernel_id detail::make_kernel_id(std::string name);

explicit kernel_id(std::string name) : reference_type(std::in_place, name) {}
};

template<bundle_state State>
Expand Down Expand Up @@ -211,3 +222,9 @@ struct std::hash<simsycl::sycl::kernel_bundle<State>>
: public std::hash<
simsycl::detail::reference_type<simsycl::sycl::kernel_bundle<State>, simsycl::detail::kernel_bundle_state>> {
};

namespace simsycl::detail {

inline sycl::kernel_id make_kernel_id(std::string name) { return sycl::kernel_id(std::move(name)); }

} // namespace simsycl::detail
8 changes: 4 additions & 4 deletions include/simsycl/sycl/platform.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace simsycl {
// forward
struct platform_config;

sycl::platform create_platform(const platform_config &config);
sycl::device create_device(sycl::platform &platform, const device_config &config);
sycl::platform make_platform(const platform_config &config);
sycl::device make_device(sycl::platform &platform, const device_config &config);

} // namespace simsycl

Expand Down Expand Up @@ -59,8 +59,8 @@ class platform final : public detail::reference_type<platform, detail::platform_
template<typename>
friend class detail::weak_ref;

friend sycl::platform simsycl::create_platform(const platform_config &config);
friend device simsycl::create_device(platform &platform, const device_config &config);
friend sycl::platform simsycl::make_platform(const platform_config &config);
friend device simsycl::make_device(platform &platform, const device_config &config);

platform(const detail::device_selector &selector);
platform(std::shared_ptr<detail::platform_state> &&state) : reference_type(std::move(state)) {}
Expand Down
20 changes: 11 additions & 9 deletions include/simsycl/sycl/sub_group.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "type_traits.hh"

#include "simsycl/detail/check.hh"
#include "simsycl/detail/config.hh"
#include "simsycl/detail/group_operation_impl.hh"

namespace simsycl::sycl {
Expand All @@ -25,7 +24,7 @@ class sub_group {

range_type get_local_range() const { return m_local_range; }

range_type get_max_local_range() const { return range<1>(detail::config::max_sub_group_size); }
range_type get_max_local_range() const { return m_max_local_range; }

id_type get_group_id() const { return m_group_id; }

Expand Down Expand Up @@ -96,18 +95,20 @@ class sub_group {
private:
id_type m_local_id;
range_type m_local_range;
range_type m_max_local_range;
id_type m_group_id;
range_type m_group_range;

detail::concurrent_sub_group *m_concurrent_group; // NOLINT

sub_group(const id_type &local_id, const range_type &local_range, const id_type &group_id,
const range_type &group_range, detail::concurrent_sub_group *concurrent_group)
: m_local_id(local_id), m_local_range(local_range), m_group_id(group_id), m_group_range(group_range),
m_concurrent_group(concurrent_group) {}
sub_group(const id_type &local_id, const range_type &local_range, const range_type &max_local_range,
const id_type &group_id, const range_type &group_range, detail::concurrent_sub_group *concurrent_group)
: m_local_id(local_id), m_local_range(local_range), m_max_local_range(max_local_range), m_group_id(group_id),
m_group_range(group_range), m_concurrent_group(concurrent_group) {}

friend sycl::sub_group detail::make_sub_group(const sycl::id<1> &local_id, const sycl::range<1> &local_range,
const sycl::id<1> &group_id, const sycl::range<1> &group_range, detail::concurrent_sub_group *impl);
const sycl::range<1> &max_local_range, const sycl::id<1> &group_id, const sycl::range<1> &group_range,
detail::concurrent_sub_group *impl);

friend detail::concurrent_sub_group &detail::get_concurrent_group(const sycl::sub_group &g);
};
Expand All @@ -123,8 +124,9 @@ template<>
struct is_sub_group<sycl::sub_group> : std::true_type {};

inline sycl::sub_group make_sub_group(const sycl::id<1> &local_id, const sycl::range<1> &local_range,
const sycl::id<1> &group_id, const sycl::range<1> &group_range, detail::concurrent_sub_group *impl) {
return sycl::sub_group(local_id, local_range, group_id, group_range, impl);
const sycl::range<1> &max_local_range, const sycl::id<1> &group_id, const sycl::range<1> &group_range,
detail::concurrent_sub_group *impl) {
return sycl::sub_group(local_id, local_range, max_local_range, group_id, group_range, impl);
}

} // namespace simsycl::detail
2 changes: 1 addition & 1 deletion include/simsycl/sycl/vec.hh
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class swizzled_vec {

static constexpr bool allow_assign = !std::is_const_v<ReferenceDataT> && no_repeat_indices_v<Indices...>;
static constexpr int num_elements = sizeof...(Indices);
static constexpr index_list<Indices...> indices = {};
static constexpr index_list<Indices...> indices{};

public:
using element_type = std::remove_const_t<ReferenceDataT>;
Expand Down
31 changes: 19 additions & 12 deletions include/simsycl/system.hh
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#pragma once

#include "detail/check.hh"

#include "sycl/device.hh"
#include "sycl/exception.hh"
#include "sycl/kernel.hh"
#include "sycl/platform.hh"
#include "sycl/range.hh"

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

namespace simsycl {

using platform_id = std::string;
using device_id = std::string;
using system_id = std::string;

struct device_config {
sycl::info::device_type device_type{};
uint32_t vendor_id{};
Expand Down Expand Up @@ -78,18 +78,17 @@ struct device_config {
std::vector<sycl::info::execution_capability> execution_capabilities{};
bool queue_profiling{};
std::vector<std::string> built_in_kernels{};
std::vector<sycl::kernel_id> built_in_kernel_ids{};
std::vector<std::string> built_in_kernel_ids{};
simsycl::platform_id platform_id{};
std::string name{};
std::string vendor{};
std::string driver_version{};
std::string profile{};
std::string version{};
std::string backend_version{};
std::vector<sycl::aspect> aspects{};
std::vector<std::string> extensions{};
size_t printf_buffer_size{};
bool preferred_interop_user_sync{};
std::optional<sycl::device> parent_device{};
std::optional<simsycl::device_id> parent_device_id{};
uint32_t partition_max_sub_devices{};
std::vector<sycl::info::partition_property> partition_properties{};
std::vector<sycl::info::partition_affinity_domain> partition_affinity_domains{};
Expand All @@ -106,17 +105,25 @@ struct platform_config {
};

struct system_config {
std::vector<sycl::platform> platforms{};
std::vector<sycl::device> devices{};
std::unordered_map<platform_id, platform_config> platforms{};
std::unordered_map<device_id, device_config> devices{};
};

const system_config &get_system_config();
void configure_system(system_config system);
extern const platform_config builtin_platform;
extern const device_config builtin_device;
extern const system_config builtin_system;

const system_config &get_default_system_config();
system_config read_system_config(const std::string &path_to_json_file);
void write_system_config(const std::string &path_to_json_file, const system_config &config);
void configure_system(const system_config &system);

} // namespace simsycl

namespace simsycl::detail {

const std::vector<sycl::platform> &get_platforms();
const std::vector<sycl::device> &get_devices();
sycl::device select_device(const device_selector &selector);

} // namespace simsycl::detail
15 changes: 0 additions & 15 deletions include/simsycl/templates.hh

This file was deleted.

Loading

0 comments on commit a223af9

Please sign in to comment.