Added some tests have to correct cpupowerdraw

This commit is contained in:
Eduardo Cueto Mendoza 2020-07-02 00:05:25 -06:00
parent 1555daf193
commit 4d42dd52c0
2 changed files with 23 additions and 6 deletions

View File

@ -1,3 +1,15 @@
struct NoNvidiaSMI <: Exception
var::Symbol
end
Base.showerror(io::IO, e::NoNvidiaSMI) = print(io, e.var)
struct NoPowerStat <: Exception
var::Symbol
end
Base.showerror(io::IO, e::NoPowerStat) = print(io, e.var)
""" """
gpupowerdraw()::Float64 gpupowerdraw()::Float64
@ -57,7 +69,7 @@ function gpupowerdraw()
end end
return nogpus, mean(usage), mean(cap) return nogpus, mean(usage), mean(cap)
else else
@info "This computer does not have acces to a GPU passing to CPU and RAM computations" throw(NoNvidiaSMI("there is no nvidia-smi installed")) #@info "This computer does not have acces to a GPU passing to CPU and RAM computations"
end end
end end
@ -68,15 +80,15 @@ end
This function uses the Linux `powerstat` utility to get the average CPU energy cost. This function uses the Linux `powerstat` utility to get the average CPU energy cost.
""" """
function cpupowerdraw() function cpupowerdraw()
cpucommand = `powerstat -R -n -d0`
try try
cpucommand = `powerstat -R -n -d0`
cpu = read(cpucommand, String); cpu = read(cpucommand, String);
cpu = split(cpu,"\n") cpu = split(cpu,"\n")
cpu = cpu[66][60:64] cpu = cpu[66][60:64]
return parse(Float64,cpu) return parse(Float64,cpu)
catch e catch e
@info "powerstat not installed in your computer" @info "powerstat not installed in your computer" #throw(NoPowerStat("there is no powerstat installed"))
end end
end end

View File

@ -1,6 +1,11 @@
using GreenFlux using GreenFlux
using Test using Test
using Flux
@testset "GreenFlux.jl" begin @testset "GreenFlux.jl" begin
# Write your tests here. convol = Conv((15,15),1=>2,tand)
dense = Dense(23,31,gelu)
@test_throws GreenFlux.NoNvidiaSMI avgpowerdraw()
@test_throws GreenFlux.NoPowerStat avgpowerdraw()
@test typeof(avgpowerdraw()) <: Float64
end end