-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhipAllocCopyBench.cpp
39 lines (34 loc) · 1.42 KB
/
hipAllocCopyBench.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <benchmark/benchmark.h>
#include <iostream>
#include <hip/hip_runtime.h>
static void BM_hipalloc(benchmark::State& state) {
for (auto _ : state) {
int *a;
hipMalloc((void**)&a, 10 * sizeof(int));
hipFree(a);
}
}
// Register the function as a benchmark
BENCHMARK(BM_hipalloc);
static void BM_hipcopy(benchmark::State& state) {
for (auto _ : state) {
int *a;
int b[] = {1,2,3,4,5,6,7,8,9,10};
hipMalloc((void**)&a, 10 * sizeof(int));
hipMemcpy(a, b, 10 * sizeof(float), hipMemcpyHostToDevice);
hipFree(a);
}
}
BENCHMARK(BM_hipcopy);
static void BM_hipcopyback(benchmark::State& state) {
for (auto _ : state) {
int *a;
int b[] = {1,2,3,4,5,6,7,8,9,10};
hipMalloc((void**)&a, 10 * sizeof(int));
hipMemcpy(a, b, 10 * sizeof(float), hipMemcpyHostToDevice);
hipMemcpy(b, a, 10 * sizeof(float), hipMemcpyDeviceToHost);
hipFree(a);
}
}
BENCHMARK(BM_hipcopyback);
BENCHMARK_MAIN();