Skip to content

Commit 0a2fa15

Browse files
committed
Fix liboffload_new linking and formatting
1 parent 60f8bfc commit 0a2fa15

File tree

8 files changed

+47
-24
lines changed

8 files changed

+47
-24
lines changed

offload/new-api/CMakeLists.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
set(LLVM_TARGET_DEFINITIONS ${CMAKE_CURRENT_SOURCE_DIR}/API/OffloadAPI.td)
32
list(APPEND LLVM_TABLEGEN_FLAGS -I ${CMAKE_CURRENT_SOURCE_DIR}/API)
43

@@ -7,25 +6,31 @@ tablegen(OFFLOAD offload_funcs.inc -gen-func-names)
76
tablegen(OFFLOAD offload_impl_func_decls.inc -gen-impl-func-decls)
87
tablegen(OFFLOAD offload_entry_points.inc -gen-entry-points)
98
tablegen(OFFLOAD offload_print.hpp -gen-print-header)
10-
9+
tablegen(OFFLOAD offload_exports -gen-exports)
1110

1211
add_public_tablegen_target(OffloadHeaderGen)
1312

1413
add_llvm_library(offload_new SHARED
1514
src/offload_lib.cpp
1615
src/offload_impl.cpp
17-
DEPENDS OffloadHeaderGen
18-
LINK_LIBS omptarget omptarget.rtl.cuda omptarget.rtl.amdgpu)
16+
DEPENDS OffloadHeaderGen)
17+
18+
foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
19+
target_link_libraries(offload_new PRIVATE omptarget.rtl.${plugin})
20+
endforeach()
21+
22+
if(LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
23+
target_link_libraries(offload_new PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/offload_exports")
24+
endif()
1925

2026
target_include_directories(offload_new PUBLIC
2127
${CMAKE_CURRENT_BINARY_DIR}
2228
${CMAKE_CURRENT_BINARY_DIR}/../include
2329
${CMAKE_CURRENT_SOURCE_DIR}/../include
2430
${CMAKE_CURRENT_SOURCE_DIR}/../plugins-nextgen/common/include)
2531

26-
# foreach(plugin IN LISTS LIBOMPTARGET_PLUGINS_TO_BUILD)
27-
# target_link_libraries(offload_new PRIVATE omptarget.rtl.${plugin})
28-
# endforeach()
32+
target_compile_options(offload_new PRIVATE ${offload_compile_flags})
33+
target_link_options(offload_new PRIVATE ${offload_link_flags})
2934

3035
set_target_properties(offload_new PROPERTIES
3136
POSITION_INDEPENDENT_CODE ON

offload/new-api/src/helpers.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include <cstring>
1818

19-
2019
template <typename T, typename Assign>
2120
offload_result_t getInfoImpl(size_t ParamValueSize, void *ParamValue,
2221
size_t *ParamValueSizeRet, T Value,

offload/new-api/src/offload_impl.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ struct offload_platform_handle_t_ {
3232
std::vector<offload_device_handle_t_> Devices;
3333
};
3434

35-
static std::vector<offload_platform_handle_t_> Platforms;
35+
std::vector<offload_platform_handle_t_> &Platforms() {
36+
static std::vector<offload_platform_handle_t_> Platforms;
37+
return Platforms;
38+
}
3639

3740
// Every plugin exports this method to create an instance of the plugin type.
3841
#define PLUGIN_TARGET(Name) extern "C" GenericPluginTy *createPlugin_##Name();
@@ -42,14 +45,14 @@ void initPlugins() {
4245
// Attempt to create an instance of each supported plugin.
4346
#define PLUGIN_TARGET(Name) \
4447
do { \
45-
Platforms.emplace_back(offload_platform_handle_t_{ \
48+
Platforms().emplace_back(offload_platform_handle_t_{ \
4649
std::unique_ptr<GenericPluginTy>(createPlugin_##Name()), {}}); \
4750
} while (false);
4851
#include "Shared/Targets.def"
4952

5053
// Preemptively initialize all devices in the plugin so we can just return
5154
// them from deviceGet
52-
for (auto &Platform : Platforms) {
55+
for (auto &Platform : Platforms()) {
5356
auto Err = Platform.Plugin->init();
5457
[[maybe_unused]] std::string InfoMsg = toString(std::move(Err));
5558
for (auto DevNum = 0; DevNum < Platform.Plugin->number_of_devices();
@@ -71,19 +74,19 @@ offload_result_t offloadPlatformGet_impl(uint32_t NumEntries,
7174
static std::once_flag InitFlag;
7275
std::call_once(InitFlag, initPlugins);
7376

74-
if (NumEntries > Platforms.size()) {
77+
if (NumEntries > Platforms().size()) {
7578
return OFFLOAD_RESULT_ERROR_INVALID_SIZE;
7679
}
7780

7881
if (phPlatforms) {
7982
for (uint32_t PlatformIndex = 0; PlatformIndex < NumEntries;
8083
PlatformIndex++) {
81-
phPlatforms[PlatformIndex] = &Platforms[PlatformIndex];
84+
phPlatforms[PlatformIndex] = &(Platforms())[PlatformIndex];
8285
}
8386
}
8487

8588
if (pNumPlatforms) {
86-
*pNumPlatforms = Platforms.size();
89+
*pNumPlatforms = Platforms().size();
8790
}
8891

8992
return OFFLOAD_RESULT_SUCCESS;

offload/plugins-nextgen/common/include/PluginInterface.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class InfoQueueTy {
132132
uint64_t Level;
133133
};
134134

135-
136135
private:
137136
std::deque<InfoQueueEntryTy> Queue;
138137

@@ -156,9 +155,7 @@ class InfoQueueTy {
156155
Queue.push_back({Key, Value, Units, L});
157156
}
158157

159-
const std::deque<InfoQueueEntryTy> &getQueue() const {
160-
return Queue;
161-
}
158+
const std::deque<InfoQueueEntryTy> &getQueue() const { return Queue; }
162159

163160
/// Print all info entries added to the queue.
164161
void print() const {

offload/tools/offload-tblgen/FuncsGen.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===- offload-tblgen/APIGen.cpp - Tablegen backend for Offload validation ===//
1+
//===- offload-tblgen/APIGen.cpp - Tablegen backend for Offload functions -===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88
//
9-
// This is a Tablegen backend that produces validation functions for the Offload
10-
// API entry point functions.
9+
// This is a Tablegen backend that handles generation of various small files
10+
// pertaining to the API functions.
1111
//
1212
//===----------------------------------------------------------------------===//
1313

@@ -36,6 +36,19 @@ void EmitOffloadFuncNames(RecordKeeper &Records, raw_ostream &OS) {
3636
OS << "\n#undef OFFLOAD_FUNC\n";
3737
}
3838

39+
void EmitOffloadExports(RecordKeeper &Records, raw_ostream &OS) {
40+
OS << "VERS1.0 {\n";
41+
OS << TAB_1 "global:\n";
42+
43+
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
44+
OS << formatv(TAB_2 "{0};\n", FunctionRec(R).getName());
45+
}
46+
OS << TAB_1 "local:\n";
47+
OS << TAB_2 "*;\n";
48+
OS << "};\n";
49+
}
50+
51+
// Emit declarations for every implementation function
3952
void EmitOffloadImplFuncDecls(RecordKeeper &Records, raw_ostream &OS) {
4053
for (auto *R : Records.getAllDerivedDefinitions("Function")) {
4154
FunctionRec F{R};

offload/tools/offload-tblgen/GenCommon.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ MakeParamComment(const llvm::offload::tblgen::ParamRec &Param) {
5555
(Param.isOut() ? "[out]" : ""),
5656
(Param.isOpt() ? "[optional]" : ""), Param.getDesc());
5757
}
58-

offload/tools/offload-tblgen/Generators.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ void EmitOffloadImplFuncDecls(llvm::RecordKeeper &Records,
1616
llvm::raw_ostream &OS);
1717
void EmitOffloadEntryPoints(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
1818
void EmitOffloadPrintHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
19+
void EmitOffloadExports(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);

offload/tools/offload-tblgen/offload-tblgen.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ enum ActionType {
2929
GenFuncNames,
3030
GenImplFuncDecls,
3131
GenEntryPoints,
32-
GenPrintHeader
32+
GenPrintHeader,
33+
GenExports
3334
};
3435

3536
namespace {
@@ -49,7 +50,9 @@ cl::opt<ActionType> Action(
4950
clEnumValN(GenEntryPoints, "gen-entry-points",
5051
"Generate Offload API wrapper function definitions"),
5152
clEnumValN(GenPrintHeader, "gen-print-header",
52-
"Generate Offload API print header")));
53+
"Generate Offload API print header"),
54+
clEnumValN(GenExports, "gen-exports",
55+
"Generate export file for the Offload library")));
5356
}
5457

5558
static bool OffloadTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
@@ -75,6 +78,9 @@ static bool OffloadTableGenMain(raw_ostream &OS, RecordKeeper &Records) {
7578
case GenPrintHeader:
7679
EmitOffloadPrintHeader(Records, OS);
7780
break;
81+
case GenExports:
82+
EmitOffloadExports(Records, OS);
83+
break;
7884
}
7985

8086
return false;

0 commit comments

Comments
 (0)