bm_knn.py 874 Bytes
Newer Older
Patrick Labatut's avatar
Patrick Labatut committed
1
2
3
4
5
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
Justin Johnson's avatar
Justin Johnson committed
6
7

from itertools import product
8

Justin Johnson's avatar
Justin Johnson committed
9
from fvcore.common.benchmark import benchmark
Georgia Gkioxari's avatar
Georgia Gkioxari committed
10
from test_knn import TestKNN
Justin Johnson's avatar
Justin Johnson committed
11
12
13
14


def bm_knn() -> None:

Georgia Gkioxari's avatar
Georgia Gkioxari committed
15
    backends = ["cpu", "cuda:0"]
Justin Johnson's avatar
Justin Johnson committed
16

Georgia Gkioxari's avatar
Georgia Gkioxari committed
17
18
19
20
    kwargs_list = []
    Ns = [32]
    P1s = [256]
    P2s = [128, 512]
Justin Johnson's avatar
Justin Johnson committed
21
    Ds = [3]
Georgia Gkioxari's avatar
Georgia Gkioxari committed
22
23
24
25
26
    Ks = [24]
    test_cases = product(Ns, P1s, P2s, Ds, Ks, backends)
    for case in test_cases:
        N, P1, P2, D, K, b = case
        kwargs_list.append({"N": N, "P1": P1, "P2": P2, "D": D, "K": K, "device": b})
Justin Johnson's avatar
Justin Johnson committed
27

Georgia Gkioxari's avatar
Georgia Gkioxari committed
28
    benchmark(TestKNN.knn_square, "KNN_SQUARE", kwargs_list, warmup_iters=1)
Justin Johnson's avatar
Justin Johnson committed
29

Georgia Gkioxari's avatar
Georgia Gkioxari committed
30
    benchmark(TestKNN.knn_ragged, "KNN_RAGGED", kwargs_list, warmup_iters=1)
Christoph Lassner's avatar
Christoph Lassner committed
31
32
33
34


if __name__ == "__main__":
    bm_knn()