{
"cells": [
{
"cell_type": "markdown",
"id": "bcc2edf8-9389-472c-b71e-abd845c6ff3d",
"metadata": {},
"source": [
"# Timing"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "00ab9b6a-91d9-4c8a-8816-34119b7ff704",
"metadata": {},
"outputs": [],
"source": [
"using NBInclude;\n",
"using Plots;\n",
"using Statistics;\n",
"@nbinclude(\"GPUFilterBanks.ipynb\");\n",
"@nbinclude(\"AudioTools.ipynb\");"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "235f4edf-0b78-45dd-b06f-9cf7ef1c9ee7",
"metadata": {},
"outputs": [],
"source": [
"x = load(\"three_minute_warning.wav\");\n",
"fs = round(Int,x.samplerate);\n",
"x = Float32.(x[:]);"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e3673638-be3d-4491-adc5-e8395c088736",
"metadata": {},
"outputs": [],
"source": [
"N_list = 2 .^ ([15,18,22,26]);"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "25d53054-7326-437c-afd0-95c3d45a4482",
"metadata": {},
"outputs": [],
"source": [
"num_octaves = 10;\n",
"\n",
"filters = [\n",
" WT.makeqmfpair(wavelet(WT.haar)),\n",
" WT.makereverseqmfpair(wavelet(WT.haar))\n",
"];\n",
"LA = tensor(Float32.(filters[1][1]));\n",
"HA = tensor(Float32.(filters[1][2]));\n",
"LS = tensor(Float32.(filters[2][1]));\n",
"HS = tensor(Float32.(filters[2][2]));"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "fe3fa52c-ba6b-443a-81c8-ee71ec8b536a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4×2 Matrix{Float64}:\n",
" 0.00816263 0.0123718\n",
" 0.0106195 0.0186567\n",
" 0.0230988 0.0673673\n",
" 0.608797 1.77462"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"n_trials = 5;\n",
"x_i = nothing\n",
"y = nothing\n",
"elapsed_time = zeros(length(N_list),2,n_trials);\n",
"for (N,i_N) ∈ zip(N_list,1:length(N_list)), trial ∈ 1:n_trials\n",
" x_i = [tensor(x[1:N])]\n",
" elapsed_time[i_N,1,trial] = Base.@elapsed y = analysis_filterbank(x_i,LA,HA)\n",
" elapsed_time[i_N,2,trial] = Base.@elapsed synthesis_filterbank(y,LS,HS)\n",
" y = nothing\n",
"end\n",
"elapsed_time = median(elapsed_time,dims=3)[:,:]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "69418c00-ec6c-46be-a4ee-5e98225ba36a",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h = plot(N_list,elapsed_time,\n",
" seriestype = :line,\n",
" marker = :d,\n",
" xaxis=:log, yaxis=:log,\n",
" labels=[\"Analysis Filter Bank\" \"Synthesis Filter Bank\"],\n",
" size=(700,350),\n",
" xlim=(8e3,1e8),\n",
" ylim=(1e-3,5),\n",
" legend=:topleft,\n",
" ylab=\"Elasped Time [seconds]\",xlab=\"Input Size [samples]\",\n",
" margin=5Plots.mm,\n",
")\n",
"annotate!(h, \n",
" 2^15 , 4e-3 ,\n",
" text(\"one second of speech\",:black, :center, 10))\n",
"annotate!(h, \n",
" 2^18 , 5e-2 ,\n",
" text(\"five seconds of music\",:black, :center, 10))\n",
"annotate!(h, \n",
" 2^22 , 1e-2 ,\n",
" text(\"one minute of music\",:black, :center, 10))\n",
"annotate!(h, \n",
" 2^(25.8) , 4 ,\n",
" text(\"one hour of film\",:black, :center, 10))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "6fe1824b-bfa3-4786-9202-d9bb7e646ad4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"import librosa\n",
"import numpy as np\n",
"import time\n",
"y,sr = librosa.load(\"three_minute_warning.wav\")\n",
"for N in [2**15,2**18,2**22,2**26]:\n",
" t1 = time.time()\n",
" x_i = y[0:N]\n",
" S = librosa.feature.melspectrogram(\n",
" y=x_i,\n",
" sr=sr,\n",
" n_fft=2^20,\n",
" hop_length=32,\n",
" n_mels=512,\n",
" )\n",
" t2 = time.time()\n",
" print(t2-t1,\"\\n\")\n",
" \n",
" t1 = time.time()\n",
" y_rec = librosa.feature.inverse.mel_to_audio(\n",
" M=S,\n",
" sr=sr,\n",
" n_fft=2^20,\n",
" hop_length=32,\n",
" )\n",
" t2 = time.time()\n",
" print(t2-t1,\"\\n\")"
]
}
],
"source": [
";cat seq_time.py"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "24d891ab-55f5-4ccb-8503-d2f44d98c3db",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.017119169235229492 \n",
"\n",
"0.09121012687683105 \n",
"\n",
"0.016405582427978516 \n",
"\n",
"0.6389076709747314 \n",
"\n",
"0.21744465827941895 \n",
"\n",
"10.451849699020386 \n",
"\n",
"1.606813669204712 \n",
"\n",
"90.8090467453003 \n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/lib/python3.9/dist-packages/librosa/filters.py:238: UserWarning: Empty filters detected in mel frequency basis. Some channels will produce empty responses. Try increasing your sampling rate (and fmax) or reducing n_mels.\n",
" warnings.warn(\n"
]
}
],
"source": [
";taskset --cpu-list 0 python3 seq_time.py"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "34ef99b7-4ea4-4492-8973-7e7b7652af23",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4×2 adjoint(::Matrix{Float64}) with eltype Float64:\n",
" 0.0171192 0.0912101\n",
" 0.0164056 0.638908\n",
" 0.217445 10.4518\n",
" 1.60681 90.809"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cpu_time = reshape([\n",
" 0.017119169235229492 \n",
" 0.09121012687683105 \n",
" 0.016405582427978516 \n",
" 0.6389076709747314 \n",
" 0.21744465827941895 \n",
" 10.451849699020386 \n",
" 1.606813669204712 \n",
" 90.8090467453003 \n",
"],(2,4))'"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "46894a73-c325-4f4e-828c-10886dc91c8a",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h = plot(N_list,cpu_time./elapsed_time,\n",
" seriestype = :line,\n",
" marker = :d,\n",
" xaxis=:log, yaxis=:log,\n",
" labels=[\"Transform\" \"Inverse Transform\"],\n",
" size=(700,350),\n",
" ylim=(0.9,200),\n",
" xlim=(8e3,1e8),\n",
" legend=:topleft,\n",
" ylab=\"Speedup\",xlab=\"Input Size [samples]\",\n",
" margin=5Plots.mm,\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.7.0-beta3",
"language": "julia",
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}