diff --git a/litert/ats/BUILD b/litert/ats/BUILD index 3a3ddc1d99..e4e22a43da 100644 --- a/litert/ats/BUILD +++ b/litert/ats/BUILD @@ -62,17 +62,25 @@ cc_library( testonly = True, srcs = ["configure.cc"], hdrs = ["configure.h"], - copts = commandline_flag_copts(), + copts = commandline_flag_copts() + [ + "-DINCLUDE_QUALCOMM_COMPILE_FLAGS", + "-DINCLUDE_QUALCOMM_RUNTIME_FLAGS", + "-DINCLUDE_MEDIATEK_COMPILE_FLAGS", + "-DINCLUDE_MEDIATEK_RUNTIME_FLAGS", + ], deps = [ ":common", "//litert/c:litert_common", "//litert/c/internal:litert_logging", "//litert/cc:litert_expected", "//litert/cc:litert_macros", + "//litert/cc:litert_options", "//litert/cc/internal:litert_rng", "//litert/compiler/plugin:compiler_plugin", "//litert/core:filesystem_testonly", "//litert/core/model:model_serialize", + "//litert/tools/flags/vendors:mediatek_flags", + "//litert/tools/flags/vendors:qualcomm_flags", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/flags:flag", "@com_google_absl//absl/strings", @@ -111,6 +119,7 @@ cc_library( "//litert/cc:litert_expected", "//litert/cc/internal:litert_detail", "//litert/cc/internal:litert_rng", + "//litert/core:filesystem", "//litert/test/generators", ], ) @@ -120,8 +129,10 @@ cc_test( srcs = ["executor_test.cc"], deps = [ ":executor", + "//litert/c:litert_common", "//litert/c:litert_op_code", "//litert/cc:litert_buffer_ref", + "//litert/cc:litert_options", "//litert/core/model", "//litert/test:matchers", "//litert/test:simple_buffer", @@ -186,8 +197,10 @@ litert_device_test( defines = ["_TEST_NPU"], deps = [ ":executor", + "//litert/c:litert_common", "//litert/c:litert_op_code", "//litert/cc:litert_buffer_ref", + "//litert/cc:litert_options", "//litert/core/model", "//litert/test:matchers", "//litert/test:simple_buffer", @@ -367,7 +380,6 @@ litert_define_ats( # "^(?:(?!npu_ats_87).)*$$", ], extra_flags = [ - "--f16_range_for_f32=true", "--data_seed=42", ], jit_suffix = "", diff --git a/litert/ats/check_ats.cc b/litert/ats/check_ats.cc index 08bdb82c4c..f577383a37 100644 --- a/litert/ats/check_ats.cc +++ b/litert/ats/check_ats.cc @@ -179,7 +179,8 @@ Expected CheckAts() { LITERT_ASSIGN_OR_RETURN(auto exec, NpuCompiledModelExecutor::Create( - *model, npu_inference_options.DispatchDir())); + *model, npu_inference_options.TargetOptions(), + npu_inference_options.DispatchDir())); const auto& subgraph = *model->Subgraphs()[0]; LITERT_ASSIGN_OR_RETURN( auto inputs, SimpleBuffer::LikeSignature(subgraph.Inputs().begin(), diff --git a/litert/ats/common.h b/litert/ats/common.h index 61858c305b..f95448a8f9 100644 --- a/litert/ats/common.h +++ b/litert/ats/common.h @@ -48,11 +48,13 @@ struct TestNames { } // Create with an explicit desc. - static TestNames Create(size_t test_id, absl::string_view family, - absl::string_view logic, absl::string_view test, + static TestNames Create(size_t test_id, absl::string_view fixture, + absl::string_view source, absl::string_view test, + absl::string_view report_id, absl::string_view desc = "") { - auto suite = MakeSuite(test_id, family, logic); - return {suite, std::string(logic), std::string(desc), std::string(test)}; + auto suite = MakeSuite(test_id, fixture, source); + return {suite, std::string(test), std::string(desc), + std::string(report_id)}; } private: @@ -98,7 +100,7 @@ enum class CompilationStatus { // Timing related types. using Clock = std::chrono::steady_clock; using TimePoint = Clock::time_point; -using Nanoseconds = uint64_t; +using Microseconds = uint64_t; // Which backend to use as the "actual". enum class ExecutionBackend { kCpu, kGpu, kNpu }; @@ -175,7 +177,7 @@ void AbslStringify(Sink& sink, const CompilationStatus& status) { } template -void AbslStringify(Sink& sink, const Nanoseconds& ns) { +void AbslStringify(Sink& sink, const Microseconds& ns) { absl::Format(&sink, "%e", ns); } diff --git a/litert/ats/compile_capture.h b/litert/ats/compile_capture.h index 7d7aa79099..5fcaa22c87 100644 --- a/litert/ats/compile_capture.h +++ b/litert/ats/compile_capture.h @@ -29,25 +29,25 @@ namespace litert::testing { // Information about the time taken to compile the model. -class CompilationTime : public Printable { +class CompilationTime : public Printable { public: // Start timing. TimePoint Start() const { return Clock::now(); } // Stop timing and record the latency. void Stop(const TimePoint& start) { - std::chrono::duration nano = Clock::now() - start; + std::chrono::duration nano = Clock::now() - start; nanos_ = nano.count(); } - Nanoseconds Nanos() const { return nanos_; } + Microseconds Nanos() const { return nanos_; } CompilationTime() : Printable("CompilationTime", "compile_time(ns)") {} private: Fields GetFields() const override { return Fields{nanos_}; } - Nanoseconds nanos_ = std::numeric_limits::max(); + Microseconds nanos_ = std::numeric_limits::max(); }; // Type to hold all of the capturable information related compilation test diff --git a/litert/ats/compile_capture_test.cc b/litert/ats/compile_capture_test.cc index 7f8a2a8f8d..8f12ce02ca 100644 --- a/litert/ats/compile_capture_test.cc +++ b/litert/ats/compile_capture_test.cc @@ -33,7 +33,7 @@ TEST(AtsCompileCaptureTest, Basic) { e.model.name = "FOO"; ASSERT_NE(e.compilation_time.Nanos(), - std::numeric_limits::max()); + std::numeric_limits::max()); std::ostringstream s; cap.Print(s); diff --git a/litert/ats/configure.cc b/litert/ats/configure.cc index 67cf75f0c8..249f2a6799 100644 --- a/litert/ats/configure.cc +++ b/litert/ats/configure.cc @@ -33,7 +33,10 @@ #include "litert/c/litert_common.h" #include "litert/cc/litert_expected.h" #include "litert/cc/litert_macros.h" +#include "litert/cc/litert_options.h" #include "litert/compiler/plugin/compiler_plugin.h" +#include "litert/tools/flags/vendors/mediatek_flags.h" // IWYU pragma: export +#include "litert/tools/flags/vendors/qualcomm_flags.h" // IWYU pragma: export ABSL_FLAG(std::optional, data_seed, std::nullopt, "Seed for the buffer data generation."); @@ -113,6 +116,9 @@ namespace litert::testing { namespace { +using ::litert::mediatek::MediatekOptionsFromFlags; +using ::litert::qualcomm::QualcommOptionsFromFlags; + Expected ParseParamSeedMap() { const auto seed_flags = absl::GetFlag(FLAGS_seeds); AtsConf::SeedMap seeds; @@ -143,15 +149,34 @@ Expected ParseBackend() { } } +Expected ParseOptions(ExecutionBackend backend) { + LITERT_ASSIGN_OR_RETURN(auto options, Options::Create()); + if (backend == ExecutionBackend::kNpu) { + if (auto qnn_opts = QualcommOptionsFromFlags()) { + options.AddOpaqueOptions(std::move(*qnn_opts)); + } + if (auto mediatek_opts = MediatekOptionsFromFlags()) { + options.AddOpaqueOptions(std::move(*mediatek_opts)); + } + options.SetHardwareAccelerators(kLiteRtHwAcceleratorNpu); + } else if (backend == ExecutionBackend::kCpu) { + options.SetHardwareAccelerators(kLiteRtHwAcceleratorCpu); + } else if (backend == ExecutionBackend::kGpu) { + options.SetHardwareAccelerators(kLiteRtHwAcceleratorGpu); + } + return options; +} + Expected> ParsePlugin( absl::string_view plugin_dir, absl::string_view soc_manufacturer, - bool compile_mode) { + bool compile_mode, const Options& litert_options) { using R = std::optional; if (!compile_mode) { return R(std::nullopt); } LITERT_ASSIGN_OR_RETURN(auto plugin, internal::CompilerPlugin::FindPlugin( - soc_manufacturer, {plugin_dir})); + soc_manufacturer, {plugin_dir}, + nullptr, litert_options.Get())); return R(std::move(plugin)); } @@ -171,7 +196,6 @@ Expected AtsConf::ParseFlagsAndDoSetup() { std::regex pos_re(absl::GetFlag(FLAGS_do_register), std::regex_constants::ECMAScript); auto extra_models = absl::GetFlag(FLAGS_extra_models); - auto f16_range_for_f32 = absl::GetFlag(FLAGS_f16_range_for_f32); auto data_seed = absl::GetFlag(FLAGS_data_seed); auto dispatch_dir = absl::GetFlag(FLAGS_dispatch_dir); auto plugin_dir = absl::GetFlag(FLAGS_plugin_dir); @@ -190,15 +214,19 @@ Expected AtsConf::ParseFlagsAndDoSetup() { auto limit = absl::GetFlag(FLAGS_limit); auto soc_manufacturer = absl::GetFlag(FLAGS_soc_manufacturer); auto soc_model = absl::GetFlag(FLAGS_soc_model); + LITERT_ASSIGN_OR_RETURN(auto target_options, ParseOptions(backend)); + LITERT_ASSIGN_OR_RETURN(auto reference_options, Options::Create()); + reference_options.SetHardwareAccelerators(kLiteRtHwAcceleratorCpu); LITERT_ASSIGN_OR_RETURN( - auto plugin, ParsePlugin(plugin_dir, soc_manufacturer, compile_mode)); + auto plugin, + ParsePlugin(plugin_dir, soc_manufacturer, compile_mode, target_options)); AtsConf res(std::move(seeds), backend, quiet, dispatch_dir, plugin_dir, std::move(neg_re), std::move(pos_re), std::move(extra_models), - f16_range_for_f32, data_seed, iters_per_test, - std::move(max_ms_per_test_opt), fail_on_timeout, dump_report, - std::move(csv), compile_mode, std::move(models_out), limit, - std::move(plugin), std::move(soc_manufacturer), - std::move(soc_model)); + data_seed, iters_per_test, std::move(max_ms_per_test_opt), + fail_on_timeout, dump_report, std::move(csv), compile_mode, + std::move(models_out), limit, std::move(plugin), + std::move(soc_manufacturer), std::move(soc_model), + std::move(target_options), std::move(reference_options)); Setup(res); return res; } diff --git a/litert/ats/configure.h b/litert/ats/configure.h index 76c8807129..682f4d5de8 100644 --- a/litert/ats/configure.h +++ b/litert/ats/configure.h @@ -28,9 +28,12 @@ #include "litert/ats/common.h" #include "litert/cc/internal/litert_rng.h" #include "litert/cc/litert_expected.h" +#include "litert/cc/litert_options.h" #include "litert/compiler/plugin/compiler_plugin.h" #include "litert/core/filesystem.h" #include "litert/core/model/model_serialize.h" +#include "litert/tools/flags/vendors/mediatek_flags.h" // IWYU pragma: export +#include "litert/tools/flags/vendors/qualcomm_flags.h" // IWYU pragma: export // Seed for the data generation. ABSL_DECLARE_FLAG(std::optional, data_seed); @@ -59,9 +62,6 @@ ABSL_DECLARE_FLAG(std::string, dont_register); // Regex for explicit inclusions. ABSL_DECLARE_FLAG(std::string, do_register); -// Will generate values for f32 tensors in the range of f16 values. -ABSL_DECLARE_FLAG(bool, f16_range_for_f32); - // Optional list of directories, or model files to add to the test. ABSL_DECLARE_FLAG(std::vector, extra_models); @@ -232,6 +232,12 @@ class AtsConf { // compilation. const std::string& SocModel() const { return soc_model_; } + // Litert options to use for the target backend. + const Options& TargetOptions() const { return target_options_; } + + // Litert options to use for the reference backend. + const Options& ReferenceOptions() const { return reference_options_; } + AtsConf(const AtsConf&) = delete; AtsConf& operator=(const AtsConf&) = delete; AtsConf(AtsConf&&) = default; @@ -242,13 +248,13 @@ class AtsConf { bool quiet, std::string dispatch_dir, std::string plugin_dir, std::regex&& neg_re, std::regex&& pos_re, std::vector extra_models, - bool f16_range_for_f32, std::optional data_seed, - size_t iters_per_test, + std::optional data_seed, size_t iters_per_test, std::chrono::milliseconds max_ms_per_test, bool fail_on_timeout, bool dump_report, std::string csv, bool compile_mode, std::string models_out, int32_t limit, std::optional plugin, - std::string soc_manufacturer, std::string soc_model) + std::string soc_manufacturer, std::string soc_model, + Options&& target_options, Options&& reference_options) : seeds_for_params_(std::move(seeds_for_params)), backend_(backend), quiet_(quiet), @@ -257,7 +263,7 @@ class AtsConf { neg_re_(std::move(neg_re)), pos_re_(std::move(pos_re)), extra_models_(std::move(extra_models)), - f16_range_for_f32_(f16_range_for_f32), + data_seed_(data_seed), iters_per_test_(iters_per_test), max_ms_per_test_(std::move(max_ms_per_test)), @@ -269,10 +275,12 @@ class AtsConf { limit_(limit), plugin_(std::move(plugin)), soc_manufacturer_(std::move(soc_manufacturer)), - soc_model_(std::move(soc_model)) { - if (f16_range_for_f32_) { - data_builder_.SetF16InF32(); - } + soc_model_(std::move(soc_model)), + target_options_(std::move(target_options)), + reference_options_(std::move(reference_options)) { + // For now, we will provide default settings for data generation. + // More configurability may be introduced later. + data_builder_.SetSin(); } SeedMap seeds_for_params_; @@ -284,7 +292,6 @@ class AtsConf { std::regex neg_re_; std::regex pos_re_; std::vector extra_models_; - bool f16_range_for_f32_; std::optional data_seed_; size_t iters_per_test_; std::chrono::milliseconds max_ms_per_test_; @@ -297,6 +304,8 @@ class AtsConf { std::optional plugin_; std::string soc_manufacturer_; std::string soc_model_; + Options target_options_; + Options reference_options_; RandomTensorDataBuilder data_builder_; }; diff --git a/litert/ats/executor.h b/litert/ats/executor.h index 2af940147a..ebc2cc96b8 100644 --- a/litert/ats/executor.h +++ b/litert/ats/executor.h @@ -87,16 +87,12 @@ class CompiledModelExecutor { virtual ~CompiledModelExecutor() = default; protected: - CompiledModelExecutor(CompiledModel&& api, Options&& options, - Environment&& env) - : api_(std::move(api)), - options_(std::move(options)), - env_(std::move(env)) {} + CompiledModelExecutor(CompiledModel&& api, Environment&& env) + : api_(std::move(api)), env_(std::move(env)) {} CompiledModel api_; private: - Options options_; Environment env_; }; @@ -113,32 +109,28 @@ class CpuCompiledModelExecutor : public CompiledModelExecutor { static constexpr absl::string_view Name() { return "cpu"; } - static Expected Create(LiteRtModelT& model) { + static Expected Create(LiteRtModelT& model, + const Options& options) { // Setup options. const std::vector environment_options = {}; LITERT_ASSIGN_OR_RETURN(auto env, Environment::Create(environment_options)); - LITERT_ASSIGN_OR_RETURN(auto options, Options::Create()); - options.SetHardwareAccelerators(kLiteRtHwAcceleratorCpu); - // Init compiled model api. LITERT_ASSIGN_OR_RETURN( auto api, CompiledModel::Create( env, Model::CreateFromNonOwnedHandle(&model), options)); - return CpuCompiledModelExecutor(std::move(api), std::move(options), - std::move(env)); + return CpuCompiledModelExecutor(std::move(api), std::move(env)); } static Expected Create(LiteRtModelT& model, + const Options& options, const Args& args) { - return Create(model); + return Create(model, options); } private: - CpuCompiledModelExecutor(CompiledModel&& api, Options&& options, - Environment&& env) - : CompiledModelExecutor(std::move(api), std::move(options), - std::move(env)) {} + CpuCompiledModelExecutor(CompiledModel&& api, Environment&& env) + : CompiledModelExecutor(std::move(api), std::move(env)) {} }; // Executor for the NPU backend. @@ -158,12 +150,14 @@ class NpuCompiledModelExecutor : public CompiledModelExecutor { static constexpr absl::string_view Name() { return "npu"; } static Expected Create(LiteRtModelT& model, + const Options& options, const Args& args) { - return Create(model, args.dispatch_dir, args.plugin_dir); + return Create(model, options, args.dispatch_dir, args.plugin_dir); } static Expected Create( - LiteRtModelT& model, const std::string& dispatch_dir, + LiteRtModelT& model, const Options& options, + const std::string& dispatch_dir, const std::optional& plugin_dir = std::nullopt) { std::vector environment_options = { litert::Environment::Option{ @@ -177,21 +171,15 @@ class NpuCompiledModelExecutor : public CompiledModelExecutor { }); } LITERT_ASSIGN_OR_RETURN(auto env, Environment::Create(environment_options)); - LITERT_ASSIGN_OR_RETURN(auto options, Options::Create()); - LITERT_RETURN_IF_ERROR( - options.SetHardwareAccelerators(kLiteRtHwAcceleratorNpu)); LITERT_ASSIGN_OR_RETURN( auto api, CompiledModel::Create( env, Model::CreateFromNonOwnedHandle(&model), options)); - return NpuCompiledModelExecutor(std::move(api), std::move(options), - std::move(env)); + return NpuCompiledModelExecutor(std::move(api), std::move(env)); } private: - NpuCompiledModelExecutor(CompiledModel&& api, Options&& options, - Environment&& env) - : CompiledModelExecutor(std::move(api), std::move(options), - std::move(env)) {} + NpuCompiledModelExecutor(CompiledModel&& api, Environment&& env) + : CompiledModelExecutor(std::move(api), std::move(env)) {} }; } // namespace litert::testing diff --git a/litert/ats/executor_test.cc b/litert/ats/executor_test.cc index a1ba01285f..a73ede06dd 100644 --- a/litert/ats/executor_test.cc +++ b/litert/ats/executor_test.cc @@ -20,9 +20,11 @@ #include #include +#include "litert/c/litert_common.h" #include "litert/c/litert_model.h" #include "litert/c/litert_op_code.h" #include "litert/cc/litert_buffer_ref.h" +#include "litert/cc/litert_options.h" #include "litert/core/model/model.h" #include "litert/test/generators/graph_helpers.h" #include "litert/test/matchers.h" @@ -49,8 +51,10 @@ TEST(CpuCompiledModelExecutorTest, CreateAndRunModel) { {std::move(lhs), std::move(rhs)}, {std::move(output)}, tflite::ActivationFunctionType_NONE, false)); - LITERT_ASSERT_OK_AND_ASSIGN(auto executor, - CpuCompiledModelExecutor::Create(*model)); + LITERT_ASSERT_OK_AND_ASSIGN(auto options, Options::Create()); + options.SetHardwareAccelerators(kLiteRtHwAcceleratorCpu); + LITERT_ASSERT_OK_AND_ASSIGN( + auto executor, CpuCompiledModelExecutor::Create(*model, options)); std::vector inputs; LITERT_ASSERT_OK_AND_ASSIGN( auto input, SimpleBuffer::Create({2, 2}, {1, 1, 1, 1})); @@ -75,9 +79,12 @@ TEST(NpuCompiledModelExecutorTest, CreateAndRunModel) { {std::move(lhs), std::move(rhs)}, {std::move(output)}, tflite::ActivationFunctionType_NONE, false)); + LITERT_ASSERT_OK_AND_ASSIGN(auto options, Options::Create()); + options.SetHardwareAccelerators(kLiteRtHwAcceleratorNpu); LITERT_ASSERT_OK_AND_ASSIGN( - auto executor, NpuCompiledModelExecutor::Create(*model, "/data/local/tmp", - "/data/local/tmp")); + auto executor, + NpuCompiledModelExecutor::Create(*model, options, "/data/local/tmp", + "/data/local/tmp")); std::vector inputs; LITERT_ASSERT_OK_AND_ASSIGN( diff --git a/litert/ats/inference_capture.h b/litert/ats/inference_capture.h index 0d4db2b29e..c09e1854b2 100644 --- a/litert/ats/inference_capture.h +++ b/litert/ats/inference_capture.h @@ -35,7 +35,7 @@ namespace litert::testing { // Information about the latency of the execution. class Latency - : public Printable { + : public Printable { public: using Ref = std::reference_wrapper; @@ -58,17 +58,18 @@ class Latency // Stop timing and record the latency. void Stop(const TimePoint& start) { - std::chrono::duration nano = Clock::now() - start; - latencies_.push_back(nano.count()); + const auto micro = std::chrono::duration_cast< + std::chrono::duration>(Clock::now() - start); + latencies_.push_back(micro.count()); } // Average latency. - Nanoseconds Avg() const { + Microseconds Avg() const { return ::litert::Avg(latencies_.cbegin(), latencies_.cend()); } // Maximum latency. - Nanoseconds Max() const { + Microseconds Max() const { if (latencies_.empty()) { return 0; } @@ -76,7 +77,7 @@ class Latency } // Minimum latency. - Nanoseconds Min() const { + Microseconds Min() const { if (latencies_.empty()) { return 0; } @@ -87,15 +88,15 @@ class Latency size_t NumSamples() const { return latencies_.size(); } Latency() - : Printable("Latency", "avg_latency(ns)", "max_latency(ns)", - "min_latency(ns)", "num_samples") {} + : Printable("Latency", "avg_latency(us)", "max_latency(us)", + "min_latency(us)", "num_samples") {} private: Fields GetFields() const override { return Fields{Avg(), Max(), Min(), NumSamples()}; } - std::vector latencies_; + std::vector latencies_; }; // Information about the numerics of the execution. diff --git a/litert/ats/inference_fixture.h b/litert/ats/inference_fixture.h index 98b1b8295e..1df7463ea7 100644 --- a/litert/ats/inference_fixture.h +++ b/litert/ats/inference_fixture.h @@ -15,6 +15,7 @@ #ifndef THIRD_PARTY_ODML_LITERT_LITERT_ATS_INFERENCE_FIXTURE_H_ #define THIRD_PARTY_ODML_LITERT_LITERT_ATS_INFERENCE_FIXTURE_H_ +#include #include #include #include @@ -116,8 +117,9 @@ class AtsInferenceTest : public RngTest { Expected MakeExecutor() { CompiledModelExecutor::Ptr exec; if (conf_.IsNpu()) { - auto exec = NpuCompiledModelExecutor::Create(Graph(), conf_.DispatchDir(), - conf_.PluginDir()); + auto exec = NpuCompiledModelExecutor::Create( + Graph(), conf_.TargetOptions(), conf_.DispatchDir(), + conf_.PluginDir()); cap_.compilation.SetFields(conf_, Graph(), !exec.HasValue()); if (!exec) { return exec.Error(); @@ -125,8 +127,8 @@ class AtsInferenceTest : public RngTest { auto res = std::make_unique(std::move(*exec)); return res; } else if (conf_.IsCpu()) { - LITERT_ASSIGN_OR_RETURN(auto exec, - CpuCompiledModelExecutor::Create(Graph())); + LITERT_ASSIGN_OR_RETURN(auto exec, CpuCompiledModelExecutor::Create( + Graph(), conf_.TargetOptions())); return std::make_unique(std::move(exec)); } @@ -135,7 +137,23 @@ class AtsInferenceTest : public RngTest { template Expected MakeInputs(Rng& device) const { - return graph_->MakeInputs(device, conf_.DataBuilder()); + auto inputs = graph_->MakeInputs(device, conf_.DataBuilder()); + if (!inputs.HasValue()) return inputs.Error(); + + LITERT_LOG(LITERT_INFO, "First 5 elements of each input:"); + for (size_t i = 0; i < inputs->size(); ++i) { + const auto& input = (*inputs)[i]; + LITERT_LOG(LITERT_INFO, " Input %zu:", i); + if (input.Type().ElementType() == ElementType::Float32) { + const auto& view = input.template AsView(); + for (int j = 0; j < std::min(5, (int)view.data.size()); ++j) { + LITERT_LOG(LITERT_INFO, " [%d]: %f", j, view.data[j]); + } + } else { + LITERT_LOG(LITERT_INFO, " Unsupported element type for printing."); + } + } + return inputs; } Expected Actual(const VarBuffers& inputs, @@ -155,8 +173,8 @@ class AtsInferenceTest : public RngTest { } Expected CpuReference(const VarBuffers& inputs) const { - LITERT_ASSIGN_OR_RETURN(auto exec, - CpuCompiledModelExecutor::Create(Graph())); + LITERT_ASSIGN_OR_RETURN(auto exec, CpuCompiledModelExecutor::Create( + Graph(), conf_.ReferenceOptions())); return exec.Run(inputs); } @@ -184,7 +202,13 @@ class AtsInferenceTest : public RngTest { template void CheckOutputImpl(const BufferView& actual, const BufferView& ref) { double mse = std::numeric_limits::max(); - EXPECT_THAT(actual.data, MeanSquaredErrorLt(ref.data, 1e-5, &mse)); + LITERT_LOG(LITERT_INFO, "First 5 elements:"); + for (int i = 0; i < std::min(5, (int)actual.data.size()); ++i) { + LITERT_LOG(LITERT_INFO, " actual[%d]: %f, ref[%d]: %f", i, + static_cast(actual.data[i]), i, + static_cast(ref.data[i])); + } + EXPECT_THAT(actual.data, MeanSquaredErrorLt(ref.data, 1e-4, &mse)); cap_.numerics.NewMse(mse); } diff --git a/litert/ats/register.h b/litert/ats/register.h index 10e64d2fa9..d3ecf6b73e 100644 --- a/litert/ats/register.h +++ b/litert/ats/register.h @@ -25,6 +25,7 @@ #include "litert/cc/internal/litert_detail.h" #include "litert/cc/internal/litert_rng.h" #include "litert/cc/litert_expected.h" +#include "litert/core/filesystem.h" #include "litert/test/generators/generators.h" namespace litert::testing { @@ -116,9 +117,10 @@ void RegisterExtraModels(size_t& test_id, const AtsConf& options, file.c_str(), model.Error().Message().c_str()); continue; } + auto test_name = internal::Filename(file); auto names = NamesForNextTest(test_id, options, Fixture::Name(), ExtraModel::Name(), - file, "user provided tflite"); + *test_name, file, "user provided tflite"); if (!names) { continue; } diff --git a/litert/cc/internal/litert_rng.h b/litert/cc/internal/litert_rng.h index 38898f4dd2..191539023e 100644 --- a/litert/cc/internal/litert_rng.h +++ b/litert/cc/internal/litert_rng.h @@ -260,6 +260,23 @@ class F16InF32Generator final { } }; +template +class SinGenerator final : public DataGeneratorBase {}; + +// Generates sin values in the range [-1, 1]. +template <> +class SinGenerator final : public DataGeneratorBase { + public: + SinGenerator() = default; + + template + float operator()(Rng& rng) { + return std::sin(rng() * 0.12345f); + } + float Max() const override { return 1.0f; } + float Min() const override { return -1.0f; } +}; + // Dummy primitive generator that returns a monotonically increasing sequence. template class DummyGenerator final : public DataGeneratorBase { @@ -536,6 +553,11 @@ class RandomTensorDataBuilder { return *this; } + RandomTensorDataBuilder& SetSin() { + float_config_ = Sin(); + return *this; + } + template std::pair Bounds() const { if constexpr (std::is_same_v) { @@ -556,6 +578,8 @@ class RandomTensorDataBuilder { std::numeric_limits::max()}; } else if (std::holds_alternative(float_config_)) { return {std::numeric_limits::lowest(), 65504.0}; + } else if (std::holds_alternative(float_config_)) { + return {-1.0f, 1.0f}; } else { auto [min, max] = std::get>(float_config_); return {min, max}; @@ -589,6 +613,9 @@ class RandomTensorDataBuilder { } else if (std::holds_alternative(float_config_)) { RandomTensorData data; return Functor()(data, std::forward(args)...); + } else if (std::holds_alternative(float_config_)) { + RandomTensorData data; + return Functor()(data, std::forward(args)...); } else { auto [min, max] = std::get>(float_config_); RandomTensorData data(min, max); @@ -603,12 +630,13 @@ class RandomTensorDataBuilder { struct Dummy {}; struct NullOpt {}; struct F16InF32 {}; + struct Sin {}; template using IntConfig = std::variant, Dummy, NullOpt>; template using FloatConfig = - std::variant, Dummy, NullOpt, F16InF32>; + std::variant, Dummy, NullOpt, F16InF32, Sin>; IntConfig int_config_ = NullOpt(); FloatConfig float_config_ = NullOpt(); diff --git a/litert/tools/flags/vendors/BUILD b/litert/tools/flags/vendors/BUILD index 8547ad08ea..1dea974e2e 100644 --- a/litert/tools/flags/vendors/BUILD +++ b/litert/tools/flags/vendors/BUILD @@ -14,6 +14,7 @@ load("@rules_cc//cc:cc_library.bzl", "cc_library") load("@rules_cc//cc:cc_test.bzl", "cc_test") +load("//litert/build_common:litert_build_defs.bzl", "commandline_flag_copts") package( # copybara:uncomment default_applicable_licenses = ["@org_tensorflow//tensorflow:license"], @@ -26,7 +27,7 @@ cc_library( name = "qualcomm_flags", srcs = ["qualcomm_flags.cc"], hdrs = ["qualcomm_flags.h"], - copts = [ + copts = commandline_flag_copts() + [ "-DINCLUDE_QUALCOMM_COMPILE_FLAGS", "-DINCLUDE_QUALCOMM_RUNTIME_FLAGS", ], @@ -136,7 +137,7 @@ cc_library( name = "mediatek_flags", srcs = ["mediatek_flags.cc"], hdrs = ["mediatek_flags.h"], - copts = [ + copts = commandline_flag_copts() + [ "-DINCLUDE_MEDIATEK_COMPILE_FLAGS", "-DINCLUDE_MEDIATEK_RUNTIME_FLAGS", ],