{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Profiling Tutorial\n",
    "\n",
    "### Learning objectives\n",
    "Learn how to profile your application with NVIDIA Nsight Systems and NVTX API calls to find performance limiters and bottlenecks and apply incremental parallelization strategies using OpenACC programming model. In this lab, you will:\n",
    "\n",
    "- Understand what a profiler is and which NVIDIA Nsight tool to choose in order to profile your application\n",
    "- Profile a sequential weather modeling application (integrated with NVIDIA Tools Extension (NVTX) APIs) with NVIDIA Nsight Systems to capture and trace CPU events and time ranges\n",
    "- Understand how to use NVIDIA Nsight Systems profiler’s report to detect hotspots and apply OpenACC compute constructs to the serial application to parallelise it on the GPU\n",
    "- Learn how to use Nsight Systems to identify issues such as underutilized GPU device and unnecessary data movements in the application and to apply optimization strategies steps by steps to expose more parallelism and utilize computer’s CPU and GPU\n",
    "- Learn how to use occupancy to address performance limitations\n",
    "- Learn to follow cyclical process (analyze, parallelize, optimize) to help you identify the portions of the code that would benefit from GPU acceleration and apply parallelisation strategies and optimization techniques to see additional speedups and improve performance\n",
    "\n",
    "In this lab, we will be optimizing the serial Weather Simulation application written in both C and Fortran programming language. You are welcome to have a look at the mini weather lab and follow the steps to familiarize yourself with the application. \n",
    "\n",
    "An optional exercise on how to use Nsight Compute profiler is available for advanced users. This exercise covers basics on how and when to use the Nsight Compute profiler to get you started. Steps to unravel performance limiters will be presented through a simple exercise.\n",
    "\n",
    "\n",
    "### Tutorial Outline\n",
    "- Introduction ([C](C/jupyter_notebook/profiling-c.ipynb) , [Fortran](Fortran/jupyter_notebook/profiling-fortran.ipynb))\n",
    "    - Overview of Nsight profiler tools\n",
    "    - How to use NVTX APIs\n",
    "    - Overview of [Mini Weather application](C/jupyter_notebook/miniweather.ipynb)\n",
    "    - Optimization Steps to parallel programming with OpneACC\n",
    "- Lab 1 ([C](C/jupyter_notebook/profiling-c-lab1.ipynb) , [Fortran](Fortran/jupyter_notebook/profiling-fortran-lab1.ipynb))\n",
    "    - How to compile a serial application with PGI compiler\n",
    "    - How to profile a serial application with Nsight Systems and NVTX APIs\n",
    "    - How to use profiler's report to find hotspots\n",
    "    - Scaling and Amdahl's law and why it matters\n",
    "- Lab 2 ([C](C/jupyter_notebook/profiling-c-lab2.ipynb) , [Fortran](Fortran/jupyter_notebook/profiling-fortran-lab2.ipynb))\n",
    "    - Parallelise the serial application using OpenACC compute directives\n",
    "    - How to compile a parallel application with PGI compiler\n",
    "    - What does the compiler feedback tell us\n",
    "    - Profile with Nsight Systems\n",
    "    - Finding bottlenecks from Nsight Systems report\n",
    "- Lab 3 ([C](C/jupyter_notebook/profiling-c-lab3.ipynb) , [Fortran](Fortran/jupyter_notebook/profiling-fortran-lab3.ipynb))\n",
    "    - How to combine the knowledge from compiler feedback and profiler to optimize the application\n",
    "    - What is occupancy\n",
    "    - Demystifying Gangs, Workers, and Vectors\n",
    "    - Apply collapse clause to optimize the application further\n",
    "- Lab 4 ([C](C/jupyter_notebook/profiling-c-lab4.ipynb) , [Fortran](Fortran/jupyter_notebook/profiling-fortran-lab4.ipynb))\n",
    "    - Inspect data movement from the profiler's report\n",
    "    - Data management with OpenACC\n",
    "    - Apply incremental parallelization strategies and use profiler's report for the next step\n",
    "- Lab 5 ([C](C/jupyter_notebook/profiling-c-lab5.ipynb) , [Fortran](Fortran/jupyter_notebook/profiling-fortran-lab5.ipynb))\n",
    "    - Overview of Nsight Compute\n",
    "    - When and How to use Nsight Compute\n",
    "    - What does the profiler tell us, where is the bottleneck\n",
    "    - How to use baselines with Nsight Compute\n",
    "    \n",
    "\n",
    "### Tutorial Duration\n",
    "The lab material will be presented in a 2hr session. Link to material is available for download at the end of the lab.\n",
    "\n",
    "### Content Level\n",
    "Beginner, Intermediate\n",
    "\n",
    "### Target Audience and Prerequisites\n",
    "The target audience for this lab is researchers/graduate students and developers who are interested in getting hands on experience with the NVIDIA Nsight System through profiling a real life parallel application using OpenACC programming model and NVTX.\n",
    "\n",
    "While this tutorial does not assume any expertise in CUDA experience, basic knowledge of OpenACC programming (e.g: compute constructs), GPU architecture, and programming experience with C/C++ or Fortran is desirable.\n",
    "\n",
    "### Start Here\n",
    "You can choose between a [C-based code](C/jupyter_notebook/profiling-c.ipynb) and a [Fortran-based code](Fortran/jupyter_notebook/profiling-fortran.ipynb).\n",
    "\n",
    "--- \n",
    "\n",
    "## Licensing \n",
    "\n",
    "This material is released by NVIDIA Corporation under the Creative Commons Attribution 4.0 International (CC BY 4.0). \n"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
