Skip to content

Commit a8cf8e8

Browse files
committed
Move constructors implementation to cpp to avoid including two version of headers
1 parent d72b38a commit a8cf8e8

File tree

3 files changed

+67
-57
lines changed

3 files changed

+67
-57
lines changed

source/adapters/level_zero/program.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,67 @@ ur_result_t urProgramSetSpecializationConstants(
970970

971971
} // namespace ur::level_zero
972972

973+
ur_program_handle_t_::ur_program_handle_t_(state St,
974+
ur_context_handle_t Context,
975+
const void *Input, size_t Length)
976+
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{true},
977+
AssociatedDevices(Context->getDevices()), SpirvCode{new uint8_t[Length]},
978+
SpirvCodeLength{Length} {
979+
std::memcpy(SpirvCode.get(), Input, Length);
980+
// All devices have the program in IL state.
981+
for (auto &Device : Context->getDevices()) {
982+
DeviceData &PerDevData = DeviceDataMap[Device->ZeDevice];
983+
PerDevData.State = St;
984+
}
985+
}
986+
987+
ur_program_handle_t_::ur_program_handle_t_(
988+
state St, ur_context_handle_t Context, const uint32_t NumDevices,
989+
const ur_device_handle_t *Devices,
990+
const ur_program_properties_t *Properties, const uint8_t **Inputs,
991+
const size_t *Lengths)
992+
: Context{Context}, NativeProperties(Properties), OwnZeModule{true},
993+
AssociatedDevices(Devices, Devices + NumDevices) {
994+
for (uint32_t I = 0; I < NumDevices; ++I) {
995+
DeviceData &PerDevData = DeviceDataMap[Devices[I]->ZeDevice];
996+
PerDevData.State = St;
997+
PerDevData.Binary = std::make_pair(
998+
std::unique_ptr<uint8_t[]>(new uint8_t[Lengths[I]]), Lengths[I]);
999+
std::memcpy(PerDevData.Binary.first.get(), Inputs[I], Lengths[I]);
1000+
}
1001+
}
1002+
1003+
ur_program_handle_t_::ur_program_handle_t_(ur_context_handle_t Context)
1004+
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{true},
1005+
AssociatedDevices(Context->getDevices()) {}
1006+
1007+
ur_program_handle_t_::ur_program_handle_t_(state, ur_context_handle_t Context,
1008+
ze_module_handle_t InteropZeModule)
1009+
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{true},
1010+
AssociatedDevices({Context->getDevices()[0]}),
1011+
InteropZeModule{InteropZeModule} {}
1012+
1013+
ur_program_handle_t_::ur_program_handle_t_(state, ur_context_handle_t Context,
1014+
ze_module_handle_t InteropZeModule,
1015+
bool OwnZeModule)
1016+
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{OwnZeModule},
1017+
AssociatedDevices({Context->getDevices()[0]}),
1018+
InteropZeModule{InteropZeModule} {
1019+
// TODO: Currently it is not possible to understand the device associated
1020+
// with provided ZeModule. So we can't set the state on that device to Exe.
1021+
}
1022+
1023+
ur_program_handle_t_::ur_program_handle_t_(state St,
1024+
ur_context_handle_t Context,
1025+
const std::string &ErrorMessage)
1026+
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{true},
1027+
ErrorMessage{ErrorMessage}, AssociatedDevices(Context->getDevices()) {
1028+
for (auto &Device : Context->getDevices()) {
1029+
DeviceData &PerDevData = DeviceDataMap[Device->ZeDevice];
1030+
PerDevData.State = St;
1031+
}
1032+
}
1033+
9731034
ur_program_handle_t_::~ur_program_handle_t_() {
9741035
if (!resourcesReleased) {
9751036
ur_release_program_resources(true);

source/adapters/level_zero/program.hpp

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111

1212
#include "common.hpp"
1313
#include "device.hpp"
14-
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
15-
#include "v2/context.hpp"
16-
#else
17-
#include "context.hpp"
18-
#endif
1914

2015
struct ur_program_handle_t_ : _ur_object {
2116
// ur_program_handle_t_() {}
@@ -73,70 +68,32 @@ struct ur_program_handle_t_ : _ur_object {
7368

7469
// Construct a program in IL.
7570
ur_program_handle_t_(state St, ur_context_handle_t Context, const void *Input,
76-
size_t Length)
77-
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{true},
78-
AssociatedDevices(Context->getDevices()),
79-
SpirvCode{new uint8_t[Length]}, SpirvCodeLength{Length} {
80-
std::memcpy(SpirvCode.get(), Input, Length);
81-
// All devices have the program in IL state.
82-
for (auto &Device : Context->getDevices()) {
83-
DeviceData &PerDevData = DeviceDataMap[Device->ZeDevice];
84-
PerDevData.State = St;
85-
}
86-
}
71+
size_t Length);
8772

8873
// Construct a program in NATIVE for multiple devices.
8974
ur_program_handle_t_(state St, ur_context_handle_t Context,
9075
const uint32_t NumDevices,
9176
const ur_device_handle_t *Devices,
9277
const ur_program_properties_t *Properties,
93-
const uint8_t **Inputs, const size_t *Lengths)
94-
: Context{Context}, NativeProperties(Properties), OwnZeModule{true},
95-
AssociatedDevices(Devices, Devices + NumDevices) {
96-
for (uint32_t I = 0; I < NumDevices; ++I) {
97-
DeviceData &PerDevData = DeviceDataMap[Devices[I]->ZeDevice];
98-
PerDevData.State = St;
99-
PerDevData.Binary = std::make_pair(
100-
std::unique_ptr<uint8_t[]>(new uint8_t[Lengths[I]]), Lengths[I]);
101-
std::memcpy(PerDevData.Binary.first.get(), Inputs[I], Lengths[I]);
102-
}
103-
}
78+
const uint8_t **Inputs, const size_t *Lengths);
10479

105-
ur_program_handle_t_(ur_context_handle_t Context)
106-
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{true},
107-
AssociatedDevices(Context->getDevices()) {}
80+
ur_program_handle_t_(ur_context_handle_t Context);
10881

10982
// Construct a program in Exe or Invalid state.
11083
ur_program_handle_t_(state, ur_context_handle_t Context,
111-
ze_module_handle_t InteropZeModule)
112-
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{true},
113-
AssociatedDevices({Context->getDevices()[0]}), InteropZeModule{
114-
InteropZeModule} {}
84+
ze_module_handle_t InteropZeModule);
11585

11686
// Construct a program in Exe state (interop).
11787
// TODO: Currently it is not possible to get the device associated with the
11888
// interop module, API must be changed to either get that info from the user
11989
// or new API need to be added to L0 to fetch that info. Consider it
12090
// associated with the first device in the context.
12191
ur_program_handle_t_(state, ur_context_handle_t Context,
122-
ze_module_handle_t InteropZeModule, bool OwnZeModule)
123-
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{OwnZeModule},
124-
AssociatedDevices({Context->getDevices()[0]}), InteropZeModule{
125-
InteropZeModule} {
126-
// TODO: Currently it is not possible to understand the device associated
127-
// with provided ZeModule. So we can't set the state on that device to Exe.
128-
}
92+
ze_module_handle_t InteropZeModule, bool OwnZeModule);
12993

13094
// Construct a program in Invalid state with a custom error message.
13195
ur_program_handle_t_(state St, ur_context_handle_t Context,
132-
const std::string &ErrorMessage)
133-
: Context{Context}, NativeProperties{nullptr}, OwnZeModule{true},
134-
ErrorMessage{ErrorMessage}, AssociatedDevices(Context->getDevices()) {
135-
for (auto &Device : Context->getDevices()) {
136-
DeviceData &PerDevData = DeviceDataMap[Device->ZeDevice];
137-
PerDevData.State = St;
138-
}
139-
}
96+
const std::string &ErrorMessage);
14097

14198
~ur_program_handle_t_();
14299
void ur_release_program_resources(bool deletion);

source/adapters/level_zero/ur_level_zero.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,9 @@
2525
#include <zes_api.h>
2626

2727
#include "common.hpp"
28-
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
29-
#include "v2/context.hpp"
30-
#else
3128
#include "context.hpp"
32-
#endif
3329
#include "device.hpp"
34-
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
35-
#include "v2/event.hpp"
36-
#else
3730
#include "event.hpp"
38-
#endif
3931
#include "image.hpp"
4032
#include "kernel.hpp"
4133
#include "memory.hpp"

0 commit comments

Comments
 (0)