\hypertarget{classnntrainer_1_1MemoryPool}{}\doxysection{nntrainer\+::Memory\+Pool Class Reference}
\label{classnntrainer_1_1MemoryPool}\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}}


Memory Pool provides a common pool for all the tensor memory.  




{\ttfamily \#include $<$memory\+\_\+pool.\+h$>$}



Inheritance diagram for nntrainer\+::Memory\+Pool\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=208pt]{classnntrainer_1_1MemoryPool__inherit__graph}
\end{center}
\end{figure}
\doxysubsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\hyperlink{classnntrainer_1_1MemoryPool_a01d476448758d7757d448595e5593a22}{Memory\+Pool}} ()
\begin{DoxyCompactList}\small\item\em \mbox{\hyperlink{classnntrainer_1_1MemoryPool}{Memory\+Pool}} default constructor. \end{DoxyCompactList}\item 
virtual \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a820c675f66ff492717ca2e677cb0039b}{$\sim$\+Memory\+Pool}} ()
\begin{DoxyCompactList}\small\item\em \mbox{\hyperlink{classnntrainer_1_1MemoryPool}{Memory\+Pool}} destructor. \end{DoxyCompactList}\item 
virtual unsigned int \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a88bbb4aefec3b4d2bacf46f6444780da}{request\+Memory}} (size\+\_\+t bytes, unsigned int start\+\_\+time, unsigned int end\+\_\+time, std\+::vector$<$ unsigned int $>$ exec\+\_\+order=std\+::vector$<$ unsigned int $>$(), \mbox{\hyperlink{namespacenntrainer_a7bd666a3854202ea94feb44a15ad622d}{Tensor\+Lifespan}} lifespan=\mbox{\hyperlink{namespacenntrainer_a7bd666a3854202ea94feb44a15ad622daa9e0b1de0ff7353f28b66401c4d303bc}{Tensor\+Lifespan\+::\+M\+A\+X\+\_\+\+L\+I\+F\+E\+S\+P\+AN}}, bool is\+\_\+wgrad=false)
\begin{DoxyCompactList}\small\item\em Request Memory from memory pool. \end{DoxyCompactList}\item 
double \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a0aeca99e88a00fee9531ce9c53995789}{plan\+Layout}} (const \mbox{\hyperlink{classnntrainer_1_1MemoryPlanner}{Memory\+Planner}} \&planner)
\begin{DoxyCompactList}\small\item\em Plan the layout with memory planner. \end{DoxyCompactList}\item 
virtual void \mbox{\hyperlink{classnntrainer_1_1MemoryPool_aed676f545b43586c8677eba8bca1db5d}{allocate}} ()
\begin{DoxyCompactList}\small\item\em Do the allocation of memory. \end{DoxyCompactList}\item 
virtual std\+::shared\+\_\+ptr$<$ \mbox{\hyperlink{classnntrainer_1_1MemoryData}{Memory\+Data}}$<$ float $>$ $>$ \mbox{\hyperlink{classnntrainer_1_1MemoryPool_ae8b04f1e5733228356efb3ff22420f42}{get\+Memory}} (unsigned int idx)
\begin{DoxyCompactList}\small\item\em Get the allocated memory. \end{DoxyCompactList}\item 
virtual void \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a3b4875203c72f40ed7c9c2138199d14b}{deallocate}} ()
\begin{DoxyCompactList}\small\item\em Free all the allocated memory. \end{DoxyCompactList}\item 
size\+\_\+t \mbox{\hyperlink{classnntrainer_1_1MemoryPool_ab3e19f0fb2f54084fe29090eeee2213a}{size}} ()
\begin{DoxyCompactList}\small\item\em Get the maximum real memory requirement. \end{DoxyCompactList}\item 
size\+\_\+t \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a85064c5622fd9b897984740b241486e8}{min\+Memory\+Requirement}} ()
\begin{DoxyCompactList}\small\item\em Get the minimum theoretical memory requirement. \end{DoxyCompactList}\item 
virtual void \mbox{\hyperlink{classnntrainer_1_1MemoryPool_acc48284c1b407129f2b90d4b8f4bafab}{clear}} ()
\begin{DoxyCompactList}\small\item\em Clear the memory pool. \end{DoxyCompactList}\item 
virtual bool \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a02b04bf079aae50660bb1bc15397a3dc}{is\+Allocated}} () const
\begin{DoxyCompactList}\small\item\em Is the memory pool allocated. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Protected Member Functions}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a9b48a46c9380f70129d7cdc8537fe023}\label{classnntrainer_1_1MemoryPool_a9b48a46c9380f70129d7cdc8537fe023}} 
std\+::vector$<$ size\+\_\+t $>$ \& \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a9b48a46c9380f70129d7cdc8537fe023}{get\+Memory\+Offset}} ()
\begin{DoxyCompactList}\small\item\em Get memory offset. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a887c4830d425a0392a56fc2bf0370aeb}\label{classnntrainer_1_1MemoryPool_a887c4830d425a0392a56fc2bf0370aeb}} 
std\+::vector$<$ size\+\_\+t $>$ \& \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a887c4830d425a0392a56fc2bf0370aeb}{get\+Memory\+Size}} ()
\begin{DoxyCompactList}\small\item\em Get memory size. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a8222b7586b25754df4f776a712c41884}\label{classnntrainer_1_1MemoryPool_a8222b7586b25754df4f776a712c41884}} 
std\+::vector$<$ std\+::vector$<$ unsigned int $>$ $>$ \& \mbox{\hyperlink{classnntrainer_1_1MemoryPool_a8222b7586b25754df4f776a712c41884}{get\+Memory\+Exec\+Order}} ()
\begin{DoxyCompactList}\small\item\em Get memory execution order. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
Memory Pool provides a common pool for all the tensor memory. 

Definition at line 36 of file memory\+\_\+pool.\+h.



\doxysubsection{Constructor \& Destructor Documentation}
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a01d476448758d7757d448595e5593a22}\label{classnntrainer_1_1MemoryPool_a01d476448758d7757d448595e5593a22}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!MemoryPool@{MemoryPool}}
\index{MemoryPool@{MemoryPool}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{MemoryPool()}{MemoryPool()}}
{\footnotesize\ttfamily nntrainer\+::\+Memory\+Pool\+::\+Memory\+Pool (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [explicit]}}



\mbox{\hyperlink{classnntrainer_1_1MemoryPool}{Memory\+Pool}} default constructor. 



Definition at line 42 of file memory\+\_\+pool.\+h.

\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a820c675f66ff492717ca2e677cb0039b}\label{classnntrainer_1_1MemoryPool_a820c675f66ff492717ca2e677cb0039b}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!````~MemoryPool@{$\sim$MemoryPool}}
\index{````~MemoryPool@{$\sim$MemoryPool}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{$\sim$MemoryPool()}{~MemoryPool()}}
{\footnotesize\ttfamily virtual nntrainer\+::\+Memory\+Pool\+::$\sim$\+Memory\+Pool (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [virtual]}}



\mbox{\hyperlink{classnntrainer_1_1MemoryPool}{Memory\+Pool}} destructor. 



Definition at line 52 of file memory\+\_\+pool.\+h.

Here is the call graph for this function\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classnntrainer_1_1MemoryPool_a820c675f66ff492717ca2e677cb0039b_cgraph}
\end{center}
\end{figure}


\doxysubsection{Member Function Documentation}
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_aed676f545b43586c8677eba8bca1db5d}\label{classnntrainer_1_1MemoryPool_aed676f545b43586c8677eba8bca1db5d}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!allocate@{allocate}}
\index{allocate@{allocate}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{allocate()}{allocate()}}
{\footnotesize\ttfamily void nntrainer\+::\+Memory\+Pool\+::allocate (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



Do the allocation of memory. 



Reimplemented in \mbox{\hyperlink{classnntrainer_1_1CachePool_ae61d8105bd4b11faa90d70af70938e9f}{nntrainer\+::\+Cache\+Pool}}.



Definition at line 91 of file memory\+\_\+pool.\+cpp.

\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_acc48284c1b407129f2b90d4b8f4bafab}\label{classnntrainer_1_1MemoryPool_acc48284c1b407129f2b90d4b8f4bafab}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!clear@{clear}}
\index{clear@{clear}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{clear()}{clear()}}
{\footnotesize\ttfamily void nntrainer\+::\+Memory\+Pool\+::clear (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



Clear the memory pool. 



Reimplemented in \mbox{\hyperlink{classnntrainer_1_1CachePool_a231a548288691114fb2dde11dc0cb4f2}{nntrainer\+::\+Cache\+Pool}}.



Definition at line 317 of file memory\+\_\+pool.\+cpp.

Here is the caller graph for this function\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classnntrainer_1_1MemoryPool_acc48284c1b407129f2b90d4b8f4bafab_icgraph}
\end{center}
\end{figure}
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a3b4875203c72f40ed7c9c2138199d14b}\label{classnntrainer_1_1MemoryPool_a3b4875203c72f40ed7c9c2138199d14b}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!deallocate@{deallocate}}
\index{deallocate@{deallocate}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{deallocate()}{deallocate()}}
{\footnotesize\ttfamily void nntrainer\+::\+Memory\+Pool\+::deallocate (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



Free all the allocated memory. 



Reimplemented in \mbox{\hyperlink{classnntrainer_1_1CachePool_a8bd8a7c31e17ce54e7e0c7052eda1e13}{nntrainer\+::\+Cache\+Pool}}.



Definition at line 130 of file memory\+\_\+pool.\+cpp.

Here is the caller graph for this function\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classnntrainer_1_1MemoryPool_a3b4875203c72f40ed7c9c2138199d14b_icgraph}
\end{center}
\end{figure}
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_ae8b04f1e5733228356efb3ff22420f42}\label{classnntrainer_1_1MemoryPool_ae8b04f1e5733228356efb3ff22420f42}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!getMemory@{getMemory}}
\index{getMemory@{getMemory}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{getMemory()}{getMemory()}}
{\footnotesize\ttfamily std\+::shared\+\_\+ptr$<$ \mbox{\hyperlink{classnntrainer_1_1MemoryData}{Memory\+Data}}$<$ float $>$ $>$ nntrainer\+::\+Memory\+Pool\+::get\+Memory (\begin{DoxyParamCaption}\item[{unsigned int}]{idx }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



Get the allocated memory. 


\begin{DoxyParams}{Parameters}
{\em token} & The token received from the request\+Memory\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The pointer of the memory
\end{DoxyReturn}
This function will throw if called before allocation.

Reimplemented in \mbox{\hyperlink{classnntrainer_1_1CachePool_aa41c9c406113ffca67aa242dd3ae5135}{nntrainer\+::\+Cache\+Pool}}.



Definition at line 116 of file memory\+\_\+pool.\+cpp.

\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a02b04bf079aae50660bb1bc15397a3dc}\label{classnntrainer_1_1MemoryPool_a02b04bf079aae50660bb1bc15397a3dc}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!isAllocated@{isAllocated}}
\index{isAllocated@{isAllocated}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{isAllocated()}{isAllocated()}}
{\footnotesize\ttfamily bool nntrainer\+::\+Memory\+Pool\+::is\+Allocated (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [virtual]}}



Is the memory pool allocated. 

\begin{DoxyReturn}{Returns}
true if the memory is allocated, else false 
\end{DoxyReturn}


Reimplemented in \mbox{\hyperlink{classnntrainer_1_1CachePool_a24fc60236178323100b2d49011594281}{nntrainer\+::\+Cache\+Pool}}.



Definition at line 336 of file memory\+\_\+pool.\+cpp.

\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a85064c5622fd9b897984740b241486e8}\label{classnntrainer_1_1MemoryPool_a85064c5622fd9b897984740b241486e8}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!minMemoryRequirement@{minMemoryRequirement}}
\index{minMemoryRequirement@{minMemoryRequirement}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{minMemoryRequirement()}{minMemoryRequirement()}}
{\footnotesize\ttfamily size\+\_\+t nntrainer\+::\+Memory\+Pool\+::min\+Memory\+Requirement (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Get the minimum theoretical memory requirement. 

\begin{DoxyReturn}{Returns}
The theoretical memory requirement with this strategy in bytes
\end{DoxyReturn}


Definition at line 149 of file memory\+\_\+pool.\+cpp.

\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a0aeca99e88a00fee9531ce9c53995789}\label{classnntrainer_1_1MemoryPool_a0aeca99e88a00fee9531ce9c53995789}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!planLayout@{planLayout}}
\index{planLayout@{planLayout}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{planLayout()}{planLayout()}}
{\footnotesize\ttfamily double nntrainer\+::\+Memory\+Pool\+::plan\+Layout (\begin{DoxyParamCaption}\item[{const \mbox{\hyperlink{classnntrainer_1_1MemoryPlanner}{Memory\+Planner}} \&}]{planner }\end{DoxyParamCaption})}



Plan the layout with memory planner. 

Planner the layout with memory planner.


\begin{DoxyParams}{Parameters}
{\em planner} & The memory planner to be used for finalizing the layout\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The efficiency of the memory layer with the given memory planner
\end{DoxyReturn}
The efficiency of the planner is calculated as the ratio of the theoretical minimum memory requirement divided by the memory requirement given by the memory planner.

plan\+Layout can be called multiple times as this does not perform any allocation but rather just plans the layout and stores the layout. Subsequent call to this function will overwrite any existing layout.

The efficiency of the planner is calculated as the ratio of the theoretical minimum memory requirement divided by the memory requirement given by the memory planner.

plan\+Layout can be called multiple times as this does not perform any allocation but rather just plans the layout and stores the layout. Subsequent call to this function will overwrite any existing layout. mem\+\_\+pool must be deallocated when plan\+Layout is being called

calculate min\+\_\+pool\+\_\+size if not already calculated

Definition at line 67 of file memory\+\_\+pool.\+cpp.

Here is the call graph for this function\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classnntrainer_1_1MemoryPool_a0aeca99e88a00fee9531ce9c53995789_cgraph}
\end{center}
\end{figure}
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_a88bbb4aefec3b4d2bacf46f6444780da}\label{classnntrainer_1_1MemoryPool_a88bbb4aefec3b4d2bacf46f6444780da}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!requestMemory@{requestMemory}}
\index{requestMemory@{requestMemory}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{requestMemory()}{requestMemory()}}
{\footnotesize\ttfamily unsigned int nntrainer\+::\+Memory\+Pool\+::request\+Memory (\begin{DoxyParamCaption}\item[{size\+\_\+t}]{bytes,  }\item[{unsigned int}]{start\+\_\+time,  }\item[{unsigned int}]{end\+\_\+time,  }\item[{std\+::vector$<$ unsigned int $>$}]{exec\+\_\+order = {\ttfamily std\+:\+:vector$<$unsigned~int$>$()},  }\item[{\mbox{\hyperlink{namespacenntrainer_a7bd666a3854202ea94feb44a15ad622d}{Tensor\+Lifespan}}}]{lifespan = {\ttfamily \mbox{\hyperlink{namespacenntrainer_a7bd666a3854202ea94feb44a15ad622daa9e0b1de0ff7353f28b66401c4d303bc}{Tensor\+Lifespan\+::\+M\+A\+X\+\_\+\+L\+I\+F\+E\+S\+P\+AN}}},  }\item[{bool}]{is\+\_\+wgrad = {\ttfamily false} }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [virtual]}}



Request Memory from memory pool. 


\begin{DoxyParams}{Parameters}
{\em bytes} & The size of the memory requested in bytes \\
\hline
{\em start\+\_\+time} & The start of the validity interval of this memory \\
\hline
{\em end\+\_\+time} & The end of the validity interval of this memory \\
\hline
{\em exec\+\_\+order} & execution orders of this memory \\
\hline
{\em lifespan} & lifespan of memory \\
\hline
{\em is\+\_\+wgrad} & check if the tensor is weight gradient\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The token to get the pointer for this memory after allocation 
\end{DoxyReturn}
\begin{DoxyNote}{Note}
start\+\_\+time is inclusive, but end\+\_\+time is exclusive 

The value of the return token starts from 1.

start\+\_\+time is inclusive, but end\+\_\+time is exclusive 
\end{DoxyNote}
invalidate min\+\_\+pool\+\_\+size if already there

Definition at line 28 of file memory\+\_\+pool.\+cpp.

Here is the caller graph for this function\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{classnntrainer_1_1MemoryPool_a88bbb4aefec3b4d2bacf46f6444780da_icgraph}
\end{center}
\end{figure}
\mbox{\Hypertarget{classnntrainer_1_1MemoryPool_ab3e19f0fb2f54084fe29090eeee2213a}\label{classnntrainer_1_1MemoryPool_ab3e19f0fb2f54084fe29090eeee2213a}} 
\index{nntrainer::MemoryPool@{nntrainer::MemoryPool}!size@{size}}
\index{size@{size}!nntrainer::MemoryPool@{nntrainer::MemoryPool}}
\doxysubsubsection{\texorpdfstring{size()}{size()}}
{\footnotesize\ttfamily size\+\_\+t nntrainer\+::\+Memory\+Pool\+::size (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})}



Get the maximum real memory requirement. 

\begin{DoxyReturn}{Returns}
The real memory requirement with this strategy in bytes
\end{DoxyReturn}


Definition at line 143 of file memory\+\_\+pool.\+cpp.



The documentation for this class was generated from the following files\+:\begin{DoxyCompactItemize}
\item 
tensor/\mbox{\hyperlink{memory__pool_8h}{memory\+\_\+pool.\+h}}\item 
tensor/\mbox{\hyperlink{memory__pool_8cpp}{memory\+\_\+pool.\+cpp}}\end{DoxyCompactItemize}
