Expected<GenericKernelTy *>
constructKernelEntry(const __tgt_offload_entry &KernelEntry,
DeviceImageTy &Image) override {
- // Create a metadata object for the exec mode global (auto-generated).
- StaticGlobalTy<llvm::omp::OMPTgtExecModeFlags> ExecModeGlobal(
- KernelEntry.name, "_exec_mode");
-
- // Retrieve execution mode for the kernel. This may fail since some kernels
- // may not have a execution mode.
- GenericGlobalHandlerTy &GHandler = Plugin::get().getGlobalHandler();
- if (auto Err = GHandler.readGlobalFromImage(*this, Image, ExecModeGlobal)) {
- DP("Failed to read execution mode for '%s': %s\n"
- "Using default GENERIC (1) execution mode\n",
- KernelEntry.name, toString(std::move(Err)).data());
- // Consume the error since it is acceptable to fail.
- consumeError(std::move(Err));
- // In some cases the execution mode is not included, so use the default.
- ExecModeGlobal.setValue(llvm::omp::OMP_TGT_EXEC_MODE_GENERIC);
- }
- // Check that the retrieved execution mode is valid.
- if (!GenericKernelTy::isValidExecutionMode(ExecModeGlobal.getValue()))
- return Plugin::error("Invalid execution mode %d for '%s'",
- ExecModeGlobal.getValue(), KernelEntry.name);
+ Expected<OMPTgtExecModeFlags> ExecModeOrErr =
+ getExecutionModeForKernel(KernelEntry.name, Image);
+ if (!ExecModeOrErr)
+ return ExecModeOrErr.takeError();
// Allocate and initialize the AMDGPU kernel.
AMDGPUKernelTy *AMDKernel = Plugin::get().allocate<AMDGPUKernelTy>();
- new (AMDKernel) AMDGPUKernelTy(KernelEntry.name, ExecModeGlobal.getValue());
+ new (AMDKernel) AMDGPUKernelTy(KernelEntry.name, ExecModeOrErr.get());
return AMDKernel;
}
#include "omptarget.h"
#include "omptargetplugin.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include "llvm/Support/Error.h"
+
#include <cstdint>
#include <limits>
return Plugin::success();
}
+Expected<OMPTgtExecModeFlags>
+GenericDeviceTy::getExecutionModeForKernel(StringRef Name,
+ DeviceImageTy &Image) {
+ // Create a metadata object for the exec mode global (auto-generated).
+ StaticGlobalTy<llvm::omp::OMPTgtExecModeFlags> ExecModeGlobal(Name.data(),
+ "_exec_mode");
+
+ // Retrieve execution mode for the kernel. This may fail since some kernels
+ // may not have an execution mode.
+ GenericGlobalHandlerTy &GHandler = Plugin::get().getGlobalHandler();
+ if (auto Err = GHandler.readGlobalFromImage(*this, Image, ExecModeGlobal)) {
+ // Consume the error since it is acceptable to fail.
+ [[maybe_unused]] std::string ErrStr = toString(std::move(Err));
+ DP("Failed to read execution mode for '%s': %s\n"
+ "Using default SPMD (2) execution mode\n",
+ Name.data(), ErrStr.data());
+
+ return OMP_TGT_EXEC_MODE_SPMD;
+ }
+
+ // Check that the retrieved execution mode is valid.
+ if (!GenericKernelTy::isValidExecutionMode(ExecModeGlobal.getValue()))
+ return Plugin::error("Invalid execution mode %d for '%s'",
+ ExecModeGlobal.getValue(), Name.data());
+
+ return ExecModeGlobal.getValue();
+}
+
Error GenericDeviceTy::registerHostPinnedMemoryBuffer(const void *Buffer,
size_t Size) {
std::lock_guard<std::shared_mutex> Lock(HostAllocationsMutex);
return ((const char *)It->first + It->second > (const char *)Buffer);
}
+ /// Return the execution mode used for kernel \p Name.
+ Expected<OMPTgtExecModeFlags> getExecutionModeForKernel(StringRef Name,
+ DeviceImageTy &Image);
+
/// Environment variables defined by the LLVM OpenMP implementation
/// regarding the initial number of streams and events.
UInt32Envar OMPX_InitialNumStreams;
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/Frontend/OpenMP/OMPConstants.h"
#include "llvm/Frontend/OpenMP/OMPGridValues.h"
+#include "llvm/Support/Error.h"
namespace llvm {
namespace omp {
DP("Entry point " DPxMOD " maps to %s (" DPxMOD ")\n", DPxPTR(&KernelEntry),
KernelEntry.name, DPxPTR(Func));
- // Create a metadata object for the exec mode global (auto-generated).
- StaticGlobalTy<llvm::omp::OMPTgtExecModeFlags> ExecModeGlobal(
- KernelEntry.name, "_exec_mode");
-
- // Retrieve execution mode for the kernel. This may fail since some kernels
- // may not have a execution mode.
- GenericGlobalHandlerTy &GHandler = Plugin::get().getGlobalHandler();
- if (auto Err = GHandler.readGlobalFromImage(*this, Image, ExecModeGlobal)) {
- // In some cases the execution mode is not included, so use the default.
- ExecModeGlobal.setValue(llvm::omp::OMP_TGT_EXEC_MODE_GENERIC);
- // Consume the error since it is acceptable to fail.
- [[maybe_unused]] std::string ErrStr = toString(std::move(Err));
-
- DP("Failed to read execution mode for '%s': %s\n"
- "Using default GENERIC (1) execution mode\n",
- KernelEntry.name, ErrStr.data());
- }
-
- // Check that the retrieved execution mode is valid.
- if (!GenericKernelTy::isValidExecutionMode(ExecModeGlobal.getValue()))
- return Plugin::error("Invalid execution mode %d for '%s'",
- ExecModeGlobal.getValue(), KernelEntry.name);
+ Expected<OMPTgtExecModeFlags> ExecModeOrErr =
+ getExecutionModeForKernel(KernelEntry.name, Image);
+ if (!ExecModeOrErr)
+ return ExecModeOrErr.takeError();
// Allocate and initialize the CUDA kernel.
CUDAKernelTy *CUDAKernel = Plugin::get().allocate<CUDAKernelTy>();
- new (CUDAKernel)
- CUDAKernelTy(KernelEntry.name, ExecModeGlobal.getValue(), Func);
+ new (CUDAKernel) CUDAKernelTy(KernelEntry.name, ExecModeOrErr.get(), Func);
return CUDAKernel;
}