Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions willow/api/client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "willow/api/client.h"

#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
Expand All @@ -22,7 +23,6 @@

#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "ffi_utils/cxx_utils.h"
#include "ffi_utils/status_macros.h"
Expand All @@ -45,24 +45,18 @@ absl::StatusOr<willow::AggregationConfigProto> CreateAggregationConfig(
config_proto.set_max_number_of_decryptors(max_number_of_decryptors);
config_proto.set_max_decryptor_dropouts(max_decryptor_dropouts);
config_proto.set_key_id(std::string(key_id));
// All metrics have same vector length, corresponding to the Cartesian product
// of group-by domains.
int64_t flattened_domain_size = 1;
for (const auto& group_by_spec : input_spec_proto.group_by_vector_specs()) {
if (group_by_spec.domain_spec().string_values().values_size() == 0) {
return absl::InvalidArgumentError(absl::StrCat(
"Missing domain, invalid domain type (must be StringValues), or "
"empty string_values for group by vector: ",
group_by_spec.vector_name()));
}
flattened_domain_size *=
group_by_spec.domain_spec().string_values().values_size();
}

// Validate the input spec and create the codec (for vector length).
SECAGG_ASSIGN_OR_RETURN(
auto codec, willow::Codec::CreateFlatHistogramCodec(input_spec_proto));

// Build VectorConfig (length and bound) for each metric.
for (const auto& metric_spec : input_spec_proto.metric_vector_specs()) {
auto& vector_config =
(*config_proto.mutable_vector_configs())[metric_spec.vector_name()];
vector_config.set_length(flattened_domain_size);
SECAGG_ASSIGN_OR_RETURN(size_t length, codec->GetEncodedVectorLength(
metric_spec.vector_name()));
vector_config.set_length(length);
if (metric_spec.has_domain_spec() &&
metric_spec.domain_spec().has_interval()) {
vector_config.set_bound(
Expand Down
46 changes: 43 additions & 3 deletions willow/input_encoding/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,80 @@ package(
default_visibility = ["//visibility:public"],
)

cc_library(
name = "time_utils",
srcs = [
"time_utils.cc",
],
hdrs = [
"time_utils.h",
],
deps = [
"@protobuf//:duration_cc_proto",
"@protobuf//:timestamp_cc_proto",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"//willow/proto/willow:input_spec_cc_proto",
],
)

cc_library(
name = "codec",
srcs = [
"codec_factory.cc",
"codec.cc",
],
hdrs = [
"codec.h",
"codec_factory.h",
],
deps = [
":time_utils",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/log:check",
"@abseil-cpp//absl/memory",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/status:statusor",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"//ffi_utils:status_macros",
"//willow/proto/willow:input_spec_cc_proto",
],
)

cc_test(
name = "explicit_codec_test",
srcs = ["explicit_codec_test.cc"],
name = "codec_test",
srcs = ["codec_test.cc"],
deps = [
":codec",
":time_utils",
"@protobuf//:duration_cc_proto",
"@googletest//:gtest_main",
"@abseil-cpp//absl/container:flat_hash_map",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/time",
"//ffi_utils:status_matchers",
"//willow/proto/willow:input_spec_cc_proto",
"//willow/testing_utils:testing_utils_cc",
],
)

cc_test(
name = "time_utils_test",
srcs = ["time_utils_test.cc"],
deps = [
":time_utils",
"@protobuf//:duration_cc_proto",
"@protobuf//:timestamp_cc_proto",
"@googletest//:gtest_main",
"@abseil-cpp//absl/status",
"@abseil-cpp//absl/time",
"//ffi_utils:status_matchers",
"//willow/proto/willow:input_spec_cc_proto",
],
)

pytype_pybind_extension(
name = "codec_bindings",
srcs = ["codec_bindings.cc"],
Expand Down
Loading