%%bash 

nvidia-smi

"""
Explanation: Explore the GPU!
Run Standard nvidia-smi Tool
End of explanation
"""


%%bash 

xla_device_test &> xla_device_test.log

tail -3 xla_device_test.log

"""
Explanation: Run Accelerated Linear Algebra (XLA) Tests
Check the generated xla_device_test.log file
End of explanation
"""


%%bash 

cat /root/src/main/cuda/SumArrays.cu

"""
Explanation: Run Some CUDA Code!
Show CUDA Code
End of explanation
"""


%%bash 

sum_arrays

"""
Explanation: Run CUDA Code and Verify Expected Output
```
EXPECTED OUTPUT
...
 Awesome!  The GPU summed the arrays!! 
...
```
Note the execution time.
End of explanation
"""


%%bash

# Don't go above 10!!
for _ in {1..5}
do
  sum_arrays > /dev/null 2>&1
done

echo "...Done!"

"""
Explanation: Open a Terminal through Jupyter Notebook
(Menu Bar -> Terminal -> New Terminal)

Run this Command to Watch GPU Every Second:
watch -n 1 nvidia-smi
Run Code In Loop, Watch GPU
Note:  Don't go higher than 10!
Otherwise the following may happen:
* this cell will take a long time to finish
* you may kill your instance!!
End of explanation
"""


%%bash 

cat /root/src/main/cuda/SumArraysAsyncMemcpy.cu

"""
Explanation: Run Some Advanced CUDA Code!
We lower overall execution time using async, stream-based memcpy
Show Advanced CUDA Code, Find Stream
End of explanation
"""


%%bash 

sum_arrays_async_memcpy

%%bash

# Don't go above 10!!
for _ in {1..5}
do
  sum_arrays_async_memcpy > /dev/null 2>&1
done

echo "...Done!"

%%bash 

which sum_arrays_async_memcpy

%%bash

ls -l /root/scripts/

%%bash

cat /root/scripts/sum_arrays_async_memcpy

"""
Explanation: Run CUDA Code and Verify Expected Output
```
EXPECTED OUTPUT
...
 Awesome!  The GPU summed the arrays!! 
...
```
Also, note the lower execution time due to async memcpy.
End of explanation
"""


