xref: /aosp_15_r20/external/federated-compute/fcp/aggregation/core/BUILD (revision 14675a029014e728ec732f129a32e299b2da0601)
1# Copyright 2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# Aggregation Core API
16
17load("//fcp:config.bzl", "FCP_COPTS")
18
19package(
20    default_visibility = ["//fcp/aggregation:internal"],
21    licenses = ["notice"],  # Apache 2.0
22)
23
24# TODO(team): Create a "core" library that bundles all core libraries together.
25
26TENSOR_SRCS = [
27    "tensor.cc",
28    "tensor_data.cc",
29    "tensor_shape.cc",
30    "input_tensor_list.cc",
31]
32
33TENSOR_HDRS = [
34    "agg_vector.h",
35    "agg_vector_iterator.h",
36    "datatype.h",
37    "tensor.h",
38    "tensor_data.h",
39    "tensor_shape.h",
40    "tensor_spec.h",
41    "mutable_vector_data.h",
42    "input_tensor_list.h",
43]
44
45proto_library(
46    name = "tensor_proto",
47    srcs = ["tensor.proto"],
48)
49
50cc_proto_library(
51    name = "tensor_cc_proto",
52    deps = [":tensor_proto"],
53)
54
55cc_library(
56    name = "tensor",
57    srcs = TENSOR_SRCS,
58    hdrs = TENSOR_HDRS,
59    copts = FCP_COPTS,
60    deps = [
61        ":tensor_cc_proto",
62        "//fcp/base",
63        "@com_google_absl//absl/strings",
64        "@com_google_protobuf//:protobuf",
65    ],
66)
67
68AGGREGATOR_SRCS = [
69    "tensor_aggregator.cc",
70    "tensor_aggregator_registry.cc",
71]
72
73AGGREGATOR_HDRS = [
74    "agg_vector_aggregator.h",
75    "one_dim_grouping_aggregator.h",
76    "aggregator.h",
77    "tensor_aggregator.h",
78    "tensor_aggregator_factory.h",
79    "tensor_aggregator_registry.h",
80]
81
82cc_library(
83    name = "aggregator",
84    srcs = AGGREGATOR_SRCS,
85    hdrs = AGGREGATOR_HDRS,
86    copts = FCP_COPTS,
87    deps = [
88        ":tensor",
89        "//fcp/base",
90        "@com_google_absl//absl/container:flat_hash_map",
91        "@com_google_absl//absl/synchronization",
92    ],
93)
94
95cc_test(
96    name = "tensor_test",
97    srcs = [
98        "tensor_data_test.cc",
99        "tensor_shape_test.cc",
100        "tensor_test.cc",
101    ],
102    copts = FCP_COPTS,
103    deps = [
104        ":tensor",
105        ":tensor_cc_proto",
106        "//fcp/aggregation/testing",
107        "//fcp/aggregation/testing:test_data",
108        "//fcp/base",
109        "//fcp/testing",
110        "@com_google_googletest//:gtest_main",
111    ],
112)
113
114cc_test(
115    name = "agg_vector_test",
116    srcs = ["agg_vector_test.cc"],
117    copts = FCP_COPTS,
118    deps = [
119        ":tensor",
120        "//fcp/aggregation/testing:test_data",
121        "@com_google_googletest//:gtest_main",
122    ],
123)
124
125cc_test(
126    name = "aggregator_test",
127    srcs = [
128        "agg_vector_aggregator_test.cc",
129    ],
130    copts = FCP_COPTS,
131    deps = [
132        ":aggregator",
133        ":tensor",
134        ":tensor_cc_proto",
135        "//fcp/aggregation/testing",
136        "//fcp/aggregation/testing:test_data",
137        "//fcp/base",
138        "//fcp/testing",
139        "@com_google_googletest//:gtest_main",
140    ],
141)
142
143cc_test(
144    name = "tensor_aggregator_registry_test",
145    srcs = [
146        "tensor_aggregator_registry_test.cc",
147    ],
148    copts = FCP_COPTS,
149    deps = [
150        ":aggregator",
151        "//fcp/base",
152        "//fcp/testing",
153        "@com_google_googletest//:gtest_main",
154    ],
155)
156
157cc_library(
158    name = "federated_sum",
159    srcs = [
160        "federated_sum.cc",
161    ],
162    copts = FCP_COPTS,
163    deps = [
164        ":aggregator",
165        ":tensor",
166        "//fcp/base",
167    ],
168    alwayslink = 1,
169)
170
171cc_library(
172    name = "composite_key_combiner",
173    srcs = ["composite_key_combiner.cc"],
174    hdrs = ["composite_key_combiner.h"],
175    deps = [
176        ":tensor",
177        ":tensor_cc_proto",
178        ":vector_string_data",
179        "//fcp/base",
180    ],
181)
182
183# Separate target from :tensor is required for vector_string_data as string_view is not yet
184# supported for nanolibc.
185cc_library(
186    name = "vector_string_data",
187    hdrs = ["vector_string_data.h"],
188    deps = [":tensor"],
189)
190
191cc_test(
192    name = "federated_sum_test",
193    srcs = ["federated_sum_test.cc"],
194    copts = FCP_COPTS,
195    deps = [
196        ":aggregator",
197        ":federated_sum",
198        ":tensor",
199        "//fcp/aggregation/testing",
200        "//fcp/aggregation/testing:test_data",
201        "//fcp/testing",
202        "@com_google_googletest//:gtest_main",
203    ],
204)
205
206cc_test(
207    name = "input_tensor_list_test",
208    srcs = ["input_tensor_list_test.cc"],
209    deps = [
210        ":tensor",
211        "//fcp/aggregation/testing:test_data",
212        "@com_google_googletest//:gtest_main",
213    ],
214)
215
216cc_test(
217    name = "composite_key_combiner_test",
218    srcs = ["composite_key_combiner_test.cc"],
219    deps = [
220        ":composite_key_combiner",
221        ":tensor",
222        ":tensor_cc_proto",
223        "//fcp/aggregation/testing",
224        "//fcp/aggregation/testing:test_data",
225        "//fcp/base",
226        "//fcp/testing",
227        "@com_google_googletest//:gtest_main",
228    ],
229)
230
231cc_test(
232    name = "mutable_vector_data_test",
233    srcs = ["mutable_vector_data_test.cc"],
234    deps = [
235        ":tensor",
236        "//fcp/testing",
237        "@com_google_googletest//:gtest_main",
238    ],
239)
240
241cc_test(
242    name = "vector_string_data_test",
243    srcs = ["vector_string_data_test.cc"],
244    deps = [
245        ":tensor",
246        ":vector_string_data",
247        "//fcp/testing",
248        "@com_google_googletest//:gtest_main",
249    ],
250)
251
252cc_test(
253    name = "one_dim_grouping_aggregator_test",
254    srcs = ["one_dim_grouping_aggregator_test.cc"],
255    deps = [
256        ":aggregator",
257        ":tensor",
258        "//fcp/aggregation/testing",
259        "//fcp/aggregation/testing:test_data",
260        "//fcp/base",
261        "//fcp/testing",
262        "@com_google_googletest//:gtest_main",
263    ],
264)
265
266cc_binary(
267    name = "federated_sum_bench",
268    testonly = 1,
269    srcs = ["federated_sum_bench.cc"],
270    copts = FCP_COPTS,
271    linkstatic = 1,
272    deps = [
273        ":aggregator",
274        ":federated_sum",
275        ":tensor",
276        "@com_google_benchmark//:benchmark_main",
277    ],
278)
279