Skip to content

Commit 4d88c07

Browse files
committed
adding synchronize for the executor along with the overhead example
1 parent 5e86494 commit 4d88c07

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Ginkgo
2+
using Printf
3+
using SparseArrays
4+
5+
# Type alias
6+
const T = Float64
7+
num_iters = 1000000
8+
9+
# print ginkgo library version
10+
version()
11+
12+
# Creates executor for a specific backend
13+
exec = create(:reference)
14+
15+
# testing solver overhead with a 1x1 system
16+
A = spzeros(T, 1, 1); A[1, 1] = 1.0; A = GkoCsr(A, exec)
17+
b = number(NaN, exec)
18+
x = number(T(0.0), exec)
19+
20+
# time solver overhead
21+
solver = GkoIterativeSolver(:cg, A, exec, maxiter = num_iters)
22+
tic = time_ns()
23+
24+
apply!(solver, b, x)
25+
synchronize(exec)
26+
27+
tac = time_ns()
28+
29+
total_ns = tac - tic
30+
total_s = total_ns / 1.0e9
31+
avg_ns = total_ns / num_iters
32+
33+
@printf("Running %d iterations of the CG solver took a total of %.5f seconds.\n", num_iters, total_s)
34+
@printf("\tAverage library overhead: %.2f [nanoseconds / iteration]\n", avg_ns)

src/Ginkgo.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export
7777

7878
# Executor
7979
create,
80-
80+
synchronize,
81+
8182
# CPU executors only
8283
get_num_cores,
8384
get_num_threads_per_core,

src/base/Executor.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ function create(executor_type::Symbol; device_id::Integer = 0, master::GkoCPUExe
187187
end
188188
end
189189

190+
"""
191+
synchronize(executor::GkoExecutor)
192+
193+
Synchronize the given executor. This function blocks until all operations associated with the executor are complete.
194+
"""
195+
function synchronize(executor::GkoExecutor = EXECUTOR[])
196+
API.gko_executor_synchronize(executor.ptr)
197+
return nothing
198+
end
190199

191200
# Getters for all CPU executors
192201
get_num_cores(exec::GkoCPUExecutor) = Int32(API.gko_executor_cpu_get_num_cores(exec.ptr))

0 commit comments

Comments
 (0)