From 739f9d6fb71b322ee66f75fcfc200537358c4641 Mon Sep 17 00:00:00 2001 From: lucass-carneiro Date: Wed, 24 Jul 2024 13:02:23 -0300 Subject: [PATCH 1/3] CarpetX: Added a section in the docs detailing host, device and inlining annotations of loop lambdas --- CarpetX/doc/documentation.tex | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CarpetX/doc/documentation.tex b/CarpetX/doc/documentation.tex index 17f8cf514..4879aa6e6 100644 --- a/CarpetX/doc/documentation.tex +++ b/CarpetX/doc/documentation.tex @@ -544,6 +544,38 @@ \subsection{Loop Lambdas} } \end{lstlisting} +In addition, users can specify inlining by using the \texttt{CCTK\_ATTRIBUTE\_ALWAYS\_INLINE} macro and designate the location (host or device) via the \texttt{CCTK\_HOST} or \texttt{CCTK\_DEVICE} macros, respectively. The location macros indicate whether a lambda should be available to the host (CPU), the device (GPU), or both. The inlining macro instructs the compiler to inline the lambda (a compile-time optimization where the function call is replaced by its body). These annotations are optional unless the compiler is unable to build a function due to an inability to automatically determine that it needs to be available for device usage, for example. However, when these annotations are desired, they must be placed in specific locations. To add them to a loop lambda declaration, the following syntax is required: +% +\begin{lstlisting} + [=] LOCATION_MACRO(const Loop::PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE { + // loop body + } +\end{lstlisting} +% +For instance, to mark a lambda for host usage, one would use: +% +\begin{lstlisting} + [=] CCTK_HOST(const Loop::PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE { + // loop body + } +\end{lstlisting} +% +For device usage, one would use: +% +\begin{lstlisting} + [=] CCTK_DEVICE(const Loop::PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE { + // loop body + } +\end{lstlisting} +% +For both host and device usage, one would use: +% +\begin{lstlisting} + [=] CCTK_HOST CCTK_DEVICE(const Loop::PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE { + // loop body + } +\end{lstlisting} + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \subsection{The \texttt{PointDesc} type and loop lambda body} \label{sec:point_des} From 4a7d32935c928b184c5f6ad7abd75c85547ea07d Mon Sep 17 00:00:00 2001 From: lucass-carneiro Date: Wed, 24 Jul 2024 14:40:41 -0300 Subject: [PATCH 2/3] CarpetX: Changed the doc text explaining the functionality of host/device macros and inlining macro --- CarpetX/doc/documentation.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CarpetX/doc/documentation.tex b/CarpetX/doc/documentation.tex index 4879aa6e6..0d77c88a8 100644 --- a/CarpetX/doc/documentation.tex +++ b/CarpetX/doc/documentation.tex @@ -544,7 +544,7 @@ \subsection{Loop Lambdas} } \end{lstlisting} -In addition, users can specify inlining by using the \texttt{CCTK\_ATTRIBUTE\_ALWAYS\_INLINE} macro and designate the location (host or device) via the \texttt{CCTK\_HOST} or \texttt{CCTK\_DEVICE} macros, respectively. The location macros indicate whether a lambda should be available to the host (CPU), the device (GPU), or both. The inlining macro instructs the compiler to inline the lambda (a compile-time optimization where the function call is replaced by its body). These annotations are optional unless the compiler is unable to build a function due to an inability to automatically determine that it needs to be available for device usage, for example. However, when these annotations are desired, they must be placed in specific locations. To add them to a loop lambda declaration, the following syntax is required: +In addition, users can specify inlining (a compile-time optimization where the function call is replaced by its body) by using the \texttt{CCTK\_ATTRIBUTE\_ALWAYS\_INLINE} macro and designate host or device availability via the \texttt{CCTK\_HOST} or \texttt{CCTK\_DEVICE} macros, respectively. These annotations are optional unless the compiler is unable to build a function due to an inability to automatically determine that it needs to be available for device usage, for example. However, when these annotations are desired, they must be placed in specific locations. To add them to a loop lambda declaration, the following syntax is required: % \begin{lstlisting} [=] LOCATION_MACRO(const Loop::PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE { From 009b65e9709fd603ae2c5fbef36ff0e9020c91ad Mon Sep 17 00:00:00 2001 From: lucass-carneiro Date: Wed, 24 Jul 2024 14:47:12 -0300 Subject: [PATCH 3/3] CarpetX: Removed the generic LOCATION_MACRO example from the loop lambda annotatio macros examples --- CarpetX/doc/documentation.tex | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/CarpetX/doc/documentation.tex b/CarpetX/doc/documentation.tex index 0d77c88a8..28a5b3f54 100644 --- a/CarpetX/doc/documentation.tex +++ b/CarpetX/doc/documentation.tex @@ -544,15 +544,9 @@ \subsection{Loop Lambdas} } \end{lstlisting} -In addition, users can specify inlining (a compile-time optimization where the function call is replaced by its body) by using the \texttt{CCTK\_ATTRIBUTE\_ALWAYS\_INLINE} macro and designate host or device availability via the \texttt{CCTK\_HOST} or \texttt{CCTK\_DEVICE} macros, respectively. These annotations are optional unless the compiler is unable to build a function due to an inability to automatically determine that it needs to be available for device usage, for example. However, when these annotations are desired, they must be placed in specific locations. To add them to a loop lambda declaration, the following syntax is required: -% -\begin{lstlisting} - [=] LOCATION_MACRO(const Loop::PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE { - // loop body - } -\end{lstlisting} -% -For instance, to mark a lambda for host usage, one would use: +In addition, users can specify inlining (a compile-time optimization where the function call is replaced by its body) by using the \texttt{CCTK\_ATTRIBUTE\_ALWAYS\_INLINE} macro and designate host or device availability via the \texttt{CCTK\_HOST} or \texttt{CCTK\_DEVICE} macros, respectively. These annotations are optional unless the compiler is unable to build a function due to an inability to automatically determine that it needs to be available for device usage, for example. However, when these annotations are desired, they must be placed in specific locations. + +To mark a lambda for host usage, one would use: % \begin{lstlisting} [=] CCTK_HOST(const Loop::PointDesc &p) CCTK_ATTRIBUTE_ALWAYS_INLINE {