Docsity

CAL Kernel Programming: AMD IL and GPU ISA Overview, Exams of Electrical and Electronics Engineering

Partial preview of the text

Download CAL Kernel Programming: AMD IL and GPU ISA Overview and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

CAL Kernel Programming

1

2

Module Overview •

CAL Kernel Programming APIs

Overview of AMD IL

Overview of AMD GPU ISA

AMD Brook+ •

‘C’ with Streaming Extensions

Includes –

Kernel programming interface

Runtime implementation

Transparent to application programmer Supports multiple runtimes

Runtime API

Simple and small API for basic operations Provides only high-level control over stream data

4

DirectX High Level Shading Language

(HLSL) •

‘C’ for GPU Programming for 3D applications

Includes –

Kernel Programming Interface

Runtime provided by associated runtime library (DirectX)

Front-end compiler provided by Microsoft (

fxc

Back-end code generation and optimization done by GPUvendors

Original BrookGPU included as DirectX runtime –

Generate HLSL for Brook kernels

Invoke DirectX runtime calls for stream management andkernel invocation, etc

5

AMD GPU ISA •

True GPU assembly

Interface and Implementation is

Architecture

Dependent –

Exposes the GPU architecture completely

Provides insight into GPU architecture and expectedperformance

No optimizations done by the assembler on specifiedISA

Not expected to use directly for applicationdevelopment –

Very useful for performance profiling

Useful for debugging programs

7

Overview of AMD IL

8

AMD IL – Data Types •

IL is a type-less language –

Registers do not have specific types

Can be used to store 32-bit integers, floats, and 64-bitdouble precision values

Types are defined by the instructions, e.g. IMUL

UMUL

MUL

and

DMUL

correspond to multiplication of signed integers, unsigned integers, floats and doublesrespectively

10

AMD IL – Instruction Syntax [][<ctrl(val)>][[_][.<write-mask>]][,

[_][.<swizzle-mask>]]...

Items within

<>

are replaced by specific words or phrases. For

example,

could be replaced by

mov

.

When more than one item of the same type exists, for example ,

a zero-based number is appended to the item name. For

example, for 2-input instructions the sources (inputs) would belabeled

src

and

src

.

Items within square brackets,

[]

, are optional.

Items within braces,

{}

, represent a choice-grouping. For example,

{x|y|z|w}

means to choose

x

,

y

,

z

or

w

.

An ellipsis,

...

, represents a list of alternatives having the same

format as the first alternative in the list.

11

Important ALU Instructions DIV

  • Division of two registers

div_zeroop(op) dst, src0, src1 dst = src0 / src1 zeroop()

decides value of output if divisor is zero, e.g.

fltmax, zero, infinity, inf_else_max

RCP

  • Reciprocal

rcp_zeroop(op) dst, src0 dst = 1/src0.w

SQRT

  • Square Root

sqrt dst, src0 dst = sqrt(src0.w)

13

14

IL Registers

IL provides registers for various tasks

Register

Description

Need to declare

Example

r#

Temporary

No

mad r0, r0, r0, r

cb#[#]

Const buffer

Yes

mov o0, cb0[0]

v

Position

Yes

mul o0, v0.xyxx, cb0[0]

o#

Output

Yes

mov o0, v0.xyxx

Reading Inputs - Samplers •

Both the sample operator and output register are type-less –

The data format and sampling mode needs to be specified in thekernel for each sampler

e.g. dcl_resource_id(0)_type(2d,unnorm)_fmtx(float)_fmty(float)_fmt

z(float)_fmtw(float) Type of resource (1d vs 2d) specified Type of address (normalized vs unnormalized) specified –

Normalized uses coordinates in [0..1] range

Unnormalized uses coordinates in [0..n-1] range

16

2D Resource

Unnormalized

Float

Register Modifiers, Masks and Swizzles [][<ctrl(val)>][[][.<write-mask>]][, [][.<swizzle-mask>]]...

17

Destination Modifier

Source Modifier

Write Mask

Swizzle Mask

Destination Modifiers

19

Write Masks •

Mask a destination element using specified flag

reg.{x||0|1}{y||0|1}{z||0|1}{w||0|1}

Letter (

x

y

z

w

) => element to be written

Underscore (

_

) => element

not

to be written

Zero (

) or One (

) => element forced to zero or one

Omitting => underscore

E.g.

mov r0.x_zw, r1 mov r0.x_01, r

20