diff options
author | 2023-04-21 22:13:21 +0200 | |
---|---|---|
committer | 2023-04-21 13:13:21 -0700 | |
commit | 7170d1b45c5092c060655ec216e4e56be74b3edb (patch) | |
tree | cf02be5c37db95408ab84da2ea70c1ae25d844dc /Source/ablastr/parallelization/KernelTimer.H | |
parent | ec6817db0bbdd418babb0002314fdc85e6c48e96 (diff) | |
download | WarpX-7170d1b45c5092c060655ec216e4e56be74b3edb.tar.gz WarpX-7170d1b45c5092c060655ec216e4e56be74b3edb.tar.zst WarpX-7170d1b45c5092c060655ec216e4e56be74b3edb.zip |
Move KernelTimer.H to ablastr/parallelization (#3863)
* move KernelTimer to ablastr
* add missing folder
* fixed bug
* fixed bug
* really fixed the bug
* kernelTimer -> KernelTimer
Diffstat (limited to 'Source/ablastr/parallelization/KernelTimer.H')
-rw-r--r-- | Source/ablastr/parallelization/KernelTimer.H | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/Source/ablastr/parallelization/KernelTimer.H b/Source/ablastr/parallelization/KernelTimer.H new file mode 100644 index 000000000..0d11220da --- /dev/null +++ b/Source/ablastr/parallelization/KernelTimer.H @@ -0,0 +1,89 @@ +/* Copyright 2019-2020 Michael Rowan, Axel Huebl, Kevin Gott + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ +#ifndef ABLASTR_KERNELTIMER_H_ +#define ABLASTR_KERNELTIMER_H_ + +#include "ablastr/utils/TextMsg.H" + +#include <AMReX.H> +#include <AMReX_BLassert.H> +#include <AMReX_GpuAtomic.H> +#include <AMReX_GpuQualifiers.H> +#include <AMReX_REAL.H> + +#include <climits> + +namespace ablastr::parallelization +{ + +/** + * \brief Defines a timer object to be used on GPU; measures summed thread cycles. + */ +class KernelTimer +{ +public: + /** Constructor. + * \param[in] do_timing Controls whether timer is active. + * \param[in,out] cost Pointer to cost which holds summed thread cycles + * (for performance, it is recommended to allocate pinned host memory). + */ + AMREX_GPU_DEVICE + KernelTimer + (const bool do_timing, amrex::Real* cost) +#if (defined AMREX_USE_GPU) + : m_do_timing(do_timing) +#endif + { +#if (defined AMREX_USE_GPU) + if (m_do_timing && cost) { + m_cost = cost; +# if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP) + // Start the timer + m_wt = clock64(); + +# elif defined(AMREX_USE_DPCPP) + // To be updated + ABLASTR_ALWAYS_ASSERT_WITH_MESSAGE(m_do_timing == false, + "KernelTimer not yet supported for this hardware."); +# endif + } +#else // AMREX_USE_GPU + amrex::ignore_unused(do_timing, cost); +#endif // AMREX_USE_GPU + } + + //! Destructor. + AMREX_GPU_DEVICE + ~KernelTimer () { +#if (defined AMREX_USE_GPU) + if (m_do_timing && m_cost) { +# if defined(AMREX_USE_CUDA) || defined(AMREX_USE_HIP) + m_wt = clock64() - m_wt; + amrex::Gpu::Atomic::Add( m_cost, amrex::Real(m_wt)); +# elif defined(AMREX_USE_DPCPP) + // To be updated +# endif + } +#endif //AMREX_USE_GPU + } + +#if (defined AMREX_USE_GPU) +private: + //! Stores whether kernel timer is active. + bool m_do_timing; + + //! Location in which to accumulate costs from all threads. + amrex::Real* m_cost = nullptr; + + //! Store the time difference (cost) from a single thread. + long long int m_wt; +#endif //AMREX_USE_GPU +}; + +} // namespace ablastr::parallelization + +#endif // ABLASTR_KERNELTIMER_H_ |