Skip to content

[Offload][NFC] Reorganize utils:: and make Device/Host/Shared clearer #100280

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

Merged
merged 1 commit into from
Sep 5, 2024
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
6 changes: 3 additions & 3 deletions offload/DeviceRTL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ set(include_files
${include_directory}/Profiling.h
${include_directory}/State.h
${include_directory}/Synchronization.h
${include_directory}/Types.h
${include_directory}/Utils.h
${include_directory}/DeviceTypes.h
${include_directory}/DeviceUtils.h
${include_directory}/Workshare.h
)

Expand All @@ -99,7 +99,7 @@ set(src_files
${source_directory}/State.cpp
${source_directory}/Synchronization.cpp
${source_directory}/Tasking.cpp
${source_directory}/Utils.cpp
${source_directory}/DeviceUtils.cpp
${source_directory}/Workshare.cpp
)

Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/include/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef OMPTARGET_ALLOCATOR_H
#define OMPTARGET_ALLOCATOR_H

#include "Types.h"
#include "DeviceTypes.h"

// Forward declaration.
struct KernelEnvironmentTy;
Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/include/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include "Shared/Environment.h"

#include "Types.h"
#include "DeviceTypes.h"

namespace ompx {
namespace config {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===---------- Types.h - OpenMP types ---------------------------- C++ -*-===//
//===---------- DeviceTypes.h - OpenMP types ---------------------- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
Expand Down Expand Up @@ -115,9 +115,9 @@ enum kmp_sched_t {
#define SCHEDULE_WITHOUT_MODIFIERS(s) \
(enum kmp_sched_t)( \
(s) & ~(kmp_sched_modifier_nonmonotonic | kmp_sched_modifier_monotonic))
#define SCHEDULE_HAS_MONOTONIC(s) (((s)&kmp_sched_modifier_monotonic) != 0)
#define SCHEDULE_HAS_MONOTONIC(s) (((s) & kmp_sched_modifier_monotonic) != 0)
#define SCHEDULE_HAS_NONMONOTONIC(s) \
(((s)&kmp_sched_modifier_nonmonotonic) != 0)
(((s) & kmp_sched_modifier_nonmonotonic) != 0)
#define SCHEDULE_HAS_NO_MODIFIERS(s) \
(((s) & (kmp_sched_modifier_nonmonotonic | kmp_sched_modifier_monotonic)) == \
0)
Expand Down
54 changes: 54 additions & 0 deletions offload/DeviceRTL/include/DeviceUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//===--- DeviceUtils.h - OpenMP device runtime utility functions -- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
//
//===----------------------------------------------------------------------===//

#ifndef OMPTARGET_DEVICERTL_DEVICE_UTILS_H
#define OMPTARGET_DEVICERTL_DEVICE_UTILS_H

#include "DeviceTypes.h"
#include "Shared/Utils.h"

#pragma omp begin declare target device_type(nohost)

namespace utils {

/// Return the value \p Var from thread Id \p SrcLane in the warp if the thread
/// is identified by \p Mask.
int32_t shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane, int32_t Width);

int32_t shuffleDown(uint64_t Mask, int32_t Var, uint32_t Delta, int32_t Width);

int64_t shuffleDown(uint64_t Mask, int64_t Var, uint32_t Delta, int32_t Width);

uint64_t ballotSync(uint64_t Mask, int32_t Pred);

/// Return \p LowBits and \p HighBits packed into a single 64 bit value.
uint64_t pack(uint32_t LowBits, uint32_t HighBits);

/// Unpack \p Val into \p LowBits and \p HighBits.
void unpack(uint64_t Val, uint32_t &LowBits, uint32_t &HighBits);

/// Return true iff \p Ptr is pointing into shared (local) memory (AS(3)).
bool isSharedMemPtr(void *Ptr);

/// Return true iff \p Ptr is pointing into (thread) local memory (AS(5)).
bool isThreadLocalMemPtr(void *Ptr);

/// A pointer variable that has by design an `undef` value. Use with care.
[[clang::loader_uninitialized]] static void *const UndefPtr;

#define OMP_LIKELY(EXPR) __builtin_expect((bool)(EXPR), true)
#define OMP_UNLIKELY(EXPR) __builtin_expect((bool)(EXPR), false)

} // namespace utils

#pragma omp end declare target

#endif
2 changes: 1 addition & 1 deletion offload/DeviceRTL/include/Interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "Shared/Environment.h"

#include "Types.h"
#include "DeviceTypes.h"

/// External API
///
Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/include/LibC.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef OMPTARGET_LIBC_H
#define OMPTARGET_LIBC_H

#include "Types.h"
#include "DeviceTypes.h"

extern "C" {

Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/include/Mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef OMPTARGET_MAPPING_H
#define OMPTARGET_MAPPING_H

#include "Types.h"
#include "DeviceTypes.h"

namespace ompx {

Expand Down
4 changes: 2 additions & 2 deletions offload/DeviceRTL/include/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include "Shared/Environment.h"

#include "Debug.h"
#include "DeviceTypes.h"
#include "DeviceUtils.h"
#include "Mapping.h"
#include "Types.h"
#include "Utils.h"

// Forward declaration.
struct KernelEnvironmentTy;
Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/include/Synchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#ifndef OMPTARGET_DEVICERTL_SYNCHRONIZATION_H
#define OMPTARGET_DEVICERTL_SYNCHRONIZATION_H

#include "Types.h"
#include "DeviceTypes.h"

namespace ompx {

Expand Down
100 changes: 0 additions & 100 deletions offload/DeviceRTL/include/Utils.h

This file was deleted.

4 changes: 2 additions & 2 deletions offload/DeviceRTL/src/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

#include "Allocator.h"
#include "Configuration.h"
#include "DeviceTypes.h"
#include "DeviceUtils.h"
#include "Mapping.h"
#include "Synchronization.h"
#include "Types.h"
#include "Utils.h"

using namespace ompx;

Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/src/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//===----------------------------------------------------------------------===//

#include "Configuration.h"
#include "DeviceTypes.h"
#include "State.h"
#include "Types.h"

using namespace ompx;

Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/src/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

#include "Configuration.h"
#include "Debug.h"
#include "DeviceTypes.h"
#include "Interface.h"
#include "Mapping.h"
#include "State.h"
#include "Types.h"

using namespace ompx;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
//===----------------------------------------------------------------------===//

#include "Utils.h"
#include "DeviceUtils.h"

#include "Debug.h"
#include "Interface.h"
Expand All @@ -33,7 +33,7 @@ uint64_t Pack(uint32_t LowBits, uint32_t HighBits) {
return (((uint64_t)HighBits) << 32) | (uint64_t)LowBits;
}

int32_t shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane);
int32_t shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane, int32_t Width);
int32_t shuffleDown(uint64_t Mask, int32_t Var, uint32_t LaneDelta,
int32_t Width);

Expand All @@ -44,8 +44,7 @@ uint64_t ballotSync(uint64_t Mask, int32_t Pred);
///{
#pragma omp begin declare variant match(device = {arch(amdgcn)})

int32_t shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane) {
int Width = mapping::getWarpSize();
int32_t shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane, int32_t Width) {
int Self = mapping::getThreadIdInWarp();
int Index = SrcLane + (Self & ~(Width - 1));
return __builtin_amdgcn_ds_bpermute(Index << 2, Var);
Expand Down Expand Up @@ -77,8 +76,8 @@ bool isSharedMemPtr(const void *Ptr) {
device = {arch(nvptx, nvptx64)}, \
implementation = {extension(match_any)})

int32_t shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane) {
return __nvvm_shfl_sync_idx_i32(Mask, Var, SrcLane, 0x1f);
int32_t shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane, int32_t Width) {
return __nvvm_shfl_sync_idx_i32(Mask, Var, SrcLane, Width - 1);
}

int32_t shuffleDown(uint64_t Mask, int32_t Var, uint32_t Delta, int32_t Width) {
Expand All @@ -104,8 +103,9 @@ void utils::unpack(uint64_t Val, uint32_t &LowBits, uint32_t &HighBits) {
impl::Unpack(Val, &LowBits, &HighBits);
}

int32_t utils::shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane) {
return impl::shuffle(Mask, Var, SrcLane);
int32_t utils::shuffle(uint64_t Mask, int32_t Var, int32_t SrcLane,
int32_t Width) {
return impl::shuffle(Mask, Var, SrcLane, Width);
}

int32_t utils::shuffleDown(uint64_t Mask, int32_t Var, uint32_t Delta,
Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/src/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

#include "Allocator.h"
#include "Debug.h"
#include "DeviceTypes.h"
#include "Interface.h"
#include "Mapping.h"
#include "State.h"
#include "Synchronization.h"
#include "Types.h"
#include "Workshare.h"

#include "llvm/Frontend/OpenMP/OMPDeviceConstants.h"
Expand Down
4 changes: 2 additions & 2 deletions offload/DeviceRTL/src/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
//===----------------------------------------------------------------------===//

#include "Mapping.h"
#include "DeviceTypes.h"
#include "DeviceUtils.h"
#include "Interface.h"
#include "State.h"
#include "Types.h"
#include "Utils.h"

#pragma omp begin declare target device_type(nohost)

Expand Down
2 changes: 1 addition & 1 deletion offload/DeviceRTL/src/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "Allocator.h"
#include "Configuration.h"
#include "Types.h"
#include "DeviceTypes.h"

#include "Debug.h"

Expand Down
4 changes: 2 additions & 2 deletions offload/DeviceRTL/src/Parallelism.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
//===----------------------------------------------------------------------===//

#include "Debug.h"
#include "DeviceTypes.h"
#include "DeviceUtils.h"
#include "Interface.h"
#include "Mapping.h"
#include "State.h"
#include "Synchronization.h"
#include "Types.h"
#include "Utils.h"

using namespace ompx;

Expand Down
Loading
Loading