commit
0df63aedcd
|
@ -34,6 +34,7 @@ function layerflops(layer::Dense,input::Tuple)
|
|||
return convert(Float64,((2*Mi*N - M)+bi)*noofopers*Fm), out
|
||||
end
|
||||
|
||||
# TODO: Maxout for more that one layer Maxout
|
||||
function layerflops(layer::Maxout,input::Tuple)
|
||||
i = 0; j = 0; Fm = 1
|
||||
if length(input) == 3
|
||||
|
|
|
@ -5,60 +5,52 @@ The function uses Linux `nvidia-smi` package to sample and get the average elect
|
|||
draw of the GPUs.
|
||||
"""
|
||||
function gpupowerdraw()
|
||||
if has_cuda_gpu()
|
||||
gpucommand = `nvidia-smi`
|
||||
usage = Array{Any}(undef,60)
|
||||
cap = Array{Any}(undef,60)
|
||||
nogpus = 0
|
||||
gpucommand = `nvidia-smi`
|
||||
usage = Array{Any}(undef,60)
|
||||
cap = Array{Any}(undef,60)
|
||||
nogpus = 0
|
||||
|
||||
for count in 1:60
|
||||
smis = Array{Any}[]
|
||||
smiss = Array{Any}[]
|
||||
gpus = Array{Any}[]
|
||||
powerdraw = Array{Float64}[]
|
||||
powercap = Array{Float64}[]
|
||||
|
||||
smi = read(gpucommand, String);
|
||||
smi = split(smi, "\n")
|
||||
for s in smi
|
||||
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)
|
||||
for count in 1:60
|
||||
smis = Array{Any}[]
|
||||
smiss = Array{Any}[]
|
||||
gpus = Array{Any}[]
|
||||
powerdraw = Array{Float64}[]
|
||||
powercap = Array{Float64}[]
|
||||
smi = read(gpucommand, String);
|
||||
smi = split(smi, "\n")
|
||||
for s in smi
|
||||
push!(smis,split(s, " "))
|
||||
end
|
||||
return nogpus, mean(usage), mean(cap)
|
||||
else
|
||||
@info "This computer does not have acces to a GPU passing to CPU and RAM computations"
|
||||
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
|
||||
return nogpus, mean(usage), mean(cap)
|
||||
end
|
||||
|
||||
|
||||
|
@ -69,16 +61,11 @@ This function uses the Linux `powerstat` utility to get the average CPU energy c
|
|||
"""
|
||||
function cpupowerdraw()
|
||||
cpucommand = `powerstat -R -n -d0`
|
||||
try
|
||||
cpu = read(cpucommand, String);
|
||||
cpu = split(cpu,"\n")
|
||||
cpu = cpu[66][60:64]
|
||||
|
||||
return parse(Float64,cpu)
|
||||
catch e
|
||||
@info "powerstat not installed in your computer"
|
||||
end
|
||||
end
|
||||
cpu = read(cpucommand, String);
|
||||
cpu = split(cpu,"\n")
|
||||
cpu = cpu[66][60:64]
|
||||
return parse(Float64,cpu)
|
||||
end
|
||||
|
||||
|
||||
#TODO: further fine tune the model
|
||||
|
@ -120,19 +107,27 @@ the number of available gpus.
|
|||
returns the average power consumption in kWh.
|
||||
"""
|
||||
function avgpowerdraw()
|
||||
if has_cuda_gpu()
|
||||
starttime = time()
|
||||
g, pg, pc, pr = 0.0, 0.0, 0.0, 0.0
|
||||
starttime = time()
|
||||
try
|
||||
g, pg, _ = gpupowerdraw()
|
||||
pc = cpupowerdraw()
|
||||
pr = rampowerdraw()
|
||||
endtime = time()
|
||||
elapsedtime = (endtime - starttime)/3600
|
||||
return 1.58*elapsedtime*(pc + pr + g*pg)/1000
|
||||
else
|
||||
pc = cpupowerdraw()
|
||||
pr = rampowerdraw()
|
||||
endtime = time()
|
||||
elapsedtime = (endtime - starttime)/3600
|
||||
return 1.58*elapsedtime*(pc + pr)/1000
|
||||
catch ex
|
||||
println(ex.msg)
|
||||
return 0.0
|
||||
end
|
||||
try
|
||||
pc = cpupowerdraw()
|
||||
catch ex
|
||||
println(ex.msg)
|
||||
return 0.0
|
||||
end
|
||||
try
|
||||
pr = rampowerdraw()
|
||||
catch ex
|
||||
println(ex.msg)
|
||||
return 0.0
|
||||
end
|
||||
endtime = time()
|
||||
elapsedtime = (endtime - starttime)/3600
|
||||
return 1.58*elapsedtime*(pc + pr + g*pg)/1000
|
||||
end
|
||||
|
|
|
@ -1,6 +1,37 @@
|
|||
using GreenFlux
|
||||
using Test
|
||||
using Flux
|
||||
|
||||
@testset "GreenFlux.jl" begin
|
||||
# Write your tests here.
|
||||
convol = Conv((15,15),4=>2,tanh)
|
||||
dense = Dense(23,31,gelu)
|
||||
maxpoo = MaxPool((12,65))
|
||||
# TODO: GlobalMaxPool
|
||||
mpool = MeanPool((3,3))
|
||||
# TODO: GlobalMeanPool
|
||||
dconv = DepthwiseConv((21,21),6=>12,relu)
|
||||
ctrans = ConvTranspose((7,7),2=>4,identity)
|
||||
cc = CrossCor((2, 2), 1=>16, relu6)
|
||||
gr = GRU(4,8)
|
||||
lst = LSTM(3,3)
|
||||
rn = RNN(3,6)
|
||||
#maxo = Maxout(()->Dense(35, 27), 4)
|
||||
maxo = Maxout((12,12))
|
||||
@test_throws Base.IOError GreenFlux.gpupowerdraw()
|
||||
@test_throws Base.IOError GreenFlux.cpupowerdraw()
|
||||
@test_throws Base.IOError GreenFlux.rampowerdraw()
|
||||
if Sys.islinux()
|
||||
@test typeof(avgpowerdraw()) <: Float64
|
||||
end
|
||||
@test GreenFlux.layerflops(convol,(28,28)) == (354368.0, (14, 14, 2))
|
||||
@test GreenFlux.layerflops(dense,(4,4)) == (2304.0, (31, 1))
|
||||
@test GreenFlux.layerflops(maxpoo,(100,100)) == (6240.0, (8, 1))
|
||||
@test GreenFlux.layerflops(mpool,(8,8)) == (36.0, (2, 2))
|
||||
@test GreenFlux.layerflops(dconv,(30,30)) == (177600.0, (10, 10, 6))
|
||||
@test GreenFlux.layerflops(ctrans,(6,6)) == (56736.0, (12, 12, 2))
|
||||
@test GreenFlux.layerflops(cc,(3,3)) == (224.0, (2, 2, 16))
|
||||
@test GreenFlux.layerflops(gr,(77,77)) == (6099.0, (24, 1))
|
||||
@test GreenFlux.layerflops(lst,(8,8)) == (1968.0, (12, 1))
|
||||
@test GreenFlux.layerflops(rn,(4,4)) == (546.0, (6, 1))
|
||||
@test GreenFlux.layerflops(maxo,(5,5)) == (3600.0, (5, 1))
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue