ROCm: Leveraging Open
Source Software forAccelerating Applications
with GPUs
Derek Bouius – Product ManagerDisclaimer

The information contained herein is for informational purposes only and is subject to change without notice. While every
precaution has been taken in the preparation of this document, it may contain technical inaccuracies, omissions andtypographical errors, and AMD is under no obligation to update or otherwise correct this information. Advanced MicroDevices, Inc. makes no representations or warranties with respect to the accuracy or completeness of the contents of thisdocument, and assumes no liability of any kind, including the implied warranties of noninfringement, merchantability orfitness for particular purposes, with respect to the operation or use of AMD hardware, software or other products
described herein. No license, including implied or arising by estoppel, to any intellectual property rights is granted by thisdocument. All open source software listed in this presentation is governed by the associated open source license. Terms
and limitations applicable to the purchase or use of AMD’s products are as set forth in a signed agreement between theparties or in AMD's Standard Terms and Conditions of Sale. GD-18©2019 Advanced Micro Devices, Inc. All rights reserved. AMD, the AMD Arrow logo, Ryzen, Threadripper, EPYC, Infinity
Fabric, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in thispublication are for identification purposes only and may be trademarks of their respective companies.
PCIe is a trademark (or registered trademark) of PCI-SIG Corporation.
OpenCL is a trademark of Apple Inc. used by permission by Khronos Group, Inc.
Linux is a trademark (or registered trademark) of Linus Torvalds.
ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

2

What Scientists Care About:“Time-to-Results”
InnovateAnalyze
ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

DesignDevelop

Execute3

Merging of HPC and ML Into Same Workflow
Accelerates “Time-to-Results”• Trained ANN can replace existing numerical solvers, enabling
fast and scalable simulations – up to 100 Million times faster!

https://arxiv.org/abs/1910.07291
ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

4

Accelerate Development Through Abstraction ofHeterogenous Compute Infrastructure
Domain Specific Languages (DSLs)
Frameworks
Directives
Libraries
ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

5• The GCN ISA is free and open:
https://developer.amd.com/resources/developerguides-manuals/• hcc (hip-clang)

AMD GPU
Compilers:
C/C++ based• Compiles HIP code
• HIP (Heterogeneous Interface for Portability) is aninterface that looks similar to CUDA
• hcc is a fork of clang• It understands HIP and emits AMDGCN in the resultingbinary• hipcc -> hcc (clang) -> amdgcn• All the x86 pieces are dealt with in the same way• AOMP (AMD OpenMP Compiler)• Compiles C/C++ code with OpenMP “target” pragmas• Links with libomptarget to produce a binary that canoffload work to the GPU• OpenCL• Khronos Industry Standard accelerator language

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

7• Important technology to the industry

AMD GPUCompilers:
theFORTRANstory• AMD has plans to support OpenMP 4.5+ target
offload from FORTRAN with two open source
options• F18 (based on llvm)• gfortran• FORTRAN compiler work is an ongoing effort• See the Frontier spec sheet for what is expected
to be supported on Frontier• https://www.olcf.ornl.gov/wpcontent/uploads/2019/05/frontier_specsheet.pdf

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

8Compiler Front Ends
(C, C++, HIP, OpenMP, etc)
GCN
Assembly
Device LLVM
Compiler (GCN)

Host LLVM
Compiler

Optimizer

Optimizer

GCN Target

CPU ISA Target

Language Runtime API
ROCr System Runtime API
ROCm Thunk API

User Space

ROCm Kernel Driver
AMDGPU Kernel Driver

Kernel SpaceCPU CodeGPU CodeADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

9

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

10

GPU kernel time interval

Memcopy time interval
API call time interval

Kernel parameters

Kernel counters
Kernel timestamps
11$ rocprof –hsa-trace -i input.txt SimpleConvolution

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

11

Decoder ring: Math library equivalents
CUBLASROCBLAS

Basic Linear Algebra Subroutines

CUFFT

ROCFFT

Fast Fourier Transforms

CUDNN

MIOPEN

Deep Learning Library

CUB

ROCPRIM

Optimized Parallel Primitives

EIGEN

EIGEN

C++ Template Library for Linear Algebra

MORE INFO AT: GITHUB.COM/ROCM-DEVELOPER-TOOLS/HIP à HIP_PORTING_GUIDE.MD
ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

12

HIP: Heterogeneous-compute Interface forPortability
C++ runtime API and kernel language that allows
developers to create portable applications that canrun on AMD’s accelerators as well as CUDA devices.
• Is open-source

Portable HIP C++ (Host & Device Code)#include “cuda.h”#include “hcc.h”

nvcchipcc

Nvidia GPUAMD GPU• Provides an API for an application to leverage GPUacceleration for both AMD and CUDA devices• Syntactically similar to CUDA. Most CUDA API calls
can be converted in place: cuda -> hip• Supports a strong subset of CUDA runtimefunctionality
ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

13

AMD GPU Libraries
A note on naming conventions:• roc* -> AMGCN library usually written in HIP• cu* -> NVIDIA PTX libraries• hip* -> usually interface layer on top of roc*/cu* backends

hip* libraries:• Can be compiled by hipcc and can generate a call forthe device you have:• hipcc->AMDGCN• hipcc->nvcc (inlined)->NVPTX

hipBLASrocBLAS

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

cuBLAS
14

Hipify-perl:

HIPify Tools• Easy to use –point at a directory and it will attempt tohipify CUDA code
• Very simple string replacement technique: may makeincorrect translations• sed -e ‘s/cuda/hip/g’, (e.g., cudaMemcpy becomes
hipMemcpy)• Recommended for quick scans of projects

Hipify-clang:• Requires clang compiler to parse files and performsemantic translation• More robust translation of the code
• Generates warnings and assistance for additional
analysis• High quality translation, particularly for cases wherethe user is familiar with the make system

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

15

Directives –OpenMP and OpenACC Abstract a Varietyof Hardware Platforms
OpenMPCPU

OpenACCGPU

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

Accelerator

16

Frameworks –HPC
KokkosRAJA

OpenMPHIP

ROCm

CUDA

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

17

Frameworks – Machine LearningPyTorch (Caffe2)

TensorFlow

MIOpenHIP

OpenCLADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

18

Domain Specific Languages– Portability of the Future?
DSL 2

DSL 1

OpenMP

OpenACC

DSL n

HIP

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

ISO C++

19

Accelerate Today

https://github.com/RadeonOpenCompute/k8s-device-plugin
https://hub.docker.com/r/rocm/k8s-device-plugin/

hub.docker.com/r/rocm/
Upstream support in
SyLabs Singularity

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

20

For more detailed information…
• www.amd.com/rocm
HIP Training Webinar:• https://www.youtube.com/watch?v=3ZXbRJVvgJs• Sessions at SC19: contact guy.ludden@amd.com

ADAC8 - ©2019 Advanced Micro Devices, Inc. All rights reserved.

21