I would like to surround some source code in my beamer presentation with a lightly shaded box.
More specifically in the C++ source code given below, I would like to
shade the code block of the vecAddKernel
function with a light grey box. How do I do this.
Here is my code for my beamer frame
\begin{frame}[fragile]{Simple CUDA Code: A Vector Sum}
\lstset{ language=C++,
basicstyle=\ttfamily\scriptsize,
keywordstyle=\color{blue}\ttfamily,
stringstyle=\color{red}\ttfamily,
commentstyle=\color{green}\ttfamily
}
\begin{lstlisting}
// Compute vector sum C = A+B
// Each thread performs one pair-wise addition
__global__
void vecAddKernel(float* A_d, float* B_d, float* C_d, int n)
{
int i = threadIdx.x + blockDim.x * blockIdx.x;
if(i<n) C_d[i] = A_d[i] + B_d[i];
}
int vecAdd(float* A, float* B, float* C, int n)
{
// A_d, B_d, C_d allocations and copies omitted
// Run ceil(n/256) blocks of 256 threads each
dim3 DimGrid(ceil(n/256.0), 1, 1);
dim3 DimBlock(256, 1, 1);
vecAddKernnel<<<DimGrid,DimBlock>>>(A_d, B_d, C_d, n);
}
\end{lstlisting}
\textbf{Note: } Calls to kernels are \textbf{\color{orange}asynchronous}.
\end{frame}
Here is the output of compiling it.
Best Answer
Here's an option using the
lstlinebgrd
package:For fancier frames, ther's another option using the improved version of
\tizmark
(thanks to Andrew Stacey); the idea is to put some marks and then use themarks to draw the colored background: