Skip to content

Commit 77ce0bf

Browse files
gcarranza-1copybara-github
authored andcommitted
Move GPU-related enums into litert::GpuOptions.
LiteRT-PiperOrigin-RevId: 826639123
1 parent beb6f8a commit 77ce0bf

File tree

4 files changed

+61
-38
lines changed

4 files changed

+61
-38
lines changed

litert/cc/litert_common.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,6 @@ inline HwAcceleratorSet operator|(HwAcceleratorSet lhs, HwAccelerators rhs) {
4545
return HwAcceleratorSet(lhs.value | static_cast<int>(rhs));
4646
}
4747

48-
enum class DelegateBufferStorageType : int {
49-
kDefault = kLiteRtDelegateBufferStorageTypeDefault,
50-
kBuffer = kLiteRtDelegateBufferStorageTypeBuffer,
51-
kTexture2D = kLiteRtDelegateBufferStorageTypeTexture2D,
52-
};
53-
54-
enum class GpuBackend : int {
55-
kAutomatic = kLiteRtGpuBackendAutomatic,
56-
kOpenCl = kLiteRtGpuBackendOpenCl,
57-
kWebGpu = kLiteRtGpuBackendWebGpu,
58-
kOpenGl = kLiteRtGpuBackendOpenGl,
59-
};
60-
61-
enum class GpuPriority : int {
62-
kDefault = kLiteRtGpuPriorityDefault,
63-
kLow = kLiteRtGpuPriorityLow,
64-
kNormal = kLiteRtGpuPriorityNormal,
65-
kHigh = kLiteRtGpuPriorityHigh,
66-
};
67-
68-
enum class DelegatePrecision : int {
69-
kDefault = kLiteRtDelegatePrecisionDefault,
70-
kFp16 = kLiteRtDelegatePrecisionFp16,
71-
kFp32 = kLiteRtDelegatePrecisionFp32,
72-
};
73-
7448
} // namespace litert
7549

7650
#endif // THIRD_PARTY_ODML_LITERT_LITERT_CC_LITERT_COMMON_H_

litert/cc/options/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ cc_library(
120120
"//litert/c:litert_common",
121121
"//litert/c:litert_opaque_options",
122122
"//litert/c/options:litert_gpu_options",
123-
"//litert/cc:litert_common",
124123
"//litert/cc:litert_expected",
125124
"//litert/cc:litert_macros",
126125
"//litert/cc:litert_opaque_options",

litert/cc/options/litert_gpu_options.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "litert/cc/options/litert_gpu_options.h"
1616

1717
#include "litert/c/litert_common.h"
18-
#include "litert/c/litert_opaque_options.h"
1918
#include "litert/c/options/litert_gpu_options.h"
2019
#include "litert/cc/internal/litert_handle.h"
2120
#include "litert/cc/litert_expected.h"
@@ -45,6 +44,12 @@ LiteRtStatus GpuOptions::EnableBenchmarkMode(bool enabled) {
4544
return LiteRtSetGpuOptionsBenchmarkMode(Get(), enabled);
4645
}
4746

47+
Expected<void> GpuOptions::SetBackend(Backend backend) {
48+
LITERT_RETURN_IF_ERROR(LiteRtSetGpuOptionsGpuBackend(
49+
Get(), static_cast<LiteRtGpuBackend>(backend)));
50+
return {};
51+
}
52+
4853
LiteRtStatus GpuOptions::SetGpuBackend(LiteRtGpuBackend backend) {
4954
return LiteRtSetGpuOptionsGpuBackend(Get(), backend);
5055
}
@@ -54,11 +59,24 @@ LiteRtStatus GpuOptions::EnableAllowSrcQuantizedFcConvOps(bool enabled) {
5459
Get(), enabled);
5560
}
5661

62+
Expected<void> GpuOptions::SetPrecision(Precision precision) {
63+
LITERT_RETURN_IF_ERROR(LiteRtSetGpuAcceleratorCompilationOptionsPrecision(
64+
Get(), static_cast<LiteRtDelegatePrecision>(precision)));
65+
return {};
66+
}
67+
5768
LiteRtStatus GpuOptions::SetDelegatePrecision(
5869
LiteRtDelegatePrecision precision) {
5970
return LiteRtSetGpuAcceleratorCompilationOptionsPrecision(Get(), precision);
6071
}
6172

73+
Expected<void> GpuOptions::SetBufferStorageType(BufferStorageType type) {
74+
LITERT_RETURN_IF_ERROR(
75+
LiteRtSetGpuAcceleratorCompilationOptionsUseBufferStorageType(
76+
Get(), static_cast<LiteRtDelegateBufferStorageType>(type)));
77+
return {};
78+
}
79+
6280
LiteRtStatus GpuOptions::SetBufferStorageType(
6381
LiteRtDelegateBufferStorageType type) {
6482
return LiteRtSetGpuAcceleratorCompilationOptionsUseBufferStorageType(Get(),
@@ -100,6 +118,12 @@ LiteRtStatus GpuOptions::AddExternalTensorPattern(const char* pattern) {
100118
return LiteRtAddGpuOptionsExternalTensorPattern(Get(), pattern);
101119
}
102120

121+
Expected<void> GpuOptions::SetPriority(Priority priority) {
122+
LITERT_RETURN_IF_ERROR(LiteRtSetGpuOptionsGpuPriority(
123+
Get(), static_cast<LiteRtGpuPriority>(priority)));
124+
return {};
125+
}
126+
103127
LiteRtStatus GpuOptions::SetGpuPriority(LiteRtGpuPriority priority) {
104128
return LiteRtSetGpuOptionsGpuPriority(Get(), priority);
105129
}

litert/cc/options/litert_gpu_options.h

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#define THIRD_PARTY_ODML_LITERT_LITERT_CC_OPTIONS_LITERT_GPU_OPTIONS_H_
1717

1818
#include "litert/c/litert_common.h"
19-
#include "litert/cc/litert_common.h"
2019
#include "litert/cc/litert_expected.h"
2120
#include "litert/cc/litert_opaque_options.h"
2221

@@ -36,26 +35,53 @@ class GpuOptions : public litert::OpaqueOptions {
3635
LiteRtStatus EnableInfiniteFloatCapping(bool enabled);
3736
LiteRtStatus EnableBenchmarkMode(bool enabled);
3837
LiteRtStatus EnableAllowSrcQuantizedFcConvOps(bool enabled);
39-
LiteRtStatus SetDelegatePrecision(DelegatePrecision precision);
40-
[[deprecated("Use SetDelegatePrecision above instead.")]]
38+
39+
enum class Precision : int {
40+
kDefault = kLiteRtDelegatePrecisionDefault,
41+
kFp16 = kLiteRtDelegatePrecisionFp16,
42+
kFp32 = kLiteRtDelegatePrecisionFp32,
43+
};
44+
Expected<void> SetPrecision(Precision precision);
45+
[[deprecated("Use SetPrecision above instead.")]]
4146
LiteRtStatus SetDelegatePrecision(LiteRtDelegatePrecision precision);
42-
LiteRtStatus SetDelegateBufferStorageType(
43-
DelegateBufferStorageType type);
44-
[[deprecated("Use SetDelegateBufferStorageType above instead.")]]
47+
48+
enum class BufferStorageType : int {
49+
kDefault = kLiteRtDelegateBufferStorageTypeDefault,
50+
kBuffer = kLiteRtDelegateBufferStorageTypeBuffer,
51+
kTexture2D = kLiteRtDelegateBufferStorageTypeTexture2D,
52+
};
53+
Expected<void> SetBufferStorageType(BufferStorageType type);
54+
[[deprecated("Use SetBufferStorageType above instead.")]]
4555
LiteRtStatus SetBufferStorageType(LiteRtDelegateBufferStorageType type);
56+
4657
LiteRtStatus SetPreferTextureWeights(bool prefer_texture_weights);
4758
LiteRtStatus SetSerializationDir(const char* serialization_dir);
4859
LiteRtStatus SetModelCacheKey(const char* model_cache_key);
4960
LiteRtStatus SetSerializeProgramCache(bool serialize_program_cache);
5061
LiteRtStatus SetSerializeExternalTensors(bool serialize_external_tensors);
5162
LiteRtStatus EnableExternalTensorsMode(bool enabled);
5263
LiteRtStatus AddExternalTensorPattern(const char* pattern);
53-
LiteRtStatus SetGpuBackend(GpuBackend backend);
54-
[[deprecated("Use SetGpuBackend above instead.")]]
64+
65+
enum class Backend : int {
66+
kAutomatic = kLiteRtGpuBackendAutomatic,
67+
kOpenCl = kLiteRtGpuBackendOpenCl,
68+
kWebGpu = kLiteRtGpuBackendWebGpu,
69+
kOpenGl = kLiteRtGpuBackendOpenGl,
70+
};
71+
Expected<void> SetBackend(Backend backend);
72+
[[deprecated("Use SetBackend above instead.")]]
5573
LiteRtStatus SetGpuBackend(LiteRtGpuBackend backend);
56-
LiteRtStatus SetGpuPriority(GpuPriority priority);
57-
[[deprecated("Use SetGpuPriority above instead.")]]
74+
75+
enum class Priority : int {
76+
kDefault = kLiteRtGpuPriorityDefault,
77+
kLow = kLiteRtGpuPriorityLow,
78+
kNormal = kLiteRtGpuPriorityNormal,
79+
kHigh = kLiteRtGpuPriorityHigh,
80+
};
81+
Expected<void> SetPriority(Priority priority);
82+
[[deprecated("Use SetPriority above instead.")]]
5883
LiteRtStatus SetGpuPriority(LiteRtGpuPriority priority);
84+
5985
LiteRtStatus SetMadviseOriginalSharedTensors(
6086
bool madvise_original_shared_tensors);
6187
};

0 commit comments

Comments
 (0)