From 9b30ed5e6656152e9aaaacda4919e35630ce75f4 Mon Sep 17 00:00:00 2001 From: Jerry Ling Date: Thu, 24 Mar 2022 14:15:13 -0400 Subject: [PATCH] remove timed enable multi-threading (#14) * remove TimerOutputs --- Project.toml | 4 +-- src/ONNXRunTime.jl | 3 -- src/capi.jl | 13 +++---- src/highlevel.jl | 90 ++++++++++++++++++++-------------------------- 4 files changed, 44 insertions(+), 66 deletions(-) diff --git a/Project.toml b/Project.toml index 59c8480..699f809 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ONNXRunTime" uuid = "e034b28e-924e-41b2-b98f-d2bbeb830c6a" authors = ["Jan Weidner and contributors"] -version = "0.2.3" +version = "0.3.0" [deps] ArgCheck = "dce04be8-c92d-5529-be00-80e4d2c0e197" @@ -12,7 +12,6 @@ LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Requires = "ae029012-a4dd-5104-9daa-d747884805df" -TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" [compat] ArgCheck = "2" @@ -20,7 +19,6 @@ CEnum = "0.4" DataStructures = "0.18" DocStringExtensions = "0.8" Requires = "1" -TimerOutputs = "0.5" julia = "1.6" [extras] diff --git a/src/ONNXRunTime.jl b/src/ONNXRunTime.jl index d2f5e6e..ec2451f 100644 --- a/src/ONNXRunTime.jl +++ b/src/ONNXRunTime.jl @@ -1,8 +1,5 @@ module ONNXRunTime using Requires:@require -import TimerOutputs - -const TIMER = TimerOutputs.TimerOutput() function _perm(arr::AbstractArray{T,N}) where {T,N} ntuple(i->N+1-i, N) diff --git a/src/capi.jl b/src/capi.jl index 8b29dc6..4e79dd7 100644 --- a/src/capi.jl +++ b/src/capi.jl @@ -5,8 +5,7 @@ This module closely follows the offical onnxruntime [C-API](https://github.com/m See [here](https://github.com/microsoft/onnxruntime-inference-examples/blob/d031f879c9a8d33c8b7dc52c5bc65fe8b9e3960d/c_cxx/fns_candy_style_transfer/fns_candy_style_transfer.c) for a C code example. """ module CAPI -using ONNXRunTime: TIMER, reversedims_lazy -using TimerOutputs: @timeit +using ONNXRunTime: reversedims_lazy using DocStringExtensions using Libdl @@ -901,14 +900,10 @@ end $TYPEDSIGNATURES """ -@timeit TIMER function GetTensorMutableData(api::OrtApi, tensor::OrtValue)::AbstractArray +function GetTensorMutableData(api::OrtApi, tensor::OrtValue)::AbstractArray GC.@preserve tensor begin - @timeit TIMER "unsafe_GetTensorMutableData" begin - data_owned_by_tensor::PermutedDimsArray = unsafe_GetTensorMutableData(api, tensor) - end - @timeit TIMER "copy" begin - reversedims_lazy(copy(parent(data_owned_by_tensor))) - end + data_owned_by_tensor::PermutedDimsArray = unsafe_GetTensorMutableData(api, tensor) + reversedims_lazy(copy(parent(data_owned_by_tensor))) end end diff --git a/src/highlevel.jl b/src/highlevel.jl index a096e59..dfa43f1 100644 --- a/src/highlevel.jl +++ b/src/highlevel.jl @@ -2,7 +2,6 @@ using ArgCheck using LazyArtifacts using DataStructures: OrderedDict using DocStringExtensions -using TimerOutputs: @timeit, TimerOutput ################################################################################ ##### testdatapath ################################################################################ @@ -29,7 +28,6 @@ struct InferenceSession allocator::OrtAllocator _input_names::Vector{String} _output_names::Vector{String} - timer::TimerOutput end function Base.show(io::IO, o::InferenceSession) print(io, @@ -60,8 +58,8 @@ end $TYPEDSIGNATURES """ function load_inference(path::AbstractString; execution_provider::Symbol=:cpu, - envname::AbstractString="defaultenv", timer=TIMER, - )::InferenceSession + envname::AbstractString="defaultenv", + )::InferenceSession api = GetApi(;execution_provider) env = CreateEnv(api, name=envname) if execution_provider === :cpu @@ -87,17 +85,14 @@ function load_inference(path::AbstractString; execution_provider::Symbol=:cpu, @check allunique(_input_names) @check allunique(_output_names) return InferenceSession(api, execution_provider, session, meminfo, allocator, - _input_names, - _output_names, - timer, - ) + _input_names, + _output_names, + ) end -@timeit o.timer function make_input_tensor(o::InferenceSession, inputs, key) +function make_input_tensor(o::InferenceSession, inputs, key) arr = inputs[keytype(inputs)(key)] - @timeit o.timer "clayout" begin - cstorage = vec(reversedims(arr)::Array) - end + cstorage = vec(reversedims(arr)::Array) CreateTensorWithDataAsOrtValue(o.api, o.meminfo, cstorage, size(arr)) end @@ -136,46 +131,39 @@ be a `NamedTuple` or an `AbstractDict`. Optionally `output_names` can be passed. In this case only the outputs whose name is contained in `output_names` are computed. """ function (o::InferenceSession)( - inputs, - output_names=nothing - ) - timer = o.timer - @timeit timer "pre CAPI.Run" begin - if output_names === nothing - output_names = @__MODULE__().output_names(o) - end - @argcheck o.execution_provider in EXECUTION_PROVIDERS - @argcheck eltype(output_names) <: Union{AbstractString, Symbol} - @argcheck keytype(inputs) <: Union{AbstractString, Symbol} - expected_input_names = ONNXRunTime.input_names(o) - for key in keys(inputs) - if !(String(key) in expected_input_names) - msg = """ - Invalid input name. - Expected: $(expected_input_names) - Got: $(key) - """ - throw(ArgumentError(msg)) - end - end - expected_output_names = ONNXRunTime.output_names(o) - for name in output_names - if !(String(name) in expected_output_names) - msg = """ - Invalid output name. - Expected: $(expected_output_names) - Got: $(name) - """ - throw(ArgumentError(msg)) - end - end - inp_names, input_tensors = prepare_inputs(o, inputs) - run_options = nothing + inputs, + output_names=nothing + ) + if output_names === nothing + output_names = @__MODULE__().output_names(o) end - @timeit timer "CAPI.Run" begin - output_tensors = Run(o.api, o.session, run_options, inp_names, input_tensors, output_names) + @argcheck o.execution_provider in EXECUTION_PROVIDERS + @argcheck eltype(output_names) <: Union{AbstractString, Symbol} + @argcheck keytype(inputs) <: Union{AbstractString, Symbol} + expected_input_names = ONNXRunTime.input_names(o) + for key in keys(inputs) + if !(String(key) in expected_input_names) + msg = """ + Invalid input name. + Expected: $(expected_input_names) + Got: $(key) + """ + throw(ArgumentError(msg)) + end end - @timeit timer "post CAPI.Run" begin - make_output(o, inputs, output_names, output_tensors) + expected_output_names = ONNXRunTime.output_names(o) + for name in output_names + if !(String(name) in expected_output_names) + msg = """ + Invalid output name. + Expected: $(expected_output_names) + Got: $(name) + """ + throw(ArgumentError(msg)) + end end + inp_names, input_tensors = prepare_inputs(o, inputs) + run_options = nothing + output_tensors = Run(o.api, o.session, run_options, inp_names, input_tensors, output_names) + make_output(o, inputs, output_names, output_tensors) end