[Offload] Don't check in generated files (#141982)

Previously we decided to check in files that we generate with tablegen.
The justification at the time was that it helped reviewers unfamiliar
with `offload-tblgen` see the actual changes to the headers in PRs.
After trying it for a while, it's ended up causing some headaches and is
also not how tablegen is used elsewhere in LLVM.

This changes our use of tablegen to be more conventional. Where
possible, files are still clang-formatted, but this is no longer a hard
requirement. Because `OffloadErrcodes.inc` is shared with libomptarget
it now gets generated in a more appropriate place.
This commit is contained in:
Callum Fare
2025-06-03 16:39:04 +01:00
committed by GitHub
parent e6529dcedb
commit b78bc35d16
15 changed files with 70 additions and 2768 deletions

View File

@@ -363,6 +363,8 @@ set(LIBOMPTARGET_LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE STRING
set(LIBOMPTARGET_LLVM_LIBRARY_INTDIR "${LIBOMPTARGET_INTDIR}" CACHE STRING
"Path to folder where intermediate libraries will be output")
add_subdirectory(tools/offload-tblgen)
# Build offloading plugins and device RTLs if they are available.
add_subdirectory(plugins-nextgen)
add_subdirectory(DeviceRTL)
@@ -371,7 +373,6 @@ add_subdirectory(tools)
# Build target agnostic offloading library.
add_subdirectory(libomptarget)
add_subdirectory(tools/offload-tblgen)
add_subdirectory(liboffload)
# Add tests.

View File

@@ -1,51 +0,0 @@
//===- Auto-generated file, part of the LLVM/Offload project --------------===//
//
// 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 OFFLOAD_ERRC
#error Please define the macro OFFLOAD_ERRCODE(Name, Desc, Value)
#endif
// Error codes are shared between PluginInterface and liboffload.
// To add new error codes, add them to offload/liboffload/API/Common.td and run
// the GenerateOffload target.
OFFLOAD_ERRC(SUCCESS, "success", 0)
OFFLOAD_ERRC(UNKNOWN, "unknown or internal error", 1)
OFFLOAD_ERRC(HOST_IO, "I/O error on host", 2)
OFFLOAD_ERRC(INVALID_BINARY, "a provided binary image is malformed", 3)
OFFLOAD_ERRC(INVALID_NULL_POINTER,
"a pointer argument is null when it should not be", 4)
OFFLOAD_ERRC(INVALID_ARGUMENT, "an argument is invalid", 5)
OFFLOAD_ERRC(NOT_FOUND, "requested object was not found in the binary image", 6)
OFFLOAD_ERRC(OUT_OF_RESOURCES, "out of resources", 7)
OFFLOAD_ERRC(
INVALID_SIZE,
"invalid size or dimensions (e.g., must not be zero, or is out of bounds)",
8)
OFFLOAD_ERRC(INVALID_ENUMERATION, "enumerator argument is not valid", 9)
OFFLOAD_ERRC(HOST_TOOL_NOT_FOUND,
"a required binary (linker, etc.) was not found on the host", 10)
OFFLOAD_ERRC(INVALID_VALUE, "invalid value", 11)
OFFLOAD_ERRC(UNIMPLEMENTED,
"generic error code for features currently unimplemented by the "
"device/backend",
12)
OFFLOAD_ERRC(
UNSUPPORTED,
"generic error code for features unsupported by the device/backend", 13)
OFFLOAD_ERRC(ASSEMBLE_FAILURE,
"assembler failure while processing binary image", 14)
OFFLOAD_ERRC(LINK_FAILURE, "linker failure while processing binary image", 15)
OFFLOAD_ERRC(BACKEND_FAILURE,
"the plugin backend is in an invalid or unsupported state", 16)
OFFLOAD_ERRC(INVALID_NULL_HANDLE,
"a handle argument is null when it should not be", 17)
OFFLOAD_ERRC(INVALID_PLATFORM, "invalid platform", 18)
OFFLOAD_ERRC(INVALID_DEVICE, "invalid device", 19)
OFFLOAD_ERRC(INVALID_QUEUE, "invalid queue", 20)
OFFLOAD_ERRC(INVALID_EVENT, "invalid event", 21)

View File

@@ -1,29 +1,46 @@
# The OffloadGenerate target is used to regenerate the generated files in the
# include directory. These files are checked in with the rest of the source,
# therefore it is only needed when making changes to the API.
# We want to clang-format the generated files if possible, since OffloadAPI.h is
# the main public header for liboffload. Generate them in a temporary location,
# then clang-format and copy them to the proper location. If clang-format is
# missing just copy them.
# Ideally we'd just clang-format them in place and avoid the copy but cmake
# gets confused about the same path being a byproduct of two custom commands.
find_program(CLANG_FORMAT clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
if (CLANG_FORMAT)
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/OffloadAPI.td)
set(files_to_copy "")
tablegen(OFFLOAD OffloadAPI.h -gen-api)
tablegen(OFFLOAD OffloadEntryPoints.inc -gen-entry-points)
tablegen(OFFLOAD OffloadFuncs.inc -gen-func-names)
tablegen(OFFLOAD OffloadImplFuncDecls.inc -gen-impl-func-decls)
tablegen(OFFLOAD OffloadPrint.hpp -gen-print-header)
tablegen(OFFLOAD OffloadErrcodes.inc -gen-errcodes)
macro(offload_tablegen file)
tablegen(OFFLOAD generated/${file}.gen ${ARGN})
list(APPEND files_to_copy ${file})
endmacro()
set(FILES_TO_COPY "OffloadAPI.h;OffloadEntryPoints.inc;OffloadFuncs.inc;OffloadImplFuncDecls.inc;OffloadPrint.hpp")
set(GEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include/generated)
add_public_tablegen_target(OffloadGenerate)
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CLANG_FORMAT}
-i ${TABLEGEN_OUTPUT})
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy_if_different ${FILES_TO_COPY} ${GEN_DIR})
add_custom_command(TARGET OffloadGenerate POST_BUILD COMMAND ${CMAKE_COMMAND}
-E copy_if_different OffloadErrcodes.inc "${LIBOMPTARGET_INCLUDE_DIR}/Shared/OffloadErrcodes.inc")
offload_tablegen(OffloadAPI.h -gen-api)
offload_tablegen(OffloadEntryPoints.inc -gen-entry-points)
offload_tablegen(OffloadFuncs.inc -gen-func-names)
offload_tablegen(OffloadImplFuncDecls.inc -gen-impl-func-decls)
offload_tablegen(OffloadPrint.hpp -gen-print-header)
add_public_tablegen_target(OffloadGenerate)
add_custom_target(OffloadAPI DEPENDS OffloadGenerate)
find_program(clang_format clang-format PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
if (clang_format)
foreach(file IN LISTS files_to_copy)
add_custom_command(
OUTPUT ${file}
COMMAND ${clang_format} -i generated/${file}.gen
COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}
DEPENDS generated/${file}.gen
)
add_custom_target(OffloadAPI.${file} DEPENDS ${file})
add_dependencies(OffloadAPI OffloadAPI.${file})
endforeach()
else()
message(WARNING "clang-format was not found, so the OffloadGenerate target\
will not be available. Offload will still build, but you will not be\
able to make changes to the API.")
message(WARNING "clang-format not found, the generated Offload API headers will not be formatted")
foreach(file IN LISTS files_to_copy)
add_custom_command(
OUTPUT ${file}
COMMAND ${CMAKE_COMMAND} -E copy_if_different generated/${file}.gen ${CMAKE_CURRENT_BINARY_DIR}/${file}
DEPENDS generated/${file}.gen
)
endforeach()
endif()

View File

@@ -8,6 +8,10 @@ add_llvm_library(
LINK_COMPONENTS
FrontendOpenMP
Support
DEPENDS
OffloadAPI
PluginErrcodes
)
foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
@@ -19,11 +23,13 @@ if(LLVM_HAVE_LINK_VERSION_SCRIPT)
endif()
target_include_directories(LLVMOffload PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/API
${CMAKE_CURRENT_BINARY_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include/generated
${CMAKE_CURRENT_SOURCE_DIR}/../include
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include
${CMAKE_CURRENT_BINARY_DIR}/../plugins-nextgen/common/include
)
target_compile_options(LLVMOffload PRIVATE ${offload_compile_flags})
target_link_options(LLVMOffload PRIVATE ${offload_link_flags})
@@ -39,5 +45,5 @@ set_target_properties(LLVMOffload PROPERTIES
BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
install(TARGETS LLVMOffload LIBRARY COMPONENT LLVMOffload DESTINATION "${OFFLOAD_INSTALL_LIBDIR}")
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/generated/OffloadAPI.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/generated/OffloadPrint.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/API/OffloadAPI.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/API/OffloadPrint.hpp DESTINATION ${CMAKE_INSTALL_PREFIX}/include/offload)

File diff suppressed because it is too large Load Diff

View File

@@ -1,903 +0,0 @@
//===- Auto-generated file, part of the LLVM/Offload project --------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
///////////////////////////////////////////////////////////////////////////////
llvm::Error olInit_val() {
if (offloadConfig().ValidationEnabled) {
}
return llvm::offload::olInit_impl();
}
OL_APIEXPORT ol_result_t OL_APICALL olInit() {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olInit";
}
ol_result_t Result = llvmErrorToOffloadError(olInit_val());
if (offloadConfig().TracingEnabled) {
llvm::errs() << "()";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olInitWithCodeLoc(ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olInit();
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olShutDown_val() {
if (offloadConfig().ValidationEnabled) {
}
return llvm::offload::olShutDown_impl();
}
OL_APIEXPORT ol_result_t OL_APICALL olShutDown() {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olShutDown";
}
ol_result_t Result = llvmErrorToOffloadError(olShutDown_val());
if (offloadConfig().TracingEnabled) {
llvm::errs() << "()";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olShutDownWithCodeLoc(ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olShutDown();
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetPlatformInfo_val(ol_platform_handle_t Platform,
ol_platform_info_t PropName, size_t PropSize,
void *PropValue) {
if (offloadConfig().ValidationEnabled) {
if (PropSize == 0) {
return createOffloadError(error::ErrorCode::INVALID_SIZE,
"validation failure: PropSize == 0");
}
if (NULL == Platform) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Platform");
}
if (NULL == PropValue) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == PropValue");
}
}
return llvm::offload::olGetPlatformInfo_impl(Platform, PropName, PropSize,
PropValue);
}
OL_APIEXPORT ol_result_t OL_APICALL
olGetPlatformInfo(ol_platform_handle_t Platform, ol_platform_info_t PropName,
size_t PropSize, void *PropValue) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olGetPlatformInfo";
}
ol_result_t Result = llvmErrorToOffloadError(
olGetPlatformInfo_val(Platform, PropName, PropSize, PropValue));
if (offloadConfig().TracingEnabled) {
ol_get_platform_info_params_t Params = {&Platform, &PropName, &PropSize,
&PropValue};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olGetPlatformInfoWithCodeLoc(ol_platform_handle_t Platform,
ol_platform_info_t PropName,
size_t PropSize, void *PropValue,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result =
::olGetPlatformInfo(Platform, PropName, PropSize, PropValue);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetPlatformInfoSize_val(ol_platform_handle_t Platform,
ol_platform_info_t PropName,
size_t *PropSizeRet) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Platform) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Platform");
}
if (NULL == PropSizeRet) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == PropSizeRet");
}
}
return llvm::offload::olGetPlatformInfoSize_impl(Platform, PropName,
PropSizeRet);
}
OL_APIEXPORT ol_result_t OL_APICALL
olGetPlatformInfoSize(ol_platform_handle_t Platform,
ol_platform_info_t PropName, size_t *PropSizeRet) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olGetPlatformInfoSize";
}
ol_result_t Result = llvmErrorToOffloadError(
olGetPlatformInfoSize_val(Platform, PropName, PropSizeRet));
if (offloadConfig().TracingEnabled) {
ol_get_platform_info_size_params_t Params = {&Platform, &PropName,
&PropSizeRet};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olGetPlatformInfoSizeWithCodeLoc(ol_platform_handle_t Platform,
ol_platform_info_t PropName,
size_t *PropSizeRet,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olGetPlatformInfoSize(Platform, PropName, PropSizeRet);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olIterateDevices_val(ol_device_iterate_cb_t Callback,
void *UserData) {
if (offloadConfig().ValidationEnabled) {
}
return llvm::offload::olIterateDevices_impl(Callback, UserData);
}
OL_APIEXPORT ol_result_t OL_APICALL
olIterateDevices(ol_device_iterate_cb_t Callback, void *UserData) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olIterateDevices";
}
ol_result_t Result =
llvmErrorToOffloadError(olIterateDevices_val(Callback, UserData));
if (offloadConfig().TracingEnabled) {
ol_iterate_devices_params_t Params = {&Callback, &UserData};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olIterateDevicesWithCodeLoc(ol_device_iterate_cb_t Callback,
void *UserData,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olIterateDevices(Callback, UserData);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetDeviceInfo_val(ol_device_handle_t Device,
ol_device_info_t PropName, size_t PropSize,
void *PropValue) {
if (offloadConfig().ValidationEnabled) {
if (PropSize == 0) {
return createOffloadError(error::ErrorCode::INVALID_SIZE,
"validation failure: PropSize == 0");
}
if (NULL == Device) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Device");
}
if (NULL == PropValue) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == PropValue");
}
}
return llvm::offload::olGetDeviceInfo_impl(Device, PropName, PropSize,
PropValue);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfo(ol_device_handle_t Device,
ol_device_info_t PropName,
size_t PropSize,
void *PropValue) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olGetDeviceInfo";
}
ol_result_t Result = llvmErrorToOffloadError(
olGetDeviceInfo_val(Device, PropName, PropSize, PropValue));
if (offloadConfig().TracingEnabled) {
ol_get_device_info_params_t Params = {&Device, &PropName, &PropSize,
&PropValue};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olGetDeviceInfoWithCodeLoc(ol_device_handle_t Device,
ol_device_info_t PropName,
size_t PropSize, void *PropValue,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olGetDeviceInfo(Device, PropName, PropSize, PropValue);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetDeviceInfoSize_val(ol_device_handle_t Device,
ol_device_info_t PropName,
size_t *PropSizeRet) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Device) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Device");
}
if (NULL == PropSizeRet) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == PropSizeRet");
}
}
return llvm::offload::olGetDeviceInfoSize_impl(Device, PropName, PropSizeRet);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetDeviceInfoSize(
ol_device_handle_t Device, ol_device_info_t PropName, size_t *PropSizeRet) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olGetDeviceInfoSize";
}
ol_result_t Result = llvmErrorToOffloadError(
olGetDeviceInfoSize_val(Device, PropName, PropSizeRet));
if (offloadConfig().TracingEnabled) {
ol_get_device_info_size_params_t Params = {&Device, &PropName,
&PropSizeRet};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olGetDeviceInfoSizeWithCodeLoc(ol_device_handle_t Device,
ol_device_info_t PropName,
size_t *PropSizeRet,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olGetDeviceInfoSize(Device, PropName, PropSizeRet);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olMemAlloc_val(ol_device_handle_t Device, ol_alloc_type_t Type,
size_t Size, void **AllocationOut) {
if (offloadConfig().ValidationEnabled) {
if (Size == 0) {
return createOffloadError(error::ErrorCode::INVALID_SIZE,
"validation failure: Size == 0");
}
if (NULL == Device) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Device");
}
if (NULL == AllocationOut) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == AllocationOut");
}
}
return llvm::offload::olMemAlloc_impl(Device, Type, Size, AllocationOut);
}
OL_APIEXPORT ol_result_t OL_APICALL olMemAlloc(ol_device_handle_t Device,
ol_alloc_type_t Type,
size_t Size,
void **AllocationOut) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olMemAlloc";
}
ol_result_t Result = llvmErrorToOffloadError(
olMemAlloc_val(Device, Type, Size, AllocationOut));
if (offloadConfig().TracingEnabled) {
ol_mem_alloc_params_t Params = {&Device, &Type, &Size, &AllocationOut};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olMemAllocWithCodeLoc(ol_device_handle_t Device,
ol_alloc_type_t Type, size_t Size,
void **AllocationOut,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olMemAlloc(Device, Type, Size, AllocationOut);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olMemFree_val(void *Address) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Address) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == Address");
}
}
return llvm::offload::olMemFree_impl(Address);
}
OL_APIEXPORT ol_result_t OL_APICALL olMemFree(void *Address) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olMemFree";
}
ol_result_t Result = llvmErrorToOffloadError(olMemFree_val(Address));
if (offloadConfig().TracingEnabled) {
ol_mem_free_params_t Params = {&Address};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olMemFreeWithCodeLoc(void *Address,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olMemFree(Address);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olMemcpy_val(ol_queue_handle_t Queue, void *DstPtr,
ol_device_handle_t DstDevice, void *SrcPtr,
ol_device_handle_t SrcDevice, size_t Size,
ol_event_handle_t *EventOut) {
if (offloadConfig().ValidationEnabled) {
if (Queue == NULL && EventOut != NULL) {
return createOffloadError(
error::ErrorCode::INVALID_ARGUMENT,
"validation failure: Queue == NULL && EventOut != NULL");
}
if (NULL == DstDevice) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == DstDevice");
}
if (NULL == SrcDevice) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == SrcDevice");
}
if (NULL == DstPtr) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == DstPtr");
}
if (NULL == SrcPtr) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == SrcPtr");
}
}
return llvm::offload::olMemcpy_impl(Queue, DstPtr, DstDevice, SrcPtr,
SrcDevice, Size, EventOut);
}
OL_APIEXPORT ol_result_t OL_APICALL
olMemcpy(ol_queue_handle_t Queue, void *DstPtr, ol_device_handle_t DstDevice,
void *SrcPtr, ol_device_handle_t SrcDevice, size_t Size,
ol_event_handle_t *EventOut) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olMemcpy";
}
ol_result_t Result = llvmErrorToOffloadError(olMemcpy_val(
Queue, DstPtr, DstDevice, SrcPtr, SrcDevice, Size, EventOut));
if (offloadConfig().TracingEnabled) {
ol_memcpy_params_t Params = {&Queue, &DstPtr, &DstDevice, &SrcPtr,
&SrcDevice, &Size, &EventOut};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olMemcpyWithCodeLoc(ol_queue_handle_t Queue, void *DstPtr,
ol_device_handle_t DstDevice, void *SrcPtr,
ol_device_handle_t SrcDevice, size_t Size,
ol_event_handle_t *EventOut,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result =
::olMemcpy(Queue, DstPtr, DstDevice, SrcPtr, SrcDevice, Size, EventOut);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olCreateQueue_val(ol_device_handle_t Device,
ol_queue_handle_t *Queue) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Device) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Device");
}
if (NULL == Queue) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == Queue");
}
}
return llvm::offload::olCreateQueue_impl(Device, Queue);
}
OL_APIEXPORT ol_result_t OL_APICALL olCreateQueue(ol_device_handle_t Device,
ol_queue_handle_t *Queue) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olCreateQueue";
}
ol_result_t Result =
llvmErrorToOffloadError(olCreateQueue_val(Device, Queue));
if (offloadConfig().TracingEnabled) {
ol_create_queue_params_t Params = {&Device, &Queue};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olCreateQueueWithCodeLoc(ol_device_handle_t Device,
ol_queue_handle_t *Queue,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olCreateQueue(Device, Queue);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olDestroyQueue_val(ol_queue_handle_t Queue) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Queue) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Queue");
}
}
return llvm::offload::olDestroyQueue_impl(Queue);
}
OL_APIEXPORT ol_result_t OL_APICALL olDestroyQueue(ol_queue_handle_t Queue) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olDestroyQueue";
}
ol_result_t Result = llvmErrorToOffloadError(olDestroyQueue_val(Queue));
if (offloadConfig().TracingEnabled) {
ol_destroy_queue_params_t Params = {&Queue};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olDestroyQueueWithCodeLoc(ol_queue_handle_t Queue,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olDestroyQueue(Queue);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olWaitQueue_val(ol_queue_handle_t Queue) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Queue) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Queue");
}
}
return llvm::offload::olWaitQueue_impl(Queue);
}
OL_APIEXPORT ol_result_t OL_APICALL olWaitQueue(ol_queue_handle_t Queue) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olWaitQueue";
}
ol_result_t Result = llvmErrorToOffloadError(olWaitQueue_val(Queue));
if (offloadConfig().TracingEnabled) {
ol_wait_queue_params_t Params = {&Queue};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olWaitQueueWithCodeLoc(ol_queue_handle_t Queue,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olWaitQueue(Queue);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olDestroyEvent_val(ol_event_handle_t Event) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Event) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Event");
}
}
return llvm::offload::olDestroyEvent_impl(Event);
}
OL_APIEXPORT ol_result_t OL_APICALL olDestroyEvent(ol_event_handle_t Event) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olDestroyEvent";
}
ol_result_t Result = llvmErrorToOffloadError(olDestroyEvent_val(Event));
if (offloadConfig().TracingEnabled) {
ol_destroy_event_params_t Params = {&Event};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olDestroyEventWithCodeLoc(ol_event_handle_t Event,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olDestroyEvent(Event);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olWaitEvent_val(ol_event_handle_t Event) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Event) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Event");
}
}
return llvm::offload::olWaitEvent_impl(Event);
}
OL_APIEXPORT ol_result_t OL_APICALL olWaitEvent(ol_event_handle_t Event) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olWaitEvent";
}
ol_result_t Result = llvmErrorToOffloadError(olWaitEvent_val(Event));
if (offloadConfig().TracingEnabled) {
ol_wait_event_params_t Params = {&Event};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olWaitEventWithCodeLoc(ol_event_handle_t Event,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olWaitEvent(Event);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olCreateProgram_val(ol_device_handle_t Device, const void *ProgData,
size_t ProgDataSize,
ol_program_handle_t *Program) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Device) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Device");
}
if (NULL == ProgData) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == ProgData");
}
if (NULL == Program) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == Program");
}
}
return llvm::offload::olCreateProgram_impl(Device, ProgData, ProgDataSize,
Program);
}
OL_APIEXPORT ol_result_t OL_APICALL
olCreateProgram(ol_device_handle_t Device, const void *ProgData,
size_t ProgDataSize, ol_program_handle_t *Program) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olCreateProgram";
}
ol_result_t Result = llvmErrorToOffloadError(
olCreateProgram_val(Device, ProgData, ProgDataSize, Program));
if (offloadConfig().TracingEnabled) {
ol_create_program_params_t Params = {&Device, &ProgData, &ProgDataSize,
&Program};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olCreateProgramWithCodeLoc(ol_device_handle_t Device,
const void *ProgData,
size_t ProgDataSize,
ol_program_handle_t *Program,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result =
::olCreateProgram(Device, ProgData, ProgDataSize, Program);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olDestroyProgram_val(ol_program_handle_t Program) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Program) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Program");
}
}
return llvm::offload::olDestroyProgram_impl(Program);
}
OL_APIEXPORT ol_result_t OL_APICALL
olDestroyProgram(ol_program_handle_t Program) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olDestroyProgram";
}
ol_result_t Result = llvmErrorToOffloadError(olDestroyProgram_val(Program));
if (offloadConfig().TracingEnabled) {
ol_destroy_program_params_t Params = {&Program};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olDestroyProgramWithCodeLoc(ol_program_handle_t Program,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olDestroyProgram(Program);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error olGetKernel_val(ol_program_handle_t Program, const char *KernelName,
ol_kernel_handle_t *Kernel) {
if (offloadConfig().ValidationEnabled) {
if (NULL == Program) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Program");
}
if (NULL == KernelName) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == KernelName");
}
if (NULL == Kernel) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == Kernel");
}
}
return llvm::offload::olGetKernel_impl(Program, KernelName, Kernel);
}
OL_APIEXPORT ol_result_t OL_APICALL olGetKernel(ol_program_handle_t Program,
const char *KernelName,
ol_kernel_handle_t *Kernel) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olGetKernel";
}
ol_result_t Result =
llvmErrorToOffloadError(olGetKernel_val(Program, KernelName, Kernel));
if (offloadConfig().TracingEnabled) {
ol_get_kernel_params_t Params = {&Program, &KernelName, &Kernel};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olGetKernelWithCodeLoc(ol_program_handle_t Program,
const char *KernelName,
ol_kernel_handle_t *Kernel,
ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result = ::olGetKernel(Program, KernelName, Kernel);
currentCodeLocation() = nullptr;
return Result;
}
///////////////////////////////////////////////////////////////////////////////
llvm::Error
olLaunchKernel_val(ol_queue_handle_t Queue, ol_device_handle_t Device,
ol_kernel_handle_t Kernel, const void *ArgumentsData,
size_t ArgumentsSize,
const ol_kernel_launch_size_args_t *LaunchSizeArgs,
ol_event_handle_t *EventOut) {
if (offloadConfig().ValidationEnabled) {
if (Queue == NULL && EventOut != NULL) {
return createOffloadError(
error::ErrorCode::INVALID_ARGUMENT,
"validation failure: Queue == NULL && EventOut != NULL");
}
if (NULL == Device) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Device");
}
if (NULL == Kernel) {
return createOffloadError(error::ErrorCode::INVALID_NULL_HANDLE,
"validation failure: NULL == Kernel");
}
if (NULL == ArgumentsData) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == ArgumentsData");
}
if (NULL == LaunchSizeArgs) {
return createOffloadError(error::ErrorCode::INVALID_NULL_POINTER,
"validation failure: NULL == LaunchSizeArgs");
}
}
return llvm::offload::olLaunchKernel_impl(Queue, Device, Kernel,
ArgumentsData, ArgumentsSize,
LaunchSizeArgs, EventOut);
}
OL_APIEXPORT ol_result_t OL_APICALL olLaunchKernel(
ol_queue_handle_t Queue, ol_device_handle_t Device,
ol_kernel_handle_t Kernel, const void *ArgumentsData, size_t ArgumentsSize,
const ol_kernel_launch_size_args_t *LaunchSizeArgs,
ol_event_handle_t *EventOut) {
if (offloadConfig().TracingEnabled) {
llvm::errs() << "---> olLaunchKernel";
}
ol_result_t Result = llvmErrorToOffloadError(
olLaunchKernel_val(Queue, Device, Kernel, ArgumentsData, ArgumentsSize,
LaunchSizeArgs, EventOut));
if (offloadConfig().TracingEnabled) {
ol_launch_kernel_params_t Params = {
&Queue, &Device, &Kernel, &ArgumentsData,
&ArgumentsSize, &LaunchSizeArgs, &EventOut};
llvm::errs() << "(" << &Params << ")";
llvm::errs() << "-> " << Result << "\n";
if (Result && Result->Details) {
llvm::errs() << " *Error Details* " << Result->Details << " \n";
}
}
return Result;
}
ol_result_t olLaunchKernelWithCodeLoc(
ol_queue_handle_t Queue, ol_device_handle_t Device,
ol_kernel_handle_t Kernel, const void *ArgumentsData, size_t ArgumentsSize,
const ol_kernel_launch_size_args_t *LaunchSizeArgs,
ol_event_handle_t *EventOut, ol_code_location_t *CodeLocation) {
currentCodeLocation() = CodeLocation;
ol_result_t Result =
::olLaunchKernel(Queue, Device, Kernel, ArgumentsData, ArgumentsSize,
LaunchSizeArgs, EventOut);
currentCodeLocation() = nullptr;
return Result;
}

View File

@@ -1,52 +0,0 @@
//===- Auto-generated file, part of the LLVM/Offload project --------------===//
//
// 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 OFFLOAD_FUNC
#error Please define the macro OFFLOAD_FUNC(Function)
#endif
OFFLOAD_FUNC(olInit)
OFFLOAD_FUNC(olShutDown)
OFFLOAD_FUNC(olGetPlatformInfo)
OFFLOAD_FUNC(olGetPlatformInfoSize)
OFFLOAD_FUNC(olIterateDevices)
OFFLOAD_FUNC(olGetDeviceInfo)
OFFLOAD_FUNC(olGetDeviceInfoSize)
OFFLOAD_FUNC(olMemAlloc)
OFFLOAD_FUNC(olMemFree)
OFFLOAD_FUNC(olMemcpy)
OFFLOAD_FUNC(olCreateQueue)
OFFLOAD_FUNC(olDestroyQueue)
OFFLOAD_FUNC(olWaitQueue)
OFFLOAD_FUNC(olDestroyEvent)
OFFLOAD_FUNC(olWaitEvent)
OFFLOAD_FUNC(olCreateProgram)
OFFLOAD_FUNC(olDestroyProgram)
OFFLOAD_FUNC(olGetKernel)
OFFLOAD_FUNC(olLaunchKernel)
OFFLOAD_FUNC(olInitWithCodeLoc)
OFFLOAD_FUNC(olShutDownWithCodeLoc)
OFFLOAD_FUNC(olGetPlatformInfoWithCodeLoc)
OFFLOAD_FUNC(olGetPlatformInfoSizeWithCodeLoc)
OFFLOAD_FUNC(olIterateDevicesWithCodeLoc)
OFFLOAD_FUNC(olGetDeviceInfoWithCodeLoc)
OFFLOAD_FUNC(olGetDeviceInfoSizeWithCodeLoc)
OFFLOAD_FUNC(olMemAllocWithCodeLoc)
OFFLOAD_FUNC(olMemFreeWithCodeLoc)
OFFLOAD_FUNC(olMemcpyWithCodeLoc)
OFFLOAD_FUNC(olCreateQueueWithCodeLoc)
OFFLOAD_FUNC(olDestroyQueueWithCodeLoc)
OFFLOAD_FUNC(olWaitQueueWithCodeLoc)
OFFLOAD_FUNC(olDestroyEventWithCodeLoc)
OFFLOAD_FUNC(olWaitEventWithCodeLoc)
OFFLOAD_FUNC(olCreateProgramWithCodeLoc)
OFFLOAD_FUNC(olDestroyProgramWithCodeLoc)
OFFLOAD_FUNC(olGetKernelWithCodeLoc)
OFFLOAD_FUNC(olLaunchKernelWithCodeLoc)
#undef OFFLOAD_FUNC

View File

@@ -1,60 +0,0 @@
//===- Auto-generated file, part of the LLVM/Offload project --------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
Error olInit_impl();
Error olShutDown_impl();
Error olGetPlatformInfo_impl(ol_platform_handle_t Platform,
ol_platform_info_t PropName, size_t PropSize,
void *PropValue);
Error olGetPlatformInfoSize_impl(ol_platform_handle_t Platform,
ol_platform_info_t PropName,
size_t *PropSizeRet);
Error olIterateDevices_impl(ol_device_iterate_cb_t Callback, void *UserData);
Error olGetDeviceInfo_impl(ol_device_handle_t Device, ol_device_info_t PropName,
size_t PropSize, void *PropValue);
Error olGetDeviceInfoSize_impl(ol_device_handle_t Device,
ol_device_info_t PropName, size_t *PropSizeRet);
Error olMemAlloc_impl(ol_device_handle_t Device, ol_alloc_type_t Type,
size_t Size, void **AllocationOut);
Error olMemFree_impl(void *Address);
Error olMemcpy_impl(ol_queue_handle_t Queue, void *DstPtr,
ol_device_handle_t DstDevice, void *SrcPtr,
ol_device_handle_t SrcDevice, size_t Size,
ol_event_handle_t *EventOut);
Error olCreateQueue_impl(ol_device_handle_t Device, ol_queue_handle_t *Queue);
Error olDestroyQueue_impl(ol_queue_handle_t Queue);
Error olWaitQueue_impl(ol_queue_handle_t Queue);
Error olDestroyEvent_impl(ol_event_handle_t Event);
Error olWaitEvent_impl(ol_event_handle_t Event);
Error olCreateProgram_impl(ol_device_handle_t Device, const void *ProgData,
size_t ProgDataSize, ol_program_handle_t *Program);
Error olDestroyProgram_impl(ol_program_handle_t Program);
Error olGetKernel_impl(ol_program_handle_t Program, const char *KernelName,
ol_kernel_handle_t *Kernel);
Error olLaunchKernel_impl(ol_queue_handle_t Queue, ol_device_handle_t Device,
ol_kernel_handle_t Kernel, const void *ArgumentsData,
size_t ArgumentsSize,
const ol_kernel_launch_size_args_t *LaunchSizeArgs,
ol_event_handle_t *EventOut);

View File

@@ -1,645 +0,0 @@
//===- Auto-generated file, part of the LLVM/Offload project --------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// Auto-generated file, do not manually edit.
#pragma once
#include <OffloadAPI.h>
#include <llvm/Support/raw_ostream.h>
template <typename T>
inline ol_result_t printPtr(llvm::raw_ostream &os, const T *ptr);
template <typename T>
inline void printTagged(llvm::raw_ostream &os, const void *ptr, T value,
size_t size);
template <typename T> struct is_handle : std::false_type {};
template <> struct is_handle<ol_platform_handle_t> : std::true_type {};
template <> struct is_handle<ol_device_handle_t> : std::true_type {};
template <> struct is_handle<ol_context_handle_t> : std::true_type {};
template <> struct is_handle<ol_queue_handle_t> : std::true_type {};
template <> struct is_handle<ol_event_handle_t> : std::true_type {};
template <> struct is_handle<ol_program_handle_t> : std::true_type {};
template <typename T> inline constexpr bool is_handle_v = is_handle<T>::value;
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_errc_t value);
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_platform_info_t value);
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_platform_backend_t value);
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_device_type_t value);
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_device_info_t value);
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_alloc_type_t value);
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ol_errc_t type
/// @returns llvm::raw_ostream &
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_errc_t value) {
switch (value) {
case OL_ERRC_SUCCESS:
os << "OL_ERRC_SUCCESS";
break;
case OL_ERRC_UNKNOWN:
os << "OL_ERRC_UNKNOWN";
break;
case OL_ERRC_HOST_IO:
os << "OL_ERRC_HOST_IO";
break;
case OL_ERRC_INVALID_BINARY:
os << "OL_ERRC_INVALID_BINARY";
break;
case OL_ERRC_INVALID_NULL_POINTER:
os << "OL_ERRC_INVALID_NULL_POINTER";
break;
case OL_ERRC_INVALID_ARGUMENT:
os << "OL_ERRC_INVALID_ARGUMENT";
break;
case OL_ERRC_NOT_FOUND:
os << "OL_ERRC_NOT_FOUND";
break;
case OL_ERRC_OUT_OF_RESOURCES:
os << "OL_ERRC_OUT_OF_RESOURCES";
break;
case OL_ERRC_INVALID_SIZE:
os << "OL_ERRC_INVALID_SIZE";
break;
case OL_ERRC_INVALID_ENUMERATION:
os << "OL_ERRC_INVALID_ENUMERATION";
break;
case OL_ERRC_HOST_TOOL_NOT_FOUND:
os << "OL_ERRC_HOST_TOOL_NOT_FOUND";
break;
case OL_ERRC_INVALID_VALUE:
os << "OL_ERRC_INVALID_VALUE";
break;
case OL_ERRC_UNIMPLEMENTED:
os << "OL_ERRC_UNIMPLEMENTED";
break;
case OL_ERRC_UNSUPPORTED:
os << "OL_ERRC_UNSUPPORTED";
break;
case OL_ERRC_ASSEMBLE_FAILURE:
os << "OL_ERRC_ASSEMBLE_FAILURE";
break;
case OL_ERRC_LINK_FAILURE:
os << "OL_ERRC_LINK_FAILURE";
break;
case OL_ERRC_BACKEND_FAILURE:
os << "OL_ERRC_BACKEND_FAILURE";
break;
case OL_ERRC_INVALID_NULL_HANDLE:
os << "OL_ERRC_INVALID_NULL_HANDLE";
break;
case OL_ERRC_INVALID_PLATFORM:
os << "OL_ERRC_INVALID_PLATFORM";
break;
case OL_ERRC_INVALID_DEVICE:
os << "OL_ERRC_INVALID_DEVICE";
break;
case OL_ERRC_INVALID_QUEUE:
os << "OL_ERRC_INVALID_QUEUE";
break;
case OL_ERRC_INVALID_EVENT:
os << "OL_ERRC_INVALID_EVENT";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ol_platform_info_t type
/// @returns llvm::raw_ostream &
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_platform_info_t value) {
switch (value) {
case OL_PLATFORM_INFO_NAME:
os << "OL_PLATFORM_INFO_NAME";
break;
case OL_PLATFORM_INFO_VENDOR_NAME:
os << "OL_PLATFORM_INFO_VENDOR_NAME";
break;
case OL_PLATFORM_INFO_VERSION:
os << "OL_PLATFORM_INFO_VERSION";
break;
case OL_PLATFORM_INFO_BACKEND:
os << "OL_PLATFORM_INFO_BACKEND";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print type-tagged ol_platform_info_t enum value
/// @returns llvm::raw_ostream &
template <>
inline void printTagged(llvm::raw_ostream &os, const void *ptr,
ol_platform_info_t value, size_t size) {
if (ptr == NULL) {
printPtr(os, ptr);
return;
}
switch (value) {
case OL_PLATFORM_INFO_NAME: {
printPtr(os, (const char *)ptr);
break;
}
case OL_PLATFORM_INFO_VENDOR_NAME: {
printPtr(os, (const char *)ptr);
break;
}
case OL_PLATFORM_INFO_VERSION: {
printPtr(os, (const char *)ptr);
break;
}
case OL_PLATFORM_INFO_BACKEND: {
const ol_platform_backend_t *const tptr =
(const ol_platform_backend_t *const)ptr;
os << (const void *)tptr << " (";
os << *tptr;
os << ")";
break;
}
default:
os << "unknown enumerator";
break;
}
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ol_platform_backend_t type
/// @returns llvm::raw_ostream &
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_platform_backend_t value) {
switch (value) {
case OL_PLATFORM_BACKEND_UNKNOWN:
os << "OL_PLATFORM_BACKEND_UNKNOWN";
break;
case OL_PLATFORM_BACKEND_CUDA:
os << "OL_PLATFORM_BACKEND_CUDA";
break;
case OL_PLATFORM_BACKEND_AMDGPU:
os << "OL_PLATFORM_BACKEND_AMDGPU";
break;
case OL_PLATFORM_BACKEND_HOST:
os << "OL_PLATFORM_BACKEND_HOST";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ol_device_type_t type
/// @returns llvm::raw_ostream &
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_device_type_t value) {
switch (value) {
case OL_DEVICE_TYPE_DEFAULT:
os << "OL_DEVICE_TYPE_DEFAULT";
break;
case OL_DEVICE_TYPE_ALL:
os << "OL_DEVICE_TYPE_ALL";
break;
case OL_DEVICE_TYPE_GPU:
os << "OL_DEVICE_TYPE_GPU";
break;
case OL_DEVICE_TYPE_CPU:
os << "OL_DEVICE_TYPE_CPU";
break;
case OL_DEVICE_TYPE_HOST:
os << "OL_DEVICE_TYPE_HOST";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ol_device_info_t type
/// @returns llvm::raw_ostream &
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_device_info_t value) {
switch (value) {
case OL_DEVICE_INFO_TYPE:
os << "OL_DEVICE_INFO_TYPE";
break;
case OL_DEVICE_INFO_PLATFORM:
os << "OL_DEVICE_INFO_PLATFORM";
break;
case OL_DEVICE_INFO_NAME:
os << "OL_DEVICE_INFO_NAME";
break;
case OL_DEVICE_INFO_VENDOR:
os << "OL_DEVICE_INFO_VENDOR";
break;
case OL_DEVICE_INFO_DRIVER_VERSION:
os << "OL_DEVICE_INFO_DRIVER_VERSION";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print type-tagged ol_device_info_t enum value
/// @returns llvm::raw_ostream &
template <>
inline void printTagged(llvm::raw_ostream &os, const void *ptr,
ol_device_info_t value, size_t size) {
if (ptr == NULL) {
printPtr(os, ptr);
return;
}
switch (value) {
case OL_DEVICE_INFO_TYPE: {
const ol_device_type_t *const tptr = (const ol_device_type_t *const)ptr;
os << (const void *)tptr << " (";
os << *tptr;
os << ")";
break;
}
case OL_DEVICE_INFO_PLATFORM: {
const ol_platform_handle_t *const tptr =
(const ol_platform_handle_t *const)ptr;
os << (const void *)tptr << " (";
os << *tptr;
os << ")";
break;
}
case OL_DEVICE_INFO_NAME: {
printPtr(os, (const char *)ptr);
break;
}
case OL_DEVICE_INFO_VENDOR: {
printPtr(os, (const char *)ptr);
break;
}
case OL_DEVICE_INFO_DRIVER_VERSION: {
printPtr(os, (const char *)ptr);
break;
}
default:
os << "unknown enumerator";
break;
}
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ol_alloc_type_t type
/// @returns llvm::raw_ostream &
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
enum ol_alloc_type_t value) {
switch (value) {
case OL_ALLOC_TYPE_HOST:
os << "OL_ALLOC_TYPE_HOST";
break;
case OL_ALLOC_TYPE_DEVICE:
os << "OL_ALLOC_TYPE_DEVICE";
break;
case OL_ALLOC_TYPE_MANAGED:
os << "OL_ALLOC_TYPE_MANAGED";
break;
default:
os << "unknown enumerator";
break;
}
return os;
}
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const ol_error_struct_t *Err) {
if (Err == nullptr) {
os << "OL_SUCCESS";
} else {
os << Err->Code;
}
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ol_code_location_t type
/// @returns llvm::raw_ostream &
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const struct ol_code_location_t params) {
os << "(struct ol_code_location_t){";
os << ".FunctionName = ";
printPtr(os, params.FunctionName);
os << ", ";
os << ".SourceFile = ";
printPtr(os, params.SourceFile);
os << ", ";
os << ".LineNumber = ";
os << params.LineNumber;
os << ", ";
os << ".ColumnNumber = ";
os << params.ColumnNumber;
os << "}";
return os;
}
///////////////////////////////////////////////////////////////////////////////
/// @brief Print operator for the ol_kernel_launch_size_args_t type
/// @returns llvm::raw_ostream &
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_kernel_launch_size_args_t params) {
os << "(struct ol_kernel_launch_size_args_t){";
os << ".Dimensions = ";
os << params.Dimensions;
os << ", ";
os << ".NumGroupsX = ";
os << params.NumGroupsX;
os << ", ";
os << ".NumGroupsY = ";
os << params.NumGroupsY;
os << ", ";
os << ".NumGroupsZ = ";
os << params.NumGroupsZ;
os << ", ";
os << ".GroupSizeX = ";
os << params.GroupSizeX;
os << ", ";
os << ".GroupSizeY = ";
os << params.GroupSizeY;
os << ", ";
os << ".GroupSizeZ = ";
os << params.GroupSizeZ;
os << ", ";
os << ".DynSharedMemory = ";
os << params.DynSharedMemory;
os << "}";
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_get_platform_info_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
os << ".PropName = ";
os << *params->pPropName;
os << ", ";
os << ".PropSize = ";
os << *params->pPropSize;
os << ", ";
os << ".PropValue = ";
printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_get_platform_info_size_params_t *params) {
os << ".Platform = ";
printPtr(os, *params->pPlatform);
os << ", ";
os << ".PropName = ";
os << *params->pPropName;
os << ", ";
os << ".PropSizeRet = ";
printPtr(os, *params->pPropSizeRet);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_iterate_devices_params_t *params) {
os << ".Callback = ";
os << reinterpret_cast<void *>(*params->pCallback);
os << ", ";
os << ".UserData = ";
printPtr(os, *params->pUserData);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_get_device_info_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
os << ".PropName = ";
os << *params->pPropName;
os << ", ";
os << ".PropSize = ";
os << *params->pPropSize;
os << ", ";
os << ".PropValue = ";
printTagged(os, *params->pPropValue, *params->pPropName, *params->pPropSize);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_get_device_info_size_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
os << ".PropName = ";
os << *params->pPropName;
os << ", ";
os << ".PropSizeRet = ";
printPtr(os, *params->pPropSizeRet);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os, const struct ol_mem_alloc_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
os << ".Type = ";
os << *params->pType;
os << ", ";
os << ".Size = ";
os << *params->pSize;
os << ", ";
os << ".AllocationOut = ";
printPtr(os, *params->pAllocationOut);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os, const struct ol_mem_free_params_t *params) {
os << ".Address = ";
printPtr(os, *params->pAddress);
return os;
}
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
const struct ol_memcpy_params_t *params) {
os << ".Queue = ";
printPtr(os, *params->pQueue);
os << ", ";
os << ".DstPtr = ";
printPtr(os, *params->pDstPtr);
os << ", ";
os << ".DstDevice = ";
printPtr(os, *params->pDstDevice);
os << ", ";
os << ".SrcPtr = ";
printPtr(os, *params->pSrcPtr);
os << ", ";
os << ".SrcDevice = ";
printPtr(os, *params->pSrcDevice);
os << ", ";
os << ".Size = ";
os << *params->pSize;
os << ", ";
os << ".EventOut = ";
printPtr(os, *params->pEventOut);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_create_queue_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
os << ".Queue = ";
printPtr(os, *params->pQueue);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_destroy_queue_params_t *params) {
os << ".Queue = ";
printPtr(os, *params->pQueue);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os, const struct ol_wait_queue_params_t *params) {
os << ".Queue = ";
printPtr(os, *params->pQueue);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_destroy_event_params_t *params) {
os << ".Event = ";
printPtr(os, *params->pEvent);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os, const struct ol_wait_event_params_t *params) {
os << ".Event = ";
printPtr(os, *params->pEvent);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_create_program_params_t *params) {
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
os << ".ProgData = ";
printPtr(os, *params->pProgData);
os << ", ";
os << ".ProgDataSize = ";
os << *params->pProgDataSize;
os << ", ";
os << ".Program = ";
printPtr(os, *params->pProgram);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_destroy_program_params_t *params) {
os << ".Program = ";
printPtr(os, *params->pProgram);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os, const struct ol_get_kernel_params_t *params) {
os << ".Program = ";
printPtr(os, *params->pProgram);
os << ", ";
os << ".KernelName = ";
printPtr(os, *params->pKernelName);
os << ", ";
os << ".Kernel = ";
printPtr(os, *params->pKernel);
return os;
}
inline llvm::raw_ostream &
operator<<(llvm::raw_ostream &os,
const struct ol_launch_kernel_params_t *params) {
os << ".Queue = ";
printPtr(os, *params->pQueue);
os << ", ";
os << ".Device = ";
printPtr(os, *params->pDevice);
os << ", ";
os << ".Kernel = ";
printPtr(os, *params->pKernel);
os << ", ";
os << ".ArgumentsData = ";
printPtr(os, *params->pArgumentsData);
os << ", ";
os << ".ArgumentsSize = ";
os << *params->pArgumentsSize;
os << ", ";
os << ".LaunchSizeArgs = ";
printPtr(os, *params->pLaunchSizeArgs);
os << ", ";
os << ".EventOut = ";
printPtr(os, *params->pEventOut);
return os;
}
///////////////////////////////////////////////////////////////////////////////
// @brief Print pointer value
template <typename T>
inline ol_result_t printPtr(llvm::raw_ostream &os, const T *ptr) {
if (ptr == nullptr) {
os << "nullptr";
} else if constexpr (std::is_pointer_v<T>) {
os << (const void *)(ptr) << " (";
printPtr(os, *ptr);
os << ")";
} else if constexpr (std::is_void_v<T> || is_handle_v<T *>) {
os << (const void *)ptr;
} else if constexpr (std::is_same_v<std::remove_cv_t<T>, char>) {
os << (const void *)(ptr) << " (";
os << ptr;
os << ")";
} else {
os << (const void *)(ptr) << " (";
os << *ptr;
os << ")";
}
return OL_SUCCESS;
}

View File

@@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//
#include "OffloadAPI.h"
#include "Shared/OffloadError.h"
#include "OffloadError.h"
#include "llvm/Support/Error.h"
#include <cstring>

View File

@@ -1,5 +1,6 @@
# Common interface to handle creating a plugin library.
set(common_dir ${CMAKE_CURRENT_SOURCE_DIR}/common)
set(common_bin_dir ${CMAKE_CURRENT_BINARY_DIR}/common)
add_subdirectory(common)
function(add_target_library target_name lib_name)
add_llvm_library(${target_name} STATIC
@@ -35,7 +36,8 @@ function(add_target_library target_name lib_name)
)
llvm_update_compile_flags(${target_name})
target_include_directories(${target_name} PUBLIC ${common_dir}/include)
target_include_directories(${target_name} PUBLIC ${common_dir}/include
${common_bin_dir}/include)
target_link_libraries(${target_name} PRIVATE
PluginCommon ${OPENMP_PTHREAD_LIB})

View File

@@ -1,3 +1,10 @@
# The error codes in this header are shared with liboffload, so need to be
# generated from the same source.
include(TableGen)
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/../../liboffload/API/OffloadAPI.td)
tablegen(OFFLOAD include/OffloadErrcodes.inc -gen-errcodes -I ${CMAKE_CURRENT_SOURCE_DIR}/../../liboffload/API)
add_public_tablegen_target(PluginErrcodes)
# NOTE: Don't try to build `PluginInterface` using `add_llvm_library` because we
# don't want to export `PluginInterface` while `add_llvm_library` requires that.
add_library(PluginCommon OBJECT
@@ -8,7 +15,7 @@ add_library(PluginCommon OBJECT
src/OffloadError.cpp
src/Utils/ELF.cpp
)
add_dependencies(PluginCommon intrinsics_gen)
add_dependencies(PluginCommon intrinsics_gen PluginErrcodes)
# Only enable JIT for those targets that LLVM can support.
set(supported_jit_targets AMDGPU NVPTX)
@@ -37,6 +44,7 @@ target_link_options(PluginCommon PUBLIC ${offload_link_flags})
target_include_directories(PluginCommon PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include
${LIBOMPTARGET_LLVM_INCLUDE_DIRS}
${LIBOMPTARGET_BINARY_INCLUDE_DIR}
${LIBOMPTARGET_INCLUDE_DIR}

View File

@@ -18,7 +18,7 @@ namespace error {
enum class ErrorCode {
#define OFFLOAD_ERRC(Name, _, Value) Name = Value,
#include "Shared/OffloadErrcodes.inc"
#include "OffloadErrcodes.inc"
#undef OFFLOAD_ERRC
};

View File

@@ -24,13 +24,13 @@
#include "Shared/Debug.h"
#include "Shared/Environment.h"
#include "Shared/EnvironmentVar.h"
#include "Shared/OffloadError.h"
#include "Shared/Requirements.h"
#include "Shared/Utils.h"
#include "GlobalHandler.h"
#include "JIT.h"
#include "MemoryManager.h"
#include "OffloadError.h"
#include "RPC.h"
#include "omptarget.h"

View File

@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
#include "Shared/OffloadError.h"
#include "OffloadError.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
@@ -24,7 +24,7 @@ public:
#define OFFLOAD_ERRC(Name, Desc, Value) \
case ErrorCode::Name: \
return #Desc;
#include "Shared/OffloadErrcodes.inc"
#include "OffloadErrcodes.inc"
#undef OFFLOAD_ERRC
}
llvm_unreachable("Unrecognized offload ErrorCode");