From 4e1dfa873bc064bbff7dab20429888202ca28f56 Mon Sep 17 00:00:00 2001 From: Eduardo Cueto Mendoza Date: Sun, 5 Jul 2020 13:31:10 -0600 Subject: [PATCH] Finished basic testing for functions --- src/neflops/layerflops.jl | 1 + src/power/powerdraw.jl | 38 ++++++++++++++-------------- test/runtests.jl | 53 +++++++++++++++++++++------------------ 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/src/neflops/layerflops.jl b/src/neflops/layerflops.jl index 46bfd6f..2218bb0 100644 --- a/src/neflops/layerflops.jl +++ b/src/neflops/layerflops.jl @@ -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 diff --git a/src/power/powerdraw.jl b/src/power/powerdraw.jl index 4f91624..e12ab4d 100644 --- a/src/power/powerdraw.jl +++ b/src/power/powerdraw.jl @@ -1,19 +1,3 @@ -struct NoNvidiaSMI <: Exception - var::String -end - -struct NoPowerStat <: Exception - var::String -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::NoFree) = print(io, e.var) - """ gpupowerdraw()::Float64 @@ -123,10 +107,26 @@ the number of available gpus. returns the average power consumption in kWh. """ function avgpowerdraw() + g, pg, pc, pr = 0.0, 0.0, 0.0, 0.0 starttime = time() - g, pg, _ = gpupowerdraw() - pc = cpupowerdraw() - pr = rampowerdraw() + try + g, pg, _ = gpupowerdraw() + 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 diff --git a/test/runtests.jl b/test/runtests.jl index c6113b3..f60fa6a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,32 +3,35 @@ using Test using Flux @testset "GreenFlux.jl" begin - #convol = Conv((15,15),1=>2,tand) - #dense = Dense(23,31,gelu) - #maxpoo = MaxPool((12,65)) + convol = Conv((15,15),4=>2,tanh) + dense = Dense(23,31,gelu) + maxpoo = MaxPool((12,65)) # TODO: GlobalMaxPool - #mpool = MeanPool((3,3)) + mpool = MeanPool((3,3)) # TODO: GlobalMeanPool - #dconv = DepthwiseConv((21,21),6=>12,relu) - #ctrans = ConvTranspose((7,7),2=>4,tan) - #cc = CrossCor((2, 2), 1=>16, relu6) - #gr = GRU(4,8) - #lst = LSTM(3,3) - #rn = RNN(3,6) + 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) - #@test_throws GreenFlux.NoNvidiaSMI GreenFlux.gpupowerdraw() - #@test_throws GreenFlux.NoPowerStat GreenFlux.cpupowerdraw() - #@test typeof(GreenFlux.rampowerdraw()) <: Float64 - #@test typeof(avgpowerdraw()) <: Float64 - #@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(maxpoo,(9,9))) == 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(ctrans,(6,6))) == 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(lst,(8,8))) == 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}} + 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