Browse Source

add figure visualizing public interface of cachedata and cache to chapter 4 design

master
Constantin Fürst 11 months ago
parent
commit
96f08fce81
  1. BIN
      thesis/bachelor.pdf
  2. 14
      thesis/content/40_design.tex
  3. BIN
      thesis/images/design-classdiagram.png
  4. 82
      thesis/images/design-classdiagram.xml

BIN
thesis/bachelor.pdf

14
thesis/content/40_design.tex

@ -34,11 +34,21 @@
The task of prefetching is somewhat aligned with that of a cache. As a cache is more generic and allows use beyond Query Driven Prefetching, the choice was made to solve the prefetching offload by implementing an offloading \texttt{Cache}. When referring to the provided implementation, \texttt{Cache} will be used from now on. The interface with \texttt{Cache} must provide three basic functions: requesting a memory block to be cached, accessing a cached memory block and synchronizing cache with the source memory. The latter operation comes in to play when the data that is cached may also be modified, requiring the entry to be updated with the source or the other way around. Due to the many possible setups and use cases, the user should also be responsible for choosing cache placement and the copy method. As re-caching is resource intensive, data should remain in the cache for as long as possible while being removed when memory pressure due to restrictive memory size drives the \texttt{Cache} to flush unused entries. \par The task of prefetching is somewhat aligned with that of a cache. As a cache is more generic and allows use beyond Query Driven Prefetching, the choice was made to solve the prefetching offload by implementing an offloading \texttt{Cache}. When referring to the provided implementation, \texttt{Cache} will be used from now on. The interface with \texttt{Cache} must provide three basic functions: requesting a memory block to be cached, accessing a cached memory block and synchronizing cache with the source memory. The latter operation comes in to play when the data that is cached may also be modified, requiring the entry to be updated with the source or the other way around. Due to the many possible setups and use cases, the user should also be responsible for choosing cache placement and the copy method. As re-caching is resource intensive, data should remain in the cache for as long as possible while being removed when memory pressure due to restrictive memory size drives the \texttt{Cache} to flush unused entries. \par
\begin{figure}[h]
\centering
\includegraphics[width=0.9\textwidth]{images/design-classdiagram.png}
\caption{Public Interface of CacheData and Cache Classes}
\label{fig:impl-design-interface}
\end{figure}
For reference, the public interface which we will develop throughout this section is visualized in Figure \ref{fig:impl-design-interface} for both classes created. Colour coding signals thread safety where grey denotes impossibility for threaded access. Green indicates full safety guarantees only relying on atomics to achieve this. Turquoise functions use locking mechanisms to achieve thread safety. Operations in yellow may observe threading effects from atomics but are still inherently safe to call. Finally, red markers indicate unsafe functions which must be called from a single threaded context. As we implement these classes in C++ in Chapter \ref{chap:implementation}, we also utilize C++-Notation for functions in the figure here.\par
\subsection{Interface} \subsection{Interface}
To allow rapid integration and ease developer workload, a simple interface was chosen. As this work primarily focuses on caching static data, the choice was made only to provide cache invalidation and not synchronization. Given a memory address, \texttt{Cache::Invalidate} will remove all entries for it. The other two operations are provided in one single function, which we shall call \texttt{Cache::Access} henceforth, receiving a data pointer and size it takes care of either submitting a caching operation if the pointer received is not yet cached or returning the cache entry if it is. The cache placement and assignment of the task to accelerators are controlled by the user. In addition to the two basic operations outlined before, the user also is given the option to flush the cache using \texttt{Cache::Flush} of unused elements manually or to clear it completely with \texttt{Cache::Clear}. \par
As caching is performed asynchronously, the user may wish to wait on the operation. This would be beneficial if there are other threads making progress in parallel while the current thread waits on its data becoming available in the faster cache, speeding up local computation. To achieve this, the \texttt{Cache::Access} will return an instance of an object which from hereinafter will be referred to as \texttt{CacheData}. Through \texttt{CacheData::GetDataLocation} a pointer to the cached data will be retrieved, while also providing \texttt{CacheData::WaitOnCompletion} which must only return when the caching operation has completed and during which the current thread is put to sleep, allowing other threads to progress. \par
To allow rapid integration and ease developer workload, a simple interface was chosen. As this work primarily focuses on caching static data, the choice was made only to provide cache invalidation and not synchronization. Given a memory address, \texttt{Cache::Invalidate} will remove all entries for it. The other two operations are provided in one single function, which we shall call \texttt{Cache::Access} henceforth, receiving a data pointer and size it takes care of either submitting a caching operation if the pointer received is not yet cached or returning the cache entry if it is. The cache placement and assignment of the task to accelerators are controlled by the user. In addition to the two basic operations outlined before, the user also is given the option to flush the cache using \texttt{Cache::Flush} of unused elements manually or to clear it completely with \texttt{Cache::Clear}. This interface is represented on the right block of Figure \ref{fig:impl-design-interface} labelled \enquote{Cache}. \par
As caching is performed asynchronously, the user may wish to wait on the operation. This would be beneficial if there are other threads making progress in parallel while the current thread waits on its data becoming available in the faster cache, speeding up local computation. To achieve this, the \texttt{Cache::Access} will return an instance of an object which from hereinafter will be referred to as \texttt{CacheData}. Through \texttt{CacheData::GetDataLocation} a pointer to the cached data will be retrieved, while also providing \texttt{CacheData::WaitOnCompletion} which must only return when the caching operation has completed and during which the current thread is put to sleep, allowing other threads to progress. Figure \ref{fig:impl-design-interface} also documents the public interface for \texttt{CacheData} on the left block labelled as such. \par
\subsection{Cache Entry Reuse} \label{subsec:design:cache-entry-reuse} \subsection{Cache Entry Reuse} \label{subsec:design:cache-entry-reuse}

BIN
thesis/images/design-classdiagram.png

After

Width: 524  |  Height: 294  |  Size: 47 KiB

82
thesis/images/design-classdiagram.xml

@ -0,0 +1,82 @@
<mxfile host="app.diagrams.net" modified="2024-01-21T16:38:15.391Z" agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" etag="9bOtjw8dTkath-EdKy1I" version="22.1.21" type="device">
<diagram name="Page-1" id="xBjmK5o3fU9FCVY3KYoo">
<mxGraphModel dx="1434" dy="803" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="827" pageHeight="369" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="tB5LUjmhD6zCi5oJ_og_-23" value="" style="group" vertex="1" connectable="0" parent="1">
<mxGeometry x="170" y="40" width="230" height="190" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-1" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-23">
<mxGeometry width="230" height="190" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-2" value="" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=4;fillColor=none;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-23">
<mxGeometry width="230" height="190" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-3" value="&lt;b&gt;CacheData&lt;/b&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fillColor=default;strokeColor=default;strokeWidth=2;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-23">
<mxGeometry width="230" height="40" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-5" value="CacheData(uint8_t* data, size_t size)" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-23">
<mxGeometry y="40" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-6" value="CacheData(const CacheData&amp;amp; other)" style="text;html=1;strokeColor=#82b366;fillColor=#d5e8d4;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-23">
<mxGeometry y="70" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-7" value="~CacheData()" style="text;html=1;strokeColor=#82b366;fillColor=#d5e8d4;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-23">
<mxGeometry y="100" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-8" value="void WaitOnCompletion()" style="text;html=1;strokeColor=#82b366;fillColor=#d5e8d4;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-23">
<mxGeometry y="130" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-9" value="" style="endArrow=none;html=1;rounded=0;exitX=1;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=0;entryDx=0;entryDy=0;strokeWidth=2;strokeColor=none;" edge="1" parent="tB5LUjmhD6zCi5oJ_og_-23" source="tB5LUjmhD6zCi5oJ_og_-8" target="tB5LUjmhD6zCi5oJ_og_-8">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="530" y="370" as="sourcePoint" />
<mxPoint x="580" y="320" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-11" value="uint8_t* GetDataLocation() const" style="text;html=1;strokeColor=#d6b656;fillColor=#fff2cc;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-23">
<mxGeometry y="160" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-26" value="" style="group;fillColor=#fad9d5;strokeColor=#ae4132;" vertex="1" connectable="0" parent="1">
<mxGeometry x="440" y="40" width="230" height="270" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-14" value="" style="rounded=0;whiteSpace=wrap;html=1;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry width="230" height="190" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-15" value="" style="rounded=0;whiteSpace=wrap;html=1;strokeWidth=4;fillColor=none;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry width="230" height="270" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-16" value="&lt;b&gt;Cache&lt;br&gt;&lt;/b&gt;" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fillColor=default;strokeColor=default;strokeWidth=2;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry width="230" height="40" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-17" value="Cache() = default" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fillColor=#f5f5f5;fontColor=#333333;strokeColor=#666666;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry y="40" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-18" value="void Flush(int node = -1)" style="text;html=1;strokeColor=#0e8088;fillColor=#b0e3e6;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry y="180" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-19" value="~Cache()" style="text;html=1;strokeColor=#b85450;fillColor=#f8cecc;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry y="70" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-20" value="void Init(CachePolicy*, CopyPolicy*)" style="text;html=1;strokeColor=#b85450;fillColor=#f8cecc;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry y="100" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-21" value="" style="endArrow=none;html=1;rounded=0;exitX=1;exitY=0;exitDx=0;exitDy=0;entryX=0;entryY=0;entryDx=0;entryDy=0;strokeWidth=2;strokeColor=none;" edge="1" parent="tB5LUjmhD6zCi5oJ_og_-26" source="tB5LUjmhD6zCi5oJ_og_-20" target="tB5LUjmhD6zCi5oJ_og_-20">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="530" y="370" as="sourcePoint" />
<mxPoint x="580" y="320" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-22" value="std::unique_ptr&amp;lt;CacheData&amp;gt; Access(uint8_t* data, size_t size)" style="text;html=1;strokeColor=#0e8088;fillColor=#b0e3e6;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry y="130" width="230" height="50" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-24" value="void Clear()" style="text;html=1;strokeColor=#0e8088;fillColor=#b0e3e6;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry y="210" width="230" height="30" as="geometry" />
</mxCell>
<mxCell id="tB5LUjmhD6zCi5oJ_og_-25" value="void Invalidate()" style="text;html=1;strokeColor=#0e8088;fillColor=#b0e3e6;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="tB5LUjmhD6zCi5oJ_og_-26">
<mxGeometry y="240" width="230" height="30" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Loading…
Cancel
Save