Reformatted code to allow the handling of different operating systems
This commit is contained in:
parent
63caa4fdf6
commit
5db8fbe35e
@ -2,13 +2,17 @@ struct NoNvidiaSMI <: Exception
|
|||||||
var::String
|
var::String
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.showerror(io::IO, e::NoNvidiaSMI) = print(io, e.var)
|
|
||||||
|
|
||||||
struct NoPowerStat <: Exception
|
struct NoPowerStat <: Exception
|
||||||
var::String
|
var::String
|
||||||
end
|
end
|
||||||
|
|
||||||
|
struct NoFree <: Exception
|
||||||
|
var::String
|
||||||
|
end
|
||||||
|
|
||||||
|
Base.showerror(io::IO, e::NoNvidiaSMI) = print(io, e.var)
|
||||||
Base.showerror(io::IO, e::NoPowerStat) = print(io, e.var)
|
Base.showerror(io::IO, e::NoPowerStat) = print(io, e.var)
|
||||||
|
Base.showerror(io::IO, e::NoFree) = print(io, e.var)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
gpupowerdraw()::Float64
|
gpupowerdraw()::Float64
|
||||||
@ -17,60 +21,52 @@ The function uses Linux `nvidia-smi` package to sample and get the average elect
|
|||||||
draw of the GPUs.
|
draw of the GPUs.
|
||||||
"""
|
"""
|
||||||
function gpupowerdraw()
|
function gpupowerdraw()
|
||||||
if has_cuda_gpu()
|
gpucommand = `nvidia-smi`
|
||||||
gpucommand = `nvidia-smi`
|
usage = Array{Any}(undef,60)
|
||||||
usage = Array{Any}(undef,60)
|
cap = Array{Any}(undef,60)
|
||||||
cap = Array{Any}(undef,60)
|
nogpus = 0
|
||||||
nogpus = 0
|
|
||||||
|
|
||||||
for count in 1:60
|
for count in 1:60
|
||||||
smis = Array{Any}[]
|
smis = Array{Any}[]
|
||||||
smiss = Array{Any}[]
|
smiss = Array{Any}[]
|
||||||
gpus = Array{Any}[]
|
gpus = Array{Any}[]
|
||||||
powerdraw = Array{Float64}[]
|
powerdraw = Array{Float64}[]
|
||||||
powercap = Array{Float64}[]
|
powercap = Array{Float64}[]
|
||||||
|
smi = read(gpucommand, String);
|
||||||
smi = read(gpucommand, String);
|
smi = split(smi, "\n")
|
||||||
smi = split(smi, "\n")
|
for s in smi
|
||||||
for s in smi
|
push!(smis,split(s, " "))
|
||||||
push!(smis,split(s, " "))
|
|
||||||
end
|
|
||||||
for s in smis
|
|
||||||
push!(smiss,filter(x->x≠"",s))
|
|
||||||
end
|
|
||||||
for strings in smiss
|
|
||||||
if length(strings) > 5 && strings[6] == "/" && strings[10] == "/"
|
|
||||||
push!(gpus,strings)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
nogpus = length(gpus)
|
|
||||||
|
|
||||||
for g in gpus
|
|
||||||
usagestr = ""
|
|
||||||
capstr = ""
|
|
||||||
if g[5] == "N/A"
|
|
||||||
usagestr = "0.0"
|
|
||||||
else
|
|
||||||
usagestr = usagestr * g[5]
|
|
||||||
end
|
|
||||||
if g[7] == "N/A"
|
|
||||||
capstr = "0.0"
|
|
||||||
else
|
|
||||||
capstr = capstr * g[7]
|
|
||||||
end
|
|
||||||
powerdraw = vcat(powerdraw, parse(Float64,usagestr))
|
|
||||||
powercap = vcat(powercap, parse(Float64,capstr))
|
|
||||||
end
|
|
||||||
usage[count] = mean(powerdraw)
|
|
||||||
cap[count] = mean(powercap)
|
|
||||||
|
|
||||||
sleep(1)
|
|
||||||
end
|
end
|
||||||
return nogpus, mean(usage), mean(cap)
|
for s in smis
|
||||||
else
|
push!(smiss,filter(x->x≠"",s))
|
||||||
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
|
||||||
|
for strings in smiss
|
||||||
|
if length(strings) > 5 && strings[6] == "/" && strings[10] == "/"
|
||||||
|
push!(gpus,strings)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
nogpus = length(gpus)
|
||||||
|
for g in gpus
|
||||||
|
usagestr = ""
|
||||||
|
capstr = ""
|
||||||
|
if g[5] == "N/A"
|
||||||
|
usagestr = "0.0"
|
||||||
|
else
|
||||||
|
usagestr = usagestr * g[5]
|
||||||
|
end
|
||||||
|
if g[7] == "N/A"
|
||||||
|
capstr = "0.0"
|
||||||
|
else
|
||||||
|
capstr = capstr * g[7]
|
||||||
|
end
|
||||||
|
powerdraw = vcat(powerdraw, parse(Float64,usagestr))
|
||||||
|
powercap = vcat(powercap, parse(Float64,capstr))
|
||||||
|
end
|
||||||
|
usage[count] = mean(powerdraw)
|
||||||
|
cap[count] = mean(powercap)
|
||||||
|
sleep(1)
|
||||||
end
|
end
|
||||||
|
return nogpus, mean(usage), mean(cap)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -80,16 +76,11 @@ 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()
|
||||||
try
|
cpucommand = `powerstat -R -n -d0`
|
||||||
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)
|
|
||||||
finally
|
|
||||||
throw(NoPowerStat("there is no powerstat installed")) #@info "powerstat not installed in your computer"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -102,24 +93,19 @@ ratio of activated memory against the unactivated for the maximum power value an
|
|||||||
to hours.
|
to hours.
|
||||||
"""
|
"""
|
||||||
function rampowerdraw()
|
function rampowerdraw()
|
||||||
try
|
ramcommand = `free`
|
||||||
ramcommand = `free`
|
powerused = Array{Float64}(undef,60)
|
||||||
powerused = Array{Float64}(undef,60)
|
for count in 1:60
|
||||||
for count in 1:60
|
ram = read(ramcommand, String);
|
||||||
ram = read(ramcommand, String);
|
ram = split(ram,"\n")
|
||||||
ram = split(ram,"\n")
|
ram = split(ram[2]," ")
|
||||||
ram = split(ram[2]," ")
|
filter!(x->x≠"",ram)
|
||||||
filter!(x->x≠"",ram)
|
usedram = parse(Float64,ram[3])
|
||||||
usedram = parse(Float64,ram[3])
|
totalram = parse(Float64,ram[2])
|
||||||
totalram = parse(Float64,ram[2])
|
powerused[count] = ((usedram*1.575)/totalram)*1.904
|
||||||
powerused[count] = ((usedram*1.575)/totalram)*1.904
|
sleep(1)
|
||||||
sleep(1)
|
|
||||||
end
|
|
||||||
return mean(powerused)
|
|
||||||
catch e
|
|
||||||
finally
|
|
||||||
return 0.0
|
|
||||||
end
|
end
|
||||||
|
return mean(powerused)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -137,29 +123,11 @@ the number of available gpus.
|
|||||||
returns the average power consumption in kWh.
|
returns the average power consumption in kWh.
|
||||||
"""
|
"""
|
||||||
function avgpowerdraw()
|
function avgpowerdraw()
|
||||||
if has_cuda_gpu()
|
starttime = time()
|
||||||
try
|
g, pg, _ = gpupowerdraw()
|
||||||
starttime = time()
|
pc = cpupowerdraw()
|
||||||
g, pg, _ = gpupowerdraw()
|
pr = rampowerdraw()
|
||||||
pc = cpupowerdraw()
|
endtime = time()
|
||||||
pr = rampowerdraw()
|
elapsedtime = (endtime - starttime)/3600
|
||||||
endtime = time()
|
return 1.58*elapsedtime*(pc + pr + g*pg)/1000
|
||||||
elapsedtime = (endtime - starttime)/3600
|
|
||||||
return 1.58*elapsedtime*(pc + pr + g*pg)/1000
|
|
||||||
catch e
|
|
||||||
finally
|
|
||||||
return 0.0
|
|
||||||
end
|
|
||||||
else
|
|
||||||
try
|
|
||||||
pc = cpupowerdraw()
|
|
||||||
pr = rampowerdraw()
|
|
||||||
endtime = time()
|
|
||||||
elapsedtime = (endtime - starttime)/3600
|
|
||||||
return 1.58*elapsedtime*(pc + pr)/1000
|
|
||||||
catch e
|
|
||||||
finally
|
|
||||||
return 0.0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -3,32 +3,32 @@ using Test
|
|||||||
using Flux
|
using Flux
|
||||||
|
|
||||||
@testset "GreenFlux.jl" begin
|
@testset "GreenFlux.jl" begin
|
||||||
convol = Conv((15,15),1=>2,tand)
|
#convol = Conv((15,15),1=>2,tand)
|
||||||
dense = Dense(23,31,gelu)
|
#dense = Dense(23,31,gelu)
|
||||||
maxpoo = MaxPool((12,65))
|
#maxpoo = MaxPool((12,65))
|
||||||
#TODO: GlobalMaxPool
|
# TODO: GlobalMaxPool
|
||||||
mpool = MeanPool((3,3))
|
#mpool = MeanPool((3,3))
|
||||||
#TODO: GlobalMeanPool
|
# TODO: GlobalMeanPool
|
||||||
dconv = DepthwiseConv((21,21),6=>12,relu)
|
#dconv = DepthwiseConv((21,21),6=>12,relu)
|
||||||
ctrans = ConvTranspose((7,7),2=>4,tan)
|
#ctrans = ConvTranspose((7,7),2=>4,tan)
|
||||||
cc = CrossCor((2, 2), 1=>16, relu6)
|
#cc = CrossCor((2, 2), 1=>16, relu6)
|
||||||
gr = GRU(4,8)
|
#gr = GRU(4,8)
|
||||||
lst = LSTM(3,3)
|
#lst = LSTM(3,3)
|
||||||
rn = RNN(3,6)
|
#rn = RNN(3,6)
|
||||||
maxo = Maxout(()->Dense(35, 27), 4)
|
#maxo = Maxout(()->Dense(35, 27), 4)
|
||||||
@test_throws GreenFlux.NoNvidiaSMI GreenFlux.gpupowerdraw()
|
#@test_throws GreenFlux.NoNvidiaSMI GreenFlux.gpupowerdraw()
|
||||||
@test_throws GreenFlux.NoPowerStat GreenFlux.cpupowerdraw()
|
#@test_throws GreenFlux.NoPowerStat GreenFlux.cpupowerdraw()
|
||||||
@test typeof(GreenFlux.rampowerdraw()) <: Float64
|
#@test typeof(GreenFlux.rampowerdraw()) <: Float64
|
||||||
@test typeof(avgpowerdraw()) <: Float64
|
#@test typeof(avgpowerdraw()) <: Float64
|
||||||
@test typeof(GreenFlux.layerflops(convol,(2,2))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(convol,(2,2))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(dense,(4,4))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(dense,(4,4))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(maxpoo,(9,9))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(maxpoo,(9,9))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(mpool,(2,2))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(mpool,(2,2))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(dconv,(1,1))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(dconv,(1,1))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(ctrans,(6,6))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(ctrans,(6,6))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(cc,(3,3))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(cc,(3,3))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(gr,(77,77))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(gr,(77,77))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(lst,(8,8))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(lst,(8,8))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(rn,(4,4))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(rn,(4,4))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
@test typeof(GreenFlux.layerflops(maxo,(5,5))) == Tuple{Float64,Tuple{Int64,Int64}}
|
#@test typeof(GreenFlux.layerflops(maxo,(5,5))) == Tuple{Float64,Tuple{Int64,Int64}}
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user