Skip to content

Commit

Permalink
[Dynamic Selection] Adding sycl profiling for auto tune policy (#1464)
Browse files Browse the repository at this point in the history
* Added static assert for keyArgs==Args

* WIP for jit compilation

* Fixing Autotune bug

* Added sycl profiling without host task

* Corrections in dynamic traits

* Remove comments in dynamic_selection_traits

* Adding back jit compolation restrictions

* Adressing comments to add thread safety, better traits

* Added backend trait to check if profiling is enabled

* Backend traits, renaming and adding a lock to lazy report

* Fixed memory leaks

* No nullptr for selection handle in async waiter constructor

* Added an erase and remove_if

* Adressing comments for profiling report, Adding profiling to default sycl backend constructor

* Changes to std::chrono::duration

* Addressed comments for sycl backend

* Addressed comments to sycl backend

* Fix USM memory leaks and create unique task names (#1537)

* test/parallel_api/dynamic_selection/sycl/test_auto_tune_policy_sycl.pass.cpp - fix USM shared memory leaks

Signed-off-by: Sergey Kopienko <[email protected]>

* test/parallel_api/dynamic_selection/sycl/test_auto_tune_policy_sycl.pass.cpp - create unique task names for h.single_task([](){});

Signed-off-by: Sergey Kopienko <[email protected]>

---------

Signed-off-by: Sergey Kopienko <[email protected]>

* Fix the format of report method - using `report_duration` in second param (#1539)

* include/oneapi/dpl/internal/dynamic_selection_traits.h - fix traits to specify report method second parameter type

Signed-off-by: Sergey Kopienko <[email protected]>

* Change second parameter type of auto_tune_selection_type::report method - to report_duration (std::chrono::milliseconds)

Signed-off-by: Sergey Kopienko <[email protected]>

---------

Signed-off-by: Sergey Kopienko <[email protected]>

* Fixing clang format

---------

Signed-off-by: Sergey Kopienko <[email protected]>
Co-authored-by: Sergey Kopienko <[email protected]>
  • Loading branch information
AnuyaWelling2801 and SergeyKopienko authored Apr 30, 2024
1 parent f6a8c40 commit 5ea755c
Show file tree
Hide file tree
Showing 7 changed files with 347 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
#include <mutex>
#include <utility>
#include <chrono>
#include <ratio>
#include <limits>
#include <vector>
#include <type_traits>
#include <tuple>
#include <unordered_map>
#include "oneapi/dpl/internal/dynamic_selection_traits.h"
#include "oneapi/dpl/internal/dynamic_selection_impl/backend_traits.h"
#if _DS_BACKEND_SYCL != 0
# include "oneapi/dpl/internal/dynamic_selection_impl/sycl_backend.h"
#endif
Expand All @@ -47,13 +49,16 @@ class auto_tune_policy
using size_type = typename std::vector<typename Backend::resource_type>::size_type;
using timing_t = uint64_t;

using report_clock_type = std::chrono::steady_clock;
using report_duration = std::chrono::milliseconds;

static constexpr timing_t never_resample = 0;
static constexpr size_type use_best_resource = ~size_type(0);

struct resource_with_index_t
{
wrapped_resource_t r_;
size_type index_;
size_type index_ = 0;
};

struct time_data_t
Expand All @@ -66,7 +71,7 @@ class auto_tune_policy
{
std::mutex m_;

std::chrono::steady_clock::time_point t0_;
report_clock_type::time_point t0_;

timing_t best_timing_ = std::numeric_limits<timing_t>::max();
resource_with_index_t best_resource_;
Expand All @@ -80,7 +85,7 @@ class auto_tune_policy
timing_t resample_time_ = 0.0;

tuner_t(resource_with_index_t br, size_type resources_size, timing_t rt)
: t0_(std::chrono::steady_clock::now()), best_resource_(br), max_resource_to_profile_(resources_size),
: t0_(report_clock_type::now()), best_resource_(br), max_resource_to_profile_(resources_size),
resample_time_(rt)
{
}
Expand All @@ -100,8 +105,8 @@ class auto_tune_policy
}
else
{
auto now = std::chrono::steady_clock::now();
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now - t0_).count();
const auto now = report_clock_type::now();
const auto ms = std::chrono::duration_cast<report_duration>(now - t0_).count();
if (ms < resample_time_)
{
return use_best_resource;
Expand Down Expand Up @@ -169,9 +174,9 @@ class auto_tune_policy
};

void
report(const execution_info::task_time_t&, const typename execution_info::task_time_t::value_type& v) const
report(const execution_info::task_time_t&, report_duration v) const
{
tuner_->add_new_timing(resource_, v);
tuner_->add_new_timing(resource_, v.count());
}
};

Expand Down Expand Up @@ -217,6 +222,10 @@ class auto_tune_policy
select(Function&& f, Args&&... args)
{
static_assert(sizeof...(KeyArgs) == sizeof...(Args));
if constexpr (backend_traits::lazy_report_v<Backend>)
{
backend_->lazy_report();
}
if (state_)
{
std::lock_guard<std::mutex> l(state_->m_);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Copyright (C) 2023 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef _ONEDPL_INTERNAL_BACKEND_TRAITS_H
#define _ONEDPL_INTERNAL_BACKEND_TRAITS_H

#include <utility>
#include <type_traits>

namespace oneapi
{
namespace dpl
{
namespace experimental
{
namespace internal
{
template <typename Backend>
auto
has_lazy_report_impl(...) -> std::false_type;

template <typename Backend>
auto
has_lazy_report_impl(int) -> decltype(std::declval<Backend>().lazy_report(), std::true_type{});

template <typename Backend>
struct has_lazy_report : decltype(has_lazy_report_impl<Backend>(0))
{
};

} //namespace internal

namespace backend_traits
{
template <typename S>
struct lazy_report_value
{
static constexpr bool value = ::oneapi::dpl::experimental::internal::has_lazy_report<S>::value;
};
template <typename S>
inline constexpr bool lazy_report_v = lazy_report_value<S>::value;

} //namespace backend_traits

} // namespace experimental
} // namespace dpl
} // namespace oneapi

#endif /*_ONEDPL_INTERNAL_BACKEND_TRAITS_H*/
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <type_traits>
#include <utility>
#include "oneapi/dpl/internal/dynamic_selection_traits.h"
#include "oneapi/dpl/internal/dynamic_selection_impl/backend_traits.h"
#if _DS_BACKEND_SYCL != 0
# include "oneapi/dpl/internal/dynamic_selection_impl/sycl_backend.h"
#endif
Expand Down Expand Up @@ -150,6 +151,10 @@ struct dynamic_load_policy
selection_type
select(Args&&...)
{
if constexpr (backend_traits::lazy_report_v<Backend>)
{
backend_->lazy_report();
}
if (state_)
{
std::lock_guard<std::mutex> l(state_->m_);
Expand Down
Loading

0 comments on commit 5ea755c

Please sign in to comment.