\doxysection{memory.\+hpp}
\hypertarget{memory_8hpp_source}{}\label{memory_8hpp_source}\index{ginkgo/core/base/memory.hpp@{ginkgo/core/base/memory.hpp}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{comment}{//\ SPDX-\/FileCopyrightText:\ 2017\ -\/\ 2024\ The\ Ginkgo\ authors}}
\DoxyCodeLine{00002\ \textcolor{comment}{//}}
\DoxyCodeLine{00003\ \textcolor{comment}{//\ SPDX-\/License-\/Identifier:\ BSD-\/3-\/Clause}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#ifndef\ GKO\_PUBLIC\_CORE\_BASE\_MEMORY\_HPP\_}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#define\ GKO\_PUBLIC\_CORE\_BASE\_MEMORY\_HPP\_}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ }
\DoxyCodeLine{00009\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/fwd\_decls.hpp>}}
\DoxyCodeLine{00010\ \textcolor{preprocessor}{\#include\ <ginkgo/core/base/types.hpp>}}
\DoxyCodeLine{00011\ }
\DoxyCodeLine{00012\ }
\DoxyCodeLine{00013\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacegko}{gko}}\ \{}
\DoxyCodeLine{00014\ }
\DoxyCodeLine{00015\ }
\DoxyCodeLine{00020\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1Allocator}{Allocator}}\ \{}
\DoxyCodeLine{00021\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00022\ \ \ \ \ \textcolor{keyword}{virtual}\ \doxymbox{\hyperlink{classgko_1_1Allocator}{\string~Allocator}}()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00023\ }
\DoxyCodeLine{00024\ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ =\ 0;}
\DoxyCodeLine{00025\ }
\DoxyCodeLine{00026\ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ =\ 0;}
\DoxyCodeLine{00027\ \};}
\DoxyCodeLine{00028\ }
\DoxyCodeLine{00029\ }
\DoxyCodeLine{00034\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1CpuAllocatorBase}{CpuAllocatorBase}}\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1Allocator}{Allocator}}\ \{\};}
\DoxyCodeLine{00035\ }
\DoxyCodeLine{00036\ }
\DoxyCodeLine{00040\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1CudaAllocatorBase}{CudaAllocatorBase}}\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1Allocator}{Allocator}}\ \{}
\DoxyCodeLine{00041\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }CudaExecutor;}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00043\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00055\ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{bool}\ check\_environment(\textcolor{keywordtype}{int}\ device\_id,\ CUstream\_st*\ stream)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00056\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00058\ \ \ \ \ \}}
\DoxyCodeLine{00059\ \};}
\DoxyCodeLine{00060\ }
\DoxyCodeLine{00061\ }
\DoxyCodeLine{00065\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1HipAllocatorBase}{HipAllocatorBase}}\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1Allocator}{Allocator}}\ \{}
\DoxyCodeLine{00066\ \ \ \ \ \textcolor{keyword}{friend}\ \textcolor{keyword}{class\ }HipExecutor;}
\DoxyCodeLine{00067\ }
\DoxyCodeLine{00068\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{bool}\ check\_environment(\textcolor{keywordtype}{int}\ device\_id,}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GKO\_HIP\_STREAM\_STRUCT*\ stream)\textcolor{keyword}{\ const}}
\DoxyCodeLine{00082\ \textcolor{keyword}{\ \ \ \ }\{}
\DoxyCodeLine{00083\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
\DoxyCodeLine{00084\ \ \ \ \ \}}
\DoxyCodeLine{00085\ \};}
\DoxyCodeLine{00086\ }
\DoxyCodeLine{00087\ }
\DoxyCodeLine{00091\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1CpuAllocator}{CpuAllocator}}\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CpuAllocatorBase}{CpuAllocatorBase}}\ \{}
\DoxyCodeLine{00092\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00093\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00094\ }
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00096\ \};}
\DoxyCodeLine{00097\ }
\DoxyCodeLine{00098\ }
\DoxyCodeLine{00102\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1CudaAllocator}{CudaAllocator}}\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CudaAllocatorBase}{CudaAllocatorBase}}\ \{}
\DoxyCodeLine{00103\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00104\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00105\ }
\DoxyCodeLine{00106\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00107\ \};}
\DoxyCodeLine{00108\ }
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00110\ \textcolor{comment}{/*}}
\DoxyCodeLine{00111\ \textcolor{comment}{\ *\ Allocator\ using\ cudaMallocAsync.}}
\DoxyCodeLine{00112\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00113\ \textcolor{keyword}{class\ }CudaAsyncAllocator\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CudaAllocatorBase}{CudaAllocatorBase}}\ \{}
\DoxyCodeLine{00114\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00115\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00116\ }
\DoxyCodeLine{00117\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00118\ }
\DoxyCodeLine{00119\ \ \ \ \ CudaAsyncAllocator(CUstream\_st*\ stream);}
\DoxyCodeLine{00120\ }
\DoxyCodeLine{00121\ \ \ \ \ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classgko_1_1CudaAsyncAllocator_ade0fbb75c0270b9df4895123965c4a65}{check\_environment}}(\textcolor{keywordtype}{int}\ device\_id,\ CUstream\_st*\ stream)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00123\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00124\ \ \ \ \ CUstream\_st*\ stream\_;}
\DoxyCodeLine{00125\ \};}
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ }
\DoxyCodeLine{00128\ \textcolor{comment}{/*}}
\DoxyCodeLine{00129\ \textcolor{comment}{\ *\ Allocator\ using\ cudaMallocManaged}}
\DoxyCodeLine{00130\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00131\ \textcolor{keyword}{class\ }CudaUnifiedAllocator\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CudaAllocatorBase}{CudaAllocatorBase}},\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CpuAllocatorBase}{CpuAllocatorBase}}\ \{}
\DoxyCodeLine{00132\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00133\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00136\ }
\DoxyCodeLine{00137\ \ \ \ \ CudaUnifiedAllocator(\textcolor{keywordtype}{int}\ device\_id);}
\DoxyCodeLine{00138\ }
\DoxyCodeLine{00139\ \ \ \ \ CudaUnifiedAllocator(\textcolor{keywordtype}{int}\ device\_id,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ flags);}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00141\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00142\ \ \ \ \ \textcolor{keywordtype}{bool}\ check\_environment(\textcolor{keywordtype}{int}\ device\_id,\ CUstream\_st*\ stream)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00143\ }
\DoxyCodeLine{00144\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00145\ \ \ \ \ \textcolor{keywordtype}{int}\ device\_id\_;}
\DoxyCodeLine{00146\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ flags\_;}
\DoxyCodeLine{00147\ \};}
\DoxyCodeLine{00148\ }
\DoxyCodeLine{00149\ }
\DoxyCodeLine{00150\ \textcolor{comment}{/*}}
\DoxyCodeLine{00151\ \textcolor{comment}{\ *\ Allocator\ using\ cudaHostMalloc.}}
\DoxyCodeLine{00152\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00153\ \textcolor{keyword}{class\ }CudaHostAllocator\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CudaAllocatorBase}{CudaAllocatorBase}},\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CpuAllocatorBase}{CpuAllocatorBase}}\ \{}
\DoxyCodeLine{00154\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00155\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00156\ }
\DoxyCodeLine{00157\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00158\ }
\DoxyCodeLine{00159\ \ \ \ \ CudaHostAllocator(\textcolor{keywordtype}{int}\ device\_id);}
\DoxyCodeLine{00160\ }
\DoxyCodeLine{00161\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{keywordtype}{bool}\ check\_environment(\textcolor{keywordtype}{int}\ device\_id,\ CUstream\_st*\ stream)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{keywordtype}{int}\ device\_id\_;}
\DoxyCodeLine{00166\ \};}
\DoxyCodeLine{00167\ }
\DoxyCodeLine{00168\ }
\DoxyCodeLine{00169\ \textcolor{comment}{/*}}
\DoxyCodeLine{00170\ \textcolor{comment}{\ *\ Allocator\ using\ hipMalloc.}}
\DoxyCodeLine{00171\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00172\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classgko_1_1HipAllocator}{HipAllocator}}\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1HipAllocatorBase}{HipAllocatorBase}}\ \{}
\DoxyCodeLine{00173\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00174\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00175\ }
\DoxyCodeLine{00176\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00177\ \};}
\DoxyCodeLine{00178\ }
\DoxyCodeLine{00179\ }
\DoxyCodeLine{00180\ \textcolor{comment}{/*}}
\DoxyCodeLine{00181\ \textcolor{comment}{\ *\ Allocator\ using\ hipMallocAsync.}}
\DoxyCodeLine{00182\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00183\ \textcolor{keyword}{class\ }HipAsyncAllocator\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1HipAllocatorBase}{HipAllocatorBase}}\ \{}
\DoxyCodeLine{00184\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00185\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00186\ }
\DoxyCodeLine{00187\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00188\ }
\DoxyCodeLine{00189\ \ \ \ \ HipAsyncAllocator(GKO\_HIP\_STREAM\_STRUCT*\ stream);}
\DoxyCodeLine{00190\ }
\DoxyCodeLine{00191\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00192\ \ \ \ \ \textcolor{keywordtype}{bool}\ check\_environment(\textcolor{keywordtype}{int}\ device\_id,}
\DoxyCodeLine{00193\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GKO\_HIP\_STREAM\_STRUCT*\ stream)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00194\ }
\DoxyCodeLine{00195\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00196\ \ \ \ \ GKO\_HIP\_STREAM\_STRUCT*\ stream\_;}
\DoxyCodeLine{00197\ \};}
\DoxyCodeLine{00198\ }
\DoxyCodeLine{00199\ }
\DoxyCodeLine{00200\ \textcolor{comment}{/*}}
\DoxyCodeLine{00201\ \textcolor{comment}{\ *\ Allocator\ using\ hipMallocManaged}}
\DoxyCodeLine{00202\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00203\ \textcolor{keyword}{class\ }HipUnifiedAllocator\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1HipAllocatorBase}{HipAllocatorBase}},\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CpuAllocatorBase}{CpuAllocatorBase}}\ \{}
\DoxyCodeLine{00204\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00205\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00206\ }
\DoxyCodeLine{00207\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00208\ }
\DoxyCodeLine{00209\ \ \ \ \ HipUnifiedAllocator(\textcolor{keywordtype}{int}\ device\_id);}
\DoxyCodeLine{00210\ }
\DoxyCodeLine{00211\ \ \ \ \ HipUnifiedAllocator(\textcolor{keywordtype}{int}\ device\_id,\ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ flags);}
\DoxyCodeLine{00212\ }
\DoxyCodeLine{00213\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00214\ \ \ \ \ \textcolor{keywordtype}{bool}\ check\_environment(\textcolor{keywordtype}{int}\ device\_id,}
\DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GKO\_HIP\_STREAM\_STRUCT*\ stream)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00216\ }
\DoxyCodeLine{00217\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00218\ \ \ \ \ \textcolor{keywordtype}{int}\ device\_id\_;}
\DoxyCodeLine{00219\ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{int}\ flags\_;}
\DoxyCodeLine{00220\ \};}
\DoxyCodeLine{00221\ }
\DoxyCodeLine{00222\ }
\DoxyCodeLine{00223\ \textcolor{comment}{/*}}
\DoxyCodeLine{00224\ \textcolor{comment}{\ *\ Allocator\ using\ hipHostAlloc.}}
\DoxyCodeLine{00225\ \textcolor{comment}{\ */}}
\DoxyCodeLine{00226\ \textcolor{keyword}{class\ }HipHostAllocator\ :\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1HipAllocatorBase}{HipAllocatorBase}},\ \textcolor{keyword}{public}\ \doxymbox{\hyperlink{classgko_1_1CpuAllocatorBase}{CpuAllocatorBase}}\ \{}
\DoxyCodeLine{00227\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00228\ \ \ \ \ \textcolor{keywordtype}{void}*\ allocate(\doxymbox{\hyperlink{namespacegko_a9579c98b1d85bf4ad02d7cb5b96fc771}{size\_type}}\ num\_bytes)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00229\ }
\DoxyCodeLine{00230\ \ \ \ \ \textcolor{keywordtype}{void}\ deallocate(\textcolor{keywordtype}{void}*\ ptr)\ \textcolor{keyword}{override};}
\DoxyCodeLine{00231\ }
\DoxyCodeLine{00232\ \ \ \ \ HipHostAllocator(\textcolor{keywordtype}{int}\ device\_id);}
\DoxyCodeLine{00233\ }
\DoxyCodeLine{00234\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00235\ \ \ \ \ \textcolor{keywordtype}{bool}\ check\_environment(\textcolor{keywordtype}{int}\ device\_id,}
\DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ GKO\_HIP\_STREAM\_STRUCT*\ stream)\ \textcolor{keyword}{const\ override};}
\DoxyCodeLine{00237\ }
\DoxyCodeLine{00238\ \textcolor{keyword}{private}:}
\DoxyCodeLine{00239\ \ \ \ \ \textcolor{keywordtype}{int}\ device\_id\_;}
\DoxyCodeLine{00240\ \};}
\DoxyCodeLine{00241\ }
\DoxyCodeLine{00242\ }
\DoxyCodeLine{00243\ \}\ \ \textcolor{comment}{//\ namespace\ gko}}
\DoxyCodeLine{00244\ }
\DoxyCodeLine{00245\ }
\DoxyCodeLine{00246\ \textcolor{preprocessor}{\#endif\ \ }\textcolor{comment}{//\ GKO\_PUBLIC\_CORE\_BASE\_MEMORY\_HPP\_}}

\end{DoxyCode}
