Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Kokkos_Profiling_[C_]Interface.* #260

Merged
Merged
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
14 changes: 12 additions & 2 deletions profiling/all/impl/Kokkos_Profiling_C_Interface.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
//@HEADER
// ************************************************************************
//
Expand All @@ -9,10 +10,11 @@
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
*/

#ifndef KOKKOS_PROFILING_C_INTERFACE_HPP
#define KOKKOS_PROFILING_C_INTERFACE_HPP
Expand All @@ -26,10 +28,14 @@
#include <stdbool.h>
#endif

#define KOKKOSP_INTERFACE_VERSION 20210623
#define KOKKOSP_INTERFACE_VERSION 20211015

// Profiling

#ifdef __cplusplus
extern "C" {
#endif

struct Kokkos_Profiling_KokkosPDeviceInfo {
size_t deviceID;
};
Expand Down Expand Up @@ -265,4 +271,8 @@ struct Kokkos_Profiling_EventSet {
// changing struct layout
};

#ifdef __cplusplus
}
#endif

#endif // KOKKOS_PROFILING_C_INTERFACE_HPP
34 changes: 20 additions & 14 deletions profiling/all/impl/Kokkos_Profiling_Interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <cinttypes>
#include <cstddef>
#include <climits>

#include <cstdlib>

Expand All @@ -45,6 +46,7 @@ enum struct DeviceType {
HPX,
Threads,
SYCL,
OpenACC,
Unknown
};

Expand All @@ -53,6 +55,12 @@ struct ExecutionSpaceIdentifier {
uint32_t device_id;
uint32_t instance_id;
};

constexpr const uint32_t num_type_bits = 8;
constexpr const uint32_t num_device_bits = 7;
constexpr const uint32_t num_instance_bits = 17;
constexpr const uint32_t num_avail_bits = sizeof(uint32_t) * CHAR_BIT;

inline DeviceType devicetype_from_uint32t(const uint32_t in) {
switch (in) {
case 0: return DeviceType::Serial;
Expand All @@ -63,37 +71,35 @@ inline DeviceType devicetype_from_uint32t(const uint32_t in) {
case 5: return DeviceType::HPX;
case 6: return DeviceType::Threads;
case 7: return DeviceType::SYCL;
case 8: return DeviceType::OpenACC;
default: return DeviceType::Unknown; // TODO: error out?
}
}

inline ExecutionSpaceIdentifier identifier_from_devid(const uint32_t in) {
// ExecutionSpaceIdentifier out;
// out.type = in >> 24;
// out.device_id = in >> 17;
// out.instance_id = ((uint32_t(-1)) << 17 ) & in;
return {devicetype_from_uint32t(in >> 24),
(~((uint32_t(-1)) << 24)) & (in >> 17),
(~((uint32_t(-1)) << 17)) & in};
constexpr const uint32_t shift = num_avail_bits - num_type_bits;

return {devicetype_from_uint32t(in >> shift), /*First 8 bits*/
(~((uint32_t(-1)) << num_device_bits)) &
(in >> num_instance_bits), /*Next 7 bits */
(~((uint32_t(-1)) << num_instance_bits)) & in}; /*Last 17 bits*/
}

template <typename ExecutionSpace>
struct DeviceTypeTraits;

constexpr const size_t device_type_bits = 8;
constexpr const size_t instance_bits = 24;
template <typename ExecutionSpace>
constexpr uint32_t device_id_root() {
/** uncomment when C++14 is enabled
constexpr auto device_id =
static_cast<uint32_t>(DeviceTypeTraits<ExecutionSpace>::id);
return (device_id << instance_bits);
*/
return 0;
return (device_id << (num_instance_bits + num_device_bits));
}
template <typename ExecutionSpace>
inline uint32_t device_id(ExecutionSpace const& space) noexcept {
return device_id_root<ExecutionSpace>() + space.impl_instance_id();
return device_id_root<ExecutionSpace>() +
(DeviceTypeTraits<ExecutionSpace>::device_id(space)
<< num_instance_bits) +
space.impl_instance_id();
}
} // namespace Experimental
} // namespace Tools
Expand Down
Loading