Skip to content

Commit 1f0ea0d

Browse files
szkarpinskicyyever
authored andcommitted
Add Cast and CoinFlip GPU benchmarks (NVIDIA#3541)
Signed-off-by: Szymon Karpiński <hugo@staszic.waw.pl>
1 parent 0fc0588 commit 1f0ea0d

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

dali/benchmark/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ if (BUILD_BENCHMARK)
3838
"${CMAKE_CURRENT_SOURCE_DIR}/copy_bench.cc"
3939
"${CMAKE_CURRENT_SOURCE_DIR}/gaussian_blur_bench.cc"
4040
"${CMAKE_CURRENT_SOURCE_DIR}/flip_bench.cc"
41+
"${CMAKE_CURRENT_SOURCE_DIR}/cast_bench.cc"
42+
"${CMAKE_CURRENT_SOURCE_DIR}/coin_flip_bench.cc"
4143
)
4244

4345
if (BUILD_LMDB)

dali/benchmark/cast_bench.cc

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2021, Szymon Karpiński. All rights reserved.
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+
#include <benchmark/benchmark.h>
16+
#include "dali/benchmark/operator_bench.h"
17+
#include "dali/benchmark/dali_bench.h"
18+
19+
namespace dali {
20+
21+
BENCHMARK_DEFINE_F(OperatorBench, CastGPU)(benchmark::State& st) {
22+
int batch_size = st.range(0);
23+
int H = st.range(1);
24+
int W = st.range(1);
25+
26+
this->RunGPU<uint8_t>(st,
27+
OpSpec("Cast")
28+
.AddArg("max_batch_size", batch_size)
29+
.AddArg("num_threads", 1)
30+
.AddArg("device", "gpu")
31+
.AddArg("dtype", DALI_FLOAT),
32+
batch_size, H, W);
33+
}
34+
35+
BENCHMARK_REGISTER_F(OperatorBench, CastGPU)->Iterations(100)
36+
->Unit(benchmark::kMicrosecond)
37+
->UseRealTime()
38+
->ArgsProduct({
39+
benchmark::CreateRange(1, 256, 2),
40+
{500, 1000},
41+
});
42+
43+
} // namespace dali

dali/benchmark/coin_flip_bench.cc

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2021, Szymon Karpiński. All rights reserved.
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+
#include <benchmark/benchmark.h>
16+
#include "dali/benchmark/operator_bench.h"
17+
#include "dali/benchmark/dali_bench.h"
18+
19+
namespace dali {
20+
21+
BENCHMARK_DEFINE_F(OperatorBench, CoinFlipGPU)(benchmark::State& st) {
22+
int batch_size = st.range(0);
23+
int H = st.range(1);
24+
int W = st.range(1);
25+
26+
this->RunGPU<uint8_t>(st,
27+
OpSpec("CoinFlip")
28+
.AddArg("max_batch_size", batch_size)
29+
.AddArg("num_threads", 1)
30+
.AddArg("device", "gpu")
31+
.AddInput("data", "gpu"),
32+
batch_size, H, W, 1);
33+
}
34+
35+
BENCHMARK_REGISTER_F(OperatorBench, CoinFlipGPU)->Iterations(100)
36+
->Unit(benchmark::kMicrosecond)
37+
->UseRealTime()
38+
->ArgsProduct({
39+
benchmark::CreateRange(1, 256, 2),
40+
{500, 1000, 2000},
41+
});
42+
43+
} // namespace dali

0 commit comments

Comments
 (0)