emu

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2021 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package emu emulates GCN3 instructions. It also implement a emulation-only Compute Unit.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ALU

type ALU interface {
	Run(state InstEmuState)

	SetLDS(lds []byte)
	LDS() []byte
}

ALU does its jobs

type ALUImpl

type ALUImpl struct {
	// contains filtered or unexported fields
}

ALUImpl is where the instructions get executed.

func NewALU

func NewALU(storageAccessor *storageAccessor) *ALUImpl

NewALU creates a new ALU with a storage as a dependency.

func (*ALUImpl) LDS

func (u *ALUImpl) LDS() []byte

LDS returns lds

func (*ALUImpl) Run

func (u *ALUImpl) Run(state InstEmuState)

Run executes the instruction in the scatchpad of the InstEmuState

func (*ALUImpl) SetLDS

func (u *ALUImpl) SetLDS(lds []byte)

SetLDS assigns the LDS storage to be used in the following instructions.

type ComputeUnit

type ComputeUnit struct {
	*sim.TickingComponent

	LDSStorage []byte

	GlobalMemStorage *mem.Storage

	ToDispatcher sim.Port
	// contains filtered or unexported fields
}

A ComputeUnit in the emu package is a component that omit the pipeline design but can still run the GCN3 instructions.

ToDispatcher <=> The port that connect the CU with the dispatcher

func BuildComputeUnit

func BuildComputeUnit(
	name string,
	engine sim.Engine,
	decoder Decoder,
	pageTable vm.PageTable,
	log2PageSize uint64,
	storage *mem.Storage,
	addrConverter idealmemcontroller.AddressConverter,
) *ComputeUnit

BuildComputeUnit build a compute unit

func NewComputeUnit

func NewComputeUnit(
	name string,
	engine sim.Engine,
	decoder Decoder,
	scratchpadPreparer ScratchpadPreparer,
	alu ALU,
	sAccessor *storageAccessor,
) *ComputeUnit

NewComputeUnit creates a new ComputeUnit with the given name

func (*ComputeUnit) ControlPort

func (cu *ComputeUnit) ControlPort() sim.Port

ControlPort returns the port that can receive controlling messages from the Command Processor.

func (*ComputeUnit) DispatchingPort

func (cu *ComputeUnit) DispatchingPort() sim.Port

DispatchingPort returns the port that the dispatcher can use to dispatch work-groups to the CU.

func (*ComputeUnit) Handle

func (cu *ComputeUnit) Handle(evt sim.Event) error

Handle defines the behavior on event scheduled on the ComputeUnit

func (*ComputeUnit) LDSBytes

func (cu *ComputeUnit) LDSBytes() int

LDSBytes returns the number of bytes in the LDS of the CU.

func (*ComputeUnit) SRegCount

func (cu *ComputeUnit) SRegCount() int

SRegCount returns the number of scalar register in the Compute Unit.

func (*ComputeUnit) Tick

func (cu *ComputeUnit) Tick(now sim.VTimeInSec) bool

Tick ticks

func (*ComputeUnit) VRegCounts

func (cu *ComputeUnit) VRegCounts() []int

VRegCounts returns an array of the numbers of vector regsiters in each SIMD unit.

func (*ComputeUnit) WfPoolSizes

func (cu *ComputeUnit) WfPoolSizes() []int

WfPoolSizes returns an array of the numbers of wavefronts that each SIMD unit can execute.

type DSLayout

type DSLayout struct {
	EXEC  uint64
	ADDR  [64]uint32
	DATA  [256]uint32
	DATA1 [256]uint32
	DST   [256]uint32
}

DSLayout represents the scratchpad layout for DS instructions

type Decoder

type Decoder interface {
	Decode(buf []byte) (*insts.Inst, error)
}

Decoder defines the interface that can convert instruction bytes to instructions

type FlatLayout

type FlatLayout struct {
	EXEC uint64
	ADDR [64]uint64
	DATA [256]uint32 // 256 to consider the X4 instructions
	DST  [256]uint32
}

FlatLayout represents the scratchpad layout for Flat instructions

type ISADebugger

type ISADebugger struct {
	sim.LogHookBase
	// contains filtered or unexported fields
}

ISADebugger is a hook that hooks to a emulator computeunit for each intruction

func NewISADebugger

func NewISADebugger(logger *log.Logger) *ISADebugger

NewISADebugger returns a new ISADebugger that keeps instruction log in logger

func (*ISADebugger) Func

func (h *ISADebugger) Func(ctx sim.HookCtx)

Func defines the behavior of the tracer when the tracer is invoked.

type InstEmuState

type InstEmuState interface {
	PID() ca.PID
	Inst() *insts.Inst
	Scratchpad() Scratchpad
}

InstEmuState is the interface used by the emulator to track the instruction execution status.

type SMEMLayout

type SMEMLayout struct {
	DATA   [4]uint32  // 0:16
	Offset uint64     // 16:24
	Base   uint64     // 24:32
	DST    [16]uint32 // 32:96
}

SMEMLayout reqpresents the scratchpad layout for SMEM instructions

type SOP1Layout

type SOP1Layout struct {
	SRC0 uint64
	DST  uint64
	EXEC uint64
	SCC  byte
	PC   uint64
}

SOP1Layout represents the scratchpad layout for SOP1 instructions

type SOP2Layout

type SOP2Layout struct {
	SRC0 uint64
	SRC1 uint64
	DST  uint64
	SCC  byte
}

SOP2Layout represents the scratchpad layout for SOP2 instructions

type SOPCLayout

type SOPCLayout struct {
	SRC0 uint64
	SRC1 uint64
	SCC  byte
}

SOPCLayout represents the scratchpad layout for SOPC instructions

type SOPKLayout

type SOPKLayout struct {
	DST uint64
	IMM uint64
	SCC byte
}

SOPKLayout represents the scratchpad layout for SOPK instructions

type SOPPLayout

type SOPPLayout struct {
	EXEC uint64
	PC   uint64
	IMM  uint64
	SCC  byte
	VCC  uint64
}

SOPPLayout reqpresents the scratchpad layout for SOPP instructions

type Scratchpad

type Scratchpad []byte

Scratchpad is a piece of pure memory that is use for the alu to store input and output data

func (Scratchpad) AsDS

func (sp Scratchpad) AsDS() *DSLayout

AsDS returns the ScratchPad as a struct representing the DS scratchpad layout

func (Scratchpad) AsFlat

func (sp Scratchpad) AsFlat() *FlatLayout

AsFlat returns the ScratchPad as a struct representing the Flat scratchpad layout

func (Scratchpad) AsSMEM

func (sp Scratchpad) AsSMEM() *SMEMLayout

AsSMEM returns the ScratchPad as a struct representing the SMEM scratchpad layout

func (Scratchpad) AsSOP1

func (sp Scratchpad) AsSOP1() *SOP1Layout

AsSOP1 returns the ScratchPad as a struct representing the SOP1 scratchpad layout

func (Scratchpad) AsSOP2

func (sp Scratchpad) AsSOP2() *SOP2Layout

AsSOP2 returns the ScratchPad as a struct representing the SOP2 scratchpad layout

func (Scratchpad) AsSOPC

func (sp Scratchpad) AsSOPC() *SOPCLayout

AsSOPC returns the ScratchPad as a struct representing the SOPC scratchpad layout

func (Scratchpad) AsSOPK

func (sp Scratchpad) AsSOPK() *SOPKLayout

AsSOPK returns the ScratchPad as a struct representing the SOPK scratchpad layout

func (Scratchpad) AsSOPP

func (sp Scratchpad) AsSOPP() *SOPPLayout

AsSOPP returns the ScratchPad as a struct representing the SOPP scratchpad layout

func (Scratchpad) AsVOP1

func (sp Scratchpad) AsVOP1() *VOP1Layout

AsVOP1 returns the ScratchPad as a struct representing the VOP1 scratchpad layout

func (Scratchpad) AsVOP2

func (sp Scratchpad) AsVOP2() *VOP2Layout

AsVOP2 returns the ScratchPad as a struct representing the VOP1 scratchpad layout

func (Scratchpad) AsVOP3A

func (sp Scratchpad) AsVOP3A() *VOP3ALayout

AsVOP3A returns the ScratchPad as a struct representing the VOP3a scratchpad layout

func (Scratchpad) AsVOP3B

func (sp Scratchpad) AsVOP3B() *VOP3BLayout

AsVOP3B returns the ScratchPad as a struct representing the VOP3a scratchpad layout

func (Scratchpad) AsVOPC

func (sp Scratchpad) AsVOPC() *VOPCLayout

AsVOPC returns the ScratchPad as a struct representing the VOPC scratchpad layout

type ScratchpadPreparer

type ScratchpadPreparer interface {
	// Prepare reads from the register file and write into the instruction
	// scratchpad
	Prepare(instEmuState InstEmuState, wf *Wavefront)

	// Commit write to the register file to reflect the change in the scratchpad
	Commit(instEmuState InstEmuState, wf *Wavefront)
}

ScratchpadPreparer is the unit that sets the instruction scratchpad before the instruction can be emulated.

type ScratchpadPreparerImpl

type ScratchpadPreparerImpl struct {
}

ScratchpadPreparerImpl reads and write registers for the emulator

func NewScratchpadPreparerImpl

func NewScratchpadPreparerImpl() *ScratchpadPreparerImpl

NewScratchpadPreparerImpl returns a newly created ScratchpadPreparerImpl, injecting the dependency of the RegInterface.

func (*ScratchpadPreparerImpl) Commit

func (p *ScratchpadPreparerImpl) Commit(
	instEmuState InstEmuState,
	wf *Wavefront,
)

Commit write to the register file according to the scratchpad layout

func (*ScratchpadPreparerImpl) Prepare

func (p *ScratchpadPreparerImpl) Prepare(
	instEmuState InstEmuState,
	wf *Wavefront,
)

Prepare read from the register file and sets the scratchpad layout

type VOP1Layout

type VOP1Layout struct {
	EXEC uint64
	DST  [64]uint64
	VCC  uint64
	SRC0 [64]uint64
}

VOP1Layout represents the scratchpad layout for VOP1 instructions

type VOP2Layout

type VOP2Layout struct {
	EXEC            uint64
	DST             [64]uint64
	VCC             uint64
	SRC0            [64]uint64
	SRC1            [64]uint64
	LiteralConstant uint64
}

VOP2Layout represents the scratchpad layout for VOP2 instructions

type VOP3ALayout

type VOP3ALayout struct {
	EXEC uint64
	DST  [64]uint64
	VCC  uint64
	SRC0 [64]uint64
	SRC1 [64]uint64
	SRC2 [64]uint64
}

VOP3ALayout represents the scratchpad layout for VOP3a instructions

type VOP3BLayout

type VOP3BLayout struct {
	EXEC uint64
	DST  [64]uint64
	VCC  uint64
	SRC0 [64]uint64
	SRC1 [64]uint64
	SRC2 [64]uint64
	SDST uint64
}

VOP3BLayout represents the scratchpad layout for VOP3a instructions

type VOPCLayout

type VOPCLayout struct {
	EXEC uint64
	VCC  uint64
	SRC0 [64]uint64
	SRC1 [64]uint64
}

VOPCLayout represents the scratchpad layout for the VOPC instructions

type WGCompleteEvent

type WGCompleteEvent struct {
	*sim.EventBase

	Req *protocol.MapWGReq
}

WGCompleteEvent is an event that marks the completion of a work-group

func NewWGCompleteEvent

func NewWGCompleteEvent(t sim.VTimeInSec, handler sim.Handler,
	req *protocol.MapWGReq,
) *WGCompleteEvent

NewWGCompleteEvent returns a newly constructed WGCompleteEvent

type Wavefront

type Wavefront struct {
	*kernels.Wavefront

	Completed bool
	AtBarrier bool

	PC       uint64
	Exec     uint64
	SCC      byte
	VCC      uint64
	M0       uint32
	SRegFile []byte
	VRegFile []byte
	LDS      []byte
	// contains filtered or unexported fields
}

A Wavefront in the emu package is a wrapper for the kernels.Wavefront

func NewWavefront

func NewWavefront(nativeWf *kernels.Wavefront) *Wavefront

NewWavefront returns the Wavefront that wraps the nativeWf

func (*Wavefront) Inst

func (wf *Wavefront) Inst() *insts.Inst

Inst returns the instruction that the wavefront is executing

func (*Wavefront) PID

func (wf *Wavefront) PID() ca.PID

PID returns pid

func (*Wavefront) ReadReg

func (wf *Wavefront) ReadReg(reg *insts.Reg, regCount int, laneID int) []byte

ReadReg returns the raw register value

func (*Wavefront) SRegValue

func (wf *Wavefront) SRegValue(i int) uint32

SRegValue returns s(i)'s value

func (*Wavefront) Scratchpad

func (wf *Wavefront) Scratchpad() Scratchpad

Scratchpad returns the scratchpad that is associated with the wavefront

func (*Wavefront) VRegValue

func (wf *Wavefront) VRegValue(lane int, i int) uint32

VRegValue returns the value of v(i) of a certain lain

func (*Wavefront) WriteReg

func (wf *Wavefront) WriteReg(
	reg *insts.Reg,
	regCount int,
	laneID int,
	data []byte,
)

WriteReg returns the raw register value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL