Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/device_hooks/cuda_hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -141,7 +141,7 @@ void CudaExecutor::raw_copy_to(const DpcppExecutor*, size_type num_bytes,
GKO_NOT_COMPILED(cuda);


void CudaExecutor::synchronize() const GKO_NOT_COMPILED(cuda);
void CudaExecutor::synchronize_impl() const GKO_NOT_COMPILED(cuda);


scoped_device_id_guard CudaExecutor::get_scoped_device_id_guard() const
Expand Down
4 changes: 2 additions & 2 deletions core/device_hooks/dpcpp_hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -84,7 +84,7 @@ void DpcppExecutor::raw_copy_to(const DpcppExecutor*, size_type num_bytes,
GKO_NOT_COMPILED(dpcpp);


void DpcppExecutor::synchronize() const GKO_NOT_COMPILED(dpcpp);
void DpcppExecutor::synchronize_impl() const GKO_NOT_COMPILED(dpcpp);


scoped_device_id_guard DpcppExecutor::get_scoped_device_id_guard() const
Expand Down
4 changes: 2 additions & 2 deletions core/device_hooks/hip_hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -140,7 +140,7 @@ void HipExecutor::raw_copy_to(const DpcppExecutor*, size_type num_bytes,
GKO_NOT_COMPILED(hip);


void HipExecutor::synchronize() const GKO_NOT_COMPILED(hip);
void HipExecutor::synchronize_impl() const GKO_NOT_COMPILED(hip);


scoped_device_id_guard HipExecutor::get_scoped_device_id_guard() const
Expand Down
20 changes: 17 additions & 3 deletions core/log/profiler_hook.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -280,6 +280,18 @@ void ProfilerHook::on_iteration_complete(
}


void ProfilerHook::on_synchronize_started(const gko::Executor*) const
{
this->begin_hook_("synchronize", profile_event_category::operation);
}


void ProfilerHook::on_synchronize_completed(const gko::Executor*) const
{
this->end_hook_("synchronize", profile_event_category::operation);
}


bool ProfilerHook::needs_propagation() const { return true; }


Expand All @@ -306,10 +318,12 @@ void ProfilerHook::set_synchronization(bool synchronize)
void ProfilerHook::maybe_synchronize(const Executor* exec) const
{
if (synchronize_) {
profiling_scope_guard sync_guard{"synchronize",
profiling_scope_guard sync_guard{"logger_synchronize",
profile_event_category::internal,
begin_hook_, end_hook_};
exec->synchronize();
// we call synchronize_impl not synchronize to separate the syncrhonize
// caller.
exec->synchronize_impl();
}
}

Expand Down
4 changes: 2 additions & 2 deletions cuda/base/executor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -165,7 +165,7 @@ void CudaExecutor::raw_copy_to(const CudaExecutor* dest, size_type num_bytes,
}


void CudaExecutor::synchronize() const
void CudaExecutor::synchronize_impl() const
{
detail::cuda_scoped_device_id_guard g(this->get_device_id());
GKO_ASSERT_NO_CUDA_ERRORS(cudaStreamSynchronize(this->get_stream()));
Expand Down
4 changes: 2 additions & 2 deletions devices/omp/executor.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -58,7 +58,7 @@ void OmpExecutor::raw_copy_to(const OmpExecutor*, size_type num_bytes,
}


void OmpExecutor::synchronize() const
void OmpExecutor::synchronize_impl() const
{
// This is a no-op for single-threaded OMP
// TODO: change when adding support for multi-threaded OMP execution
Expand Down
4 changes: 2 additions & 2 deletions dpcpp/base/executor.dp.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -153,7 +153,7 @@ void DpcppExecutor::raw_copy_to(const DpcppExecutor* dest, size_type num_bytes,
}


void DpcppExecutor::synchronize() const { queue_->wait_and_throw(); }
void DpcppExecutor::synchronize_impl() const { queue_->wait_and_throw(); }

scoped_device_id_guard DpcppExecutor::get_scoped_device_id_guard() const
{
Expand Down
4 changes: 2 additions & 2 deletions hip/base/executor.hip.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -161,7 +161,7 @@ void HipExecutor::raw_copy_to(const HipExecutor* dest, size_type num_bytes,
}


void HipExecutor::synchronize() const
void HipExecutor::synchronize_impl() const
{
detail::hip_scoped_device_id_guard g(this->get_device_id());
GKO_ASSERT_NO_HIP_ERRORS(hipStreamSynchronize(this->get_stream()));
Expand Down
41 changes: 31 additions & 10 deletions include/ginkgo/core/base/executor.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -141,6 +141,15 @@ class ExecutorBase;
} // namespace detail


namespace log {


class ProfilerHook;


} // namespace log


/**
* Operations can be used to define functionalities whose implementations differ
* among devices.
Expand Down Expand Up @@ -619,6 +628,8 @@ class Executor : public log::EnableLogging<Executor> {
GKO_ENABLE_FOR_ALL_EXECUTORS(GKO_DECLARE_EXECUTOR_FRIEND);
friend class ReferenceExecutor;

friend class log::ProfilerHook;

public:
virtual ~Executor() = default;

Expand Down Expand Up @@ -827,7 +838,12 @@ class Executor : public log::EnableLogging<Executor> {
/**
* Synchronize the operations launched on the executor with its master.
*/
virtual void synchronize() const = 0;
void synchronize() const
{
this->template log<log::Logger::synchronize_started>(this);
this->synchronize_impl();
this->template log<log::Logger::synchronize_completed>(this);
}

/**
* @copydoc Loggable::add_logger
Expand Down Expand Up @@ -1023,6 +1039,11 @@ class Executor : public log::EnableLogging<Executor> {
*/
const exec_info& get_exec_info() const { return this->exec_info_; }

/**
* Synchronize the operations launched on the executor with its master.
*/
virtual void synchronize_impl() const = 0;

/**
* Allocates raw memory in this Executor.
*
Expand Down Expand Up @@ -1404,8 +1425,6 @@ class OmpExecutor : public detail::ExecutorBase<OmpExecutor>,

std::shared_ptr<const Executor> get_master() const noexcept override;

void synchronize() const override;

int get_num_cores() const
{
return this->get_exec_info().num_computing_units;
Expand All @@ -1431,6 +1450,8 @@ class OmpExecutor : public detail::ExecutorBase<OmpExecutor>,

void populate_exec_info(const machine_topology* mach_topo) override;

void synchronize_impl() const override;

void* raw_alloc(size_type size) const override;

void raw_free(void* ptr) const noexcept override;
Expand Down Expand Up @@ -1588,8 +1609,6 @@ class CudaExecutor : public detail::ExecutorBase<CudaExecutor>,

std::shared_ptr<const Executor> get_master() const noexcept override;

void synchronize() const override;

scoped_device_id_guard get_scoped_device_id_guard() const override;

std::string get_description() const override;
Expand Down Expand Up @@ -1731,6 +1750,8 @@ class CudaExecutor : public detail::ExecutorBase<CudaExecutor>,
this->init_handles();
}

void synchronize_impl() const override;

void* raw_alloc(size_type size) const override;

void raw_free(void* ptr) const noexcept override;
Expand Down Expand Up @@ -1812,8 +1833,6 @@ class HipExecutor : public detail::ExecutorBase<HipExecutor>,

std::shared_ptr<const Executor> get_master() const noexcept override;

void synchronize() const override;

scoped_device_id_guard get_scoped_device_id_guard() const override;

std::string get_description() const override;
Expand Down Expand Up @@ -1949,6 +1968,8 @@ class HipExecutor : public detail::ExecutorBase<HipExecutor>,
this->init_handles();
}

void synchronize_impl() const override;

void* raw_alloc(size_type size) const override;

void raw_free(void* ptr) const noexcept override;
Expand Down Expand Up @@ -2017,8 +2038,6 @@ class DpcppExecutor : public detail::ExecutorBase<DpcppExecutor>,

std::shared_ptr<const Executor> get_master() const noexcept override;

void synchronize() const override;

scoped_device_id_guard get_scoped_device_id_guard() const override;

std::string get_description() const override;
Expand Down Expand Up @@ -2132,6 +2151,8 @@ class DpcppExecutor : public detail::ExecutorBase<DpcppExecutor>,

void populate_exec_info(const machine_topology* mach_topo) override;

void synchronize_impl() const override;

void* raw_alloc(size_type size) const override;

void raw_free(void* ptr) const noexcept override;
Expand Down
19 changes: 18 additions & 1 deletion include/ginkgo/core/log/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,22 @@ public: \
#endif


public:
/**
* synchronize started event.
*
* @param exec the executor used
*/
GKO_LOGGER_REGISTER_EVENT(27, synchronize_started, const Executor* exec)

/**
* synchronize completed event.
*
* @param exec the executor used
*/
GKO_LOGGER_REGISTER_EVENT(28, synchronize_completed, const Executor* exec)


public:
#undef GKO_LOGGER_REGISTER_EVENT

Expand All @@ -626,7 +642,8 @@ public: \
static constexpr mask_type executor_events_mask =
allocation_started_mask | allocation_completed_mask |
free_started_mask | free_completed_mask | copy_started_mask |
copy_completed_mask;
copy_completed_mask | synchronize_started_mask |
synchronize_completed_mask;

/**
* Bitset Mask which activates all operation events
Expand Down
6 changes: 5 additions & 1 deletion include/ginkgo/core/log/profiler_hook.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -87,6 +87,10 @@ class ProfilerHook : public Logger {
void on_operation_completed(const Executor* exec,
const Operation* operation) const override;

void on_synchronize_started(const Executor*) const override;

void on_synchronize_completed(const Executor*) const override;

/* PolymorphicObject events */
void on_polymorphic_object_copy_started(
const Executor* exec, const PolymorphicObject* from,
Expand Down
Loading