Skip to content

Commit c19b4dc

Browse files
LukeBoyercopybara-github
authored andcommitted
Switch ats to use micro seconds for latency instead of nano
LiteRT-PiperOrigin-RevId: 826195550
1 parent 30faa6d commit c19b4dc

File tree

14 files changed

+191
-88
lines changed

14 files changed

+191
-88
lines changed

litert/ats/BUILD

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,25 @@ cc_library(
6262
testonly = True,
6363
srcs = ["configure.cc"],
6464
hdrs = ["configure.h"],
65-
copts = commandline_flag_copts(),
65+
copts = commandline_flag_copts() + [
66+
"-DINCLUDE_QUALCOMM_COMPILE_FLAGS",
67+
"-DINCLUDE_QUALCOMM_RUNTIME_FLAGS",
68+
"-DINCLUDE_MEDIATEK_COMPILE_FLAGS",
69+
"-DINCLUDE_MEDIATEK_RUNTIME_FLAGS",
70+
],
6671
deps = [
6772
":common",
6873
"//litert/c:litert_common",
6974
"//litert/c/internal:litert_logging",
7075
"//litert/cc:litert_expected",
7176
"//litert/cc:litert_macros",
77+
"//litert/cc:litert_options",
7278
"//litert/cc/internal:litert_rng",
7379
"//litert/compiler/plugin:compiler_plugin",
7480
"//litert/core:filesystem_testonly",
7581
"//litert/core/model:model_serialize",
82+
"//litert/tools/flags/vendors:mediatek_flags",
83+
"//litert/tools/flags/vendors:qualcomm_flags",
7684
"@com_google_absl//absl/container:flat_hash_map",
7785
"@com_google_absl//absl/flags:flag",
7886
"@com_google_absl//absl/strings",
@@ -111,6 +119,7 @@ cc_library(
111119
"//litert/cc:litert_expected",
112120
"//litert/cc/internal:litert_detail",
113121
"//litert/cc/internal:litert_rng",
122+
"//litert/core:filesystem",
114123
"//litert/test/generators",
115124
],
116125
)
@@ -120,8 +129,10 @@ cc_test(
120129
srcs = ["executor_test.cc"],
121130
deps = [
122131
":executor",
132+
"//litert/c:litert_common",
123133
"//litert/c:litert_op_code",
124134
"//litert/cc:litert_buffer_ref",
135+
"//litert/cc:litert_options",
125136
"//litert/core/model",
126137
"//litert/test:matchers",
127138
"//litert/test:simple_buffer",
@@ -186,8 +197,10 @@ litert_device_test(
186197
defines = ["_TEST_NPU"],
187198
deps = [
188199
":executor",
200+
"//litert/c:litert_common",
189201
"//litert/c:litert_op_code",
190202
"//litert/cc:litert_buffer_ref",
203+
"//litert/cc:litert_options",
191204
"//litert/core/model",
192205
"//litert/test:matchers",
193206
"//litert/test:simple_buffer",
@@ -367,7 +380,6 @@ litert_define_ats(
367380
# "^(?:(?!npu_ats_87).)*$$",
368381
],
369382
extra_flags = [
370-
"--f16_range_for_f32=true",
371383
"--data_seed=42",
372384
],
373385
jit_suffix = "",

litert/ats/check_ats.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ Expected<void> CheckAts() {
179179

180180
LITERT_ASSIGN_OR_RETURN(auto exec,
181181
NpuCompiledModelExecutor::Create(
182-
*model, npu_inference_options.DispatchDir()));
182+
*model, npu_inference_options.TargetOptions(),
183+
npu_inference_options.DispatchDir()));
183184
const auto& subgraph = *model->Subgraphs()[0];
184185
LITERT_ASSIGN_OR_RETURN(
185186
auto inputs, SimpleBuffer::LikeSignature(subgraph.Inputs().begin(),

litert/ats/common.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ struct TestNames {
4848
}
4949

5050
// Create with an explicit desc.
51-
static TestNames Create(size_t test_id, absl::string_view family,
52-
absl::string_view logic, absl::string_view test,
51+
static TestNames Create(size_t test_id, absl::string_view fixture,
52+
absl::string_view source, absl::string_view test,
53+
absl::string_view report_id,
5354
absl::string_view desc = "") {
54-
auto suite = MakeSuite(test_id, family, logic);
55-
return {suite, std::string(logic), std::string(desc), std::string(test)};
55+
auto suite = MakeSuite(test_id, fixture, source);
56+
return {suite, std::string(test), std::string(desc),
57+
std::string(report_id)};
5658
}
5759

5860
private:
@@ -98,7 +100,7 @@ enum class CompilationStatus {
98100
// Timing related types.
99101
using Clock = std::chrono::steady_clock;
100102
using TimePoint = Clock::time_point;
101-
using Nanoseconds = uint64_t;
103+
using Microseconds = uint64_t;
102104

103105
// Which backend to use as the "actual".
104106
enum class ExecutionBackend { kCpu, kGpu, kNpu };
@@ -175,7 +177,7 @@ void AbslStringify(Sink& sink, const CompilationStatus& status) {
175177
}
176178

177179
template <typename Sink>
178-
void AbslStringify(Sink& sink, const Nanoseconds& ns) {
180+
void AbslStringify(Sink& sink, const Microseconds& ns) {
179181
absl::Format(&sink, "%e", ns);
180182
}
181183

litert/ats/compile_capture.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@
2929
namespace litert::testing {
3030

3131
// Information about the time taken to compile the model.
32-
class CompilationTime : public Printable<Nanoseconds> {
32+
class CompilationTime : public Printable<Microseconds> {
3333
public:
3434
// Start timing.
3535
TimePoint Start() const { return Clock::now(); }
3636

3737
// Stop timing and record the latency.
3838
void Stop(const TimePoint& start) {
39-
std::chrono::duration<Nanoseconds, std::nano> nano = Clock::now() - start;
39+
std::chrono::duration<Microseconds, std::nano> nano = Clock::now() - start;
4040
nanos_ = nano.count();
4141
}
4242

43-
Nanoseconds Nanos() const { return nanos_; }
43+
Microseconds Nanos() const { return nanos_; }
4444

4545
CompilationTime() : Printable("CompilationTime", "compile_time(ns)") {}
4646

4747
private:
4848
Fields GetFields() const override { return Fields{nanos_}; }
4949

50-
Nanoseconds nanos_ = std::numeric_limits<Nanoseconds>::max();
50+
Microseconds nanos_ = std::numeric_limits<Microseconds>::max();
5151
};
5252

5353
// Type to hold all of the capturable information related compilation test

litert/ats/compile_capture_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ TEST(AtsCompileCaptureTest, Basic) {
3333
e.model.name = "FOO";
3434

3535
ASSERT_NE(e.compilation_time.Nanos(),
36-
std::numeric_limits<Nanoseconds>::max());
36+
std::numeric_limits<Microseconds>::max());
3737

3838
std::ostringstream s;
3939
cap.Print(s);

litert/ats/configure.cc

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
#include "litert/c/litert_common.h"
3434
#include "litert/cc/litert_expected.h"
3535
#include "litert/cc/litert_macros.h"
36+
#include "litert/cc/litert_options.h"
3637
#include "litert/compiler/plugin/compiler_plugin.h"
38+
#include "litert/tools/flags/vendors/mediatek_flags.h" // IWYU pragma: export
39+
#include "litert/tools/flags/vendors/qualcomm_flags.h" // IWYU pragma: export
3740

3841
ABSL_FLAG(std::optional<int>, data_seed, std::nullopt,
3942
"Seed for the buffer data generation.");
@@ -113,6 +116,9 @@ namespace litert::testing {
113116

114117
namespace {
115118

119+
using ::litert::mediatek::MediatekOptionsFromFlags;
120+
using ::litert::qualcomm::QualcommOptionsFromFlags;
121+
116122
Expected<AtsConf::SeedMap> ParseParamSeedMap() {
117123
const auto seed_flags = absl::GetFlag(FLAGS_seeds);
118124
AtsConf::SeedMap seeds;
@@ -143,15 +149,34 @@ Expected<ExecutionBackend> ParseBackend() {
143149
}
144150
}
145151

152+
Expected<Options> ParseOptions(ExecutionBackend backend) {
153+
LITERT_ASSIGN_OR_RETURN(auto options, Options::Create());
154+
if (backend == ExecutionBackend::kNpu) {
155+
if (auto qnn_opts = QualcommOptionsFromFlags()) {
156+
options.AddOpaqueOptions(std::move(*qnn_opts));
157+
}
158+
if (auto mediatek_opts = MediatekOptionsFromFlags()) {
159+
options.AddOpaqueOptions(std::move(*mediatek_opts));
160+
}
161+
options.SetHardwareAccelerators(kLiteRtHwAcceleratorNpu);
162+
} else if (backend == ExecutionBackend::kCpu) {
163+
options.SetHardwareAccelerators(kLiteRtHwAcceleratorCpu);
164+
} else if (backend == ExecutionBackend::kGpu) {
165+
options.SetHardwareAccelerators(kLiteRtHwAcceleratorGpu);
166+
}
167+
return options;
168+
}
169+
146170
Expected<std::optional<internal::CompilerPlugin>> ParsePlugin(
147171
absl::string_view plugin_dir, absl::string_view soc_manufacturer,
148-
bool compile_mode) {
172+
bool compile_mode, const Options& litert_options) {
149173
using R = std::optional<internal::CompilerPlugin>;
150174
if (!compile_mode) {
151175
return R(std::nullopt);
152176
}
153177
LITERT_ASSIGN_OR_RETURN(auto plugin, internal::CompilerPlugin::FindPlugin(
154-
soc_manufacturer, {plugin_dir}));
178+
soc_manufacturer, {plugin_dir},
179+
nullptr, litert_options.Get()));
155180
return R(std::move(plugin));
156181
}
157182

@@ -171,7 +196,6 @@ Expected<AtsConf> AtsConf::ParseFlagsAndDoSetup() {
171196
std::regex pos_re(absl::GetFlag(FLAGS_do_register),
172197
std::regex_constants::ECMAScript);
173198
auto extra_models = absl::GetFlag(FLAGS_extra_models);
174-
auto f16_range_for_f32 = absl::GetFlag(FLAGS_f16_range_for_f32);
175199
auto data_seed = absl::GetFlag(FLAGS_data_seed);
176200
auto dispatch_dir = absl::GetFlag(FLAGS_dispatch_dir);
177201
auto plugin_dir = absl::GetFlag(FLAGS_plugin_dir);
@@ -190,15 +214,19 @@ Expected<AtsConf> AtsConf::ParseFlagsAndDoSetup() {
190214
auto limit = absl::GetFlag(FLAGS_limit);
191215
auto soc_manufacturer = absl::GetFlag(FLAGS_soc_manufacturer);
192216
auto soc_model = absl::GetFlag(FLAGS_soc_model);
217+
LITERT_ASSIGN_OR_RETURN(auto target_options, ParseOptions(backend));
218+
LITERT_ASSIGN_OR_RETURN(auto reference_options, Options::Create());
219+
reference_options.SetHardwareAccelerators(kLiteRtHwAcceleratorCpu);
193220
LITERT_ASSIGN_OR_RETURN(
194-
auto plugin, ParsePlugin(plugin_dir, soc_manufacturer, compile_mode));
221+
auto plugin,
222+
ParsePlugin(plugin_dir, soc_manufacturer, compile_mode, target_options));
195223
AtsConf res(std::move(seeds), backend, quiet, dispatch_dir, plugin_dir,
196224
std::move(neg_re), std::move(pos_re), std::move(extra_models),
197-
f16_range_for_f32, data_seed, iters_per_test,
198-
std::move(max_ms_per_test_opt), fail_on_timeout, dump_report,
199-
std::move(csv), compile_mode, std::move(models_out), limit,
200-
std::move(plugin), std::move(soc_manufacturer),
201-
std::move(soc_model));
225+
data_seed, iters_per_test, std::move(max_ms_per_test_opt),
226+
fail_on_timeout, dump_report, std::move(csv), compile_mode,
227+
std::move(models_out), limit, std::move(plugin),
228+
std::move(soc_manufacturer), std::move(soc_model),
229+
std::move(target_options), std::move(reference_options));
202230
Setup(res);
203231
return res;
204232
}

litert/ats/configure.h

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@
2828
#include "litert/ats/common.h"
2929
#include "litert/cc/internal/litert_rng.h"
3030
#include "litert/cc/litert_expected.h"
31+
#include "litert/cc/litert_options.h"
3132
#include "litert/compiler/plugin/compiler_plugin.h"
3233
#include "litert/core/filesystem.h"
3334
#include "litert/core/model/model_serialize.h"
35+
#include "litert/tools/flags/vendors/mediatek_flags.h" // IWYU pragma: export
36+
#include "litert/tools/flags/vendors/qualcomm_flags.h" // IWYU pragma: export
3437

3538
// Seed for the data generation.
3639
ABSL_DECLARE_FLAG(std::optional<int>, data_seed);
@@ -59,9 +62,6 @@ ABSL_DECLARE_FLAG(std::string, dont_register);
5962
// Regex for explicit inclusions.
6063
ABSL_DECLARE_FLAG(std::string, do_register);
6164

62-
// Will generate values for f32 tensors in the range of f16 values.
63-
ABSL_DECLARE_FLAG(bool, f16_range_for_f32);
64-
6565
// Optional list of directories, or model files to add to the test.
6666
ABSL_DECLARE_FLAG(std::vector<std::string>, extra_models);
6767

@@ -232,6 +232,12 @@ class AtsConf {
232232
// compilation.
233233
const std::string& SocModel() const { return soc_model_; }
234234

235+
// Litert options to use for the target backend.
236+
const Options& TargetOptions() const { return target_options_; }
237+
238+
// Litert options to use for the reference backend.
239+
const Options& ReferenceOptions() const { return reference_options_; }
240+
235241
AtsConf(const AtsConf&) = delete;
236242
AtsConf& operator=(const AtsConf&) = delete;
237243
AtsConf(AtsConf&&) = default;
@@ -242,13 +248,13 @@ class AtsConf {
242248
bool quiet, std::string dispatch_dir, std::string plugin_dir,
243249
std::regex&& neg_re, std::regex&& pos_re,
244250
std::vector<std::string> extra_models,
245-
bool f16_range_for_f32, std::optional<int> data_seed,
246-
size_t iters_per_test,
251+
std::optional<int> data_seed, size_t iters_per_test,
247252
std::chrono::milliseconds max_ms_per_test,
248253
bool fail_on_timeout, bool dump_report, std::string csv,
249254
bool compile_mode, std::string models_out, int32_t limit,
250255
std::optional<internal::CompilerPlugin> plugin,
251-
std::string soc_manufacturer, std::string soc_model)
256+
std::string soc_manufacturer, std::string soc_model,
257+
Options&& target_options, Options&& reference_options)
252258
: seeds_for_params_(std::move(seeds_for_params)),
253259
backend_(backend),
254260
quiet_(quiet),
@@ -257,7 +263,7 @@ class AtsConf {
257263
neg_re_(std::move(neg_re)),
258264
pos_re_(std::move(pos_re)),
259265
extra_models_(std::move(extra_models)),
260-
f16_range_for_f32_(f16_range_for_f32),
266+
261267
data_seed_(data_seed),
262268
iters_per_test_(iters_per_test),
263269
max_ms_per_test_(std::move(max_ms_per_test)),
@@ -269,10 +275,12 @@ class AtsConf {
269275
limit_(limit),
270276
plugin_(std::move(plugin)),
271277
soc_manufacturer_(std::move(soc_manufacturer)),
272-
soc_model_(std::move(soc_model)) {
273-
if (f16_range_for_f32_) {
274-
data_builder_.SetF16InF32();
275-
}
278+
soc_model_(std::move(soc_model)),
279+
target_options_(std::move(target_options)),
280+
reference_options_(std::move(reference_options)) {
281+
// For now, we will provide default settings for data generation.
282+
// More configurability may be introduced later.
283+
data_builder_.SetSin();
276284
}
277285

278286
SeedMap seeds_for_params_;
@@ -284,7 +292,6 @@ class AtsConf {
284292
std::regex neg_re_;
285293
std::regex pos_re_;
286294
std::vector<std::string> extra_models_;
287-
bool f16_range_for_f32_;
288295
std::optional<int> data_seed_;
289296
size_t iters_per_test_;
290297
std::chrono::milliseconds max_ms_per_test_;
@@ -297,6 +304,8 @@ class AtsConf {
297304
std::optional<internal::CompilerPlugin> plugin_;
298305
std::string soc_manufacturer_;
299306
std::string soc_model_;
307+
Options target_options_;
308+
Options reference_options_;
300309

301310
RandomTensorDataBuilder data_builder_;
302311
};

0 commit comments

Comments
 (0)