Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial accelsim traing branch #28

Merged
merged 10 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@
"program": "${workspaceFolder}/samples/fir",
"args": [
"-timing",
"-length=64",
"-length=8192",
"-report-all",
"-gpus=1,2",
"-use-unified-memory=false",
],
},
{
Expand Down
3 changes: 3 additions & 0 deletions accelsim_tracing/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accelsim_tracing
output/
example/
Binary file added accelsim_tracing/README.md
Binary file not shown.
17 changes: 17 additions & 0 deletions accelsim_tracing/alu/alu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package alu

import "github.com/sarchlab/mgpusim/v3/accelsim_tracing/nvidia"

type ALU interface {
withParent(aluGroup *ALUGroup) ALU
Execute(inst nvidia.Instruction)
}

func (a *ALUGroup) newALU() ALU {
switch a.meta.aluType {
case "int32":
return newInt32ALU().withParent(a)
default:
panic("Unknown ALU type")
}
}
45 changes: 45 additions & 0 deletions accelsim_tracing/alu/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package alu

import "github.com/sarchlab/mgpusim/v3/accelsim_tracing/nvidia"

type ALUGroup struct {
meta *aluGroupMetaData
alus []ALU
}

type aluGroupMetaData struct {
aluType string
aluNum int32
}

func NewALUGroup() *ALUGroup {
return &ALUGroup{
meta: &aluGroupMetaData{
aluType: "undefined",
aluNum: 0,
},
}
}

func (a *ALUGroup) WithALUType(aluType string) *ALUGroup {
a.meta.aluType = aluType
return a
}

func (a *ALUGroup) WithALUNum(num int32) *ALUGroup {
a.meta.aluNum = num
return a
}

func (a *ALUGroup) Build() {
a.alus = make([]ALU, a.meta.aluNum)
for i := range a.alus {
a.alus[i] = a.newALU()
}
}

func (a *ALUGroup) Execute(inst nvidia.Instruction) {
for _, alu := range a.alus {
alu.Execute(inst)
}
}
2 changes: 2 additions & 0 deletions accelsim_tracing/alu/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package alu contains the ALU implementation
package alu
19 changes: 19 additions & 0 deletions accelsim_tracing/alu/int32.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package alu

import "github.com/sarchlab/mgpusim/v3/accelsim_tracing/nvidia"

type int32ALU struct {
parent *ALUGroup
}

func newInt32ALU() *int32ALU {
return &int32ALU{}
}

func (a *int32ALU) withParent(aluGroup *ALUGroup) ALU {
a.parent = aluGroup
return a
}

func (a *int32ALU) Execute(inst nvidia.Instruction) {
}
45 changes: 45 additions & 0 deletions accelsim_tracing/benchmark/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package benchmark

import (
"errors"

"github.com/sarchlab/mgpusim/v3/accelsim_tracing/gpu"
"github.com/sarchlab/mgpusim/v3/accelsim_tracing/trace"
)

type BenchMark struct {
fromTrace bool
traceDirPath string
trace *trace.Trace
}

func NewBenchMark() *BenchMark {
return &BenchMark{
fromTrace: false,
traceDirPath: "",
trace: nil,
}
}

func (bm *BenchMark) WithTraceDirPath(path string) *BenchMark {
bm.traceDirPath = path
bm.fromTrace = true
return bm
}

func (bm *BenchMark) Build() error {
if bm.fromTrace == false {
return errors.New("no trace dir path specified")
}
bm.trace = trace.NewTrace().WithTraceDirPath(bm.traceDirPath)
bm.trace.Build()
return nil
}

func (bm *BenchMark) Exec(gpu *gpu.GPU) error {
if bm.fromTrace == false {
panic("No trace dir path specified")
}
err := bm.trace.Exec(gpu)
return err
}
2 changes: 2 additions & 0 deletions accelsim_tracing/benchmark/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package benchmark contains the driver which links traces and the simulator
package benchmark
142 changes: 142 additions & 0 deletions accelsim_tracing/gpc/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package gpc

import (
"github.com/sarchlab/mgpusim/v3/accelsim_tracing/nvidia"
"github.com/sarchlab/mgpusim/v3/accelsim_tracing/sm"
)

type GPC struct {
meta *gpcMetaData
dispatcher gpcDispatcher
sms []*sm.SM
}

type gpcMetaData struct {
smNum int32
smUnitNum int32

gpcStrategy string
smStrategy string
smUnitStrategy string

l2CacheSize int32
l1CacheSize int32
l0CacheSize int32

registerFileSize int32
laneSize int32

alus []struct {
aluType string
aluNum int32
}
}

func NewGPC() *GPC {
return &GPC{
meta: &gpcMetaData{
smNum: 0,
smUnitNum: 0,

gpcStrategy: "default",
smStrategy: "default",
smUnitStrategy: "default",

l2CacheSize: 0,
l1CacheSize: 0,
l0CacheSize: 0,

registerFileSize: 0,
laneSize: 0,

alus: nil,
},
dispatcher: nil,
sms: nil,
}
}

func (g *GPC) WithSMNum(num int32) *GPC {
g.meta.smNum = num
return g
}

func (g *GPC) WithGPCStrategy(strategy string) *GPC {
g.meta.gpcStrategy = strategy
return g
}

func (g *GPC) WithSMUnitNum(num int32) *GPC {
g.meta.smUnitNum = num
return g
}

func (g *GPC) WithSMStrategy(strategy string) *GPC {
g.meta.smStrategy = strategy
return g
}

func (g *GPC) WithSMUnitStrategy(strategy string) *GPC {
g.meta.smUnitStrategy = strategy
return g
}

func (g *GPC) WithL2CacheSize(size int32) *GPC {
g.meta.l2CacheSize = size
return g
}

func (g *GPC) WithL1CacheSize(size int32) *GPC {
g.meta.l1CacheSize = size
return g
}

func (g *GPC) WithL0CacheSize(size int32) *GPC {
g.meta.l0CacheSize = size
return g
}

func (g *GPC) WithRegisterFileSize(size int32) *GPC {
g.meta.registerFileSize = size
return g
}

func (g *GPC) WithLaneSize(size int32) *GPC {
g.meta.laneSize = size
return g
}

func (g *GPC) WithALU(aluType string, num int32) *GPC {
g.meta.alus = append(g.meta.alus, struct {
aluType string
aluNum int32
}{aluType: aluType, aluNum: num})
return g
}

func (g *GPC) Build() {
g.buildDispatcher()
g.sms = make([]*sm.SM, g.meta.smNum)
for i := 0; i < int(g.meta.smNum); i++ {
g.sms[i] = sm.NewSM().
WithSMStrategy(g.meta.smStrategy).
WithSMUnitNum(g.meta.smUnitNum).
WithSMUnitStrategy(g.meta.smUnitStrategy).
WithL1CacheSize(g.meta.l1CacheSize).
WithL0CacheSize(g.meta.l0CacheSize).
WithRegisterFileSize(g.meta.registerFileSize).
WithLaneSize(g.meta.laneSize)
for _, alu := range g.meta.alus {
g.sms[i].WithALU(alu.aluType, alu.aluNum)
}
g.sms[i].Build()
}
}

func (g *GPC) IsFree() bool {
return true
}

func (g *GPC) Execute(tb *nvidia.ThreadBlock) {
g.dispatcher.dispatch(tb)
}
32 changes: 32 additions & 0 deletions accelsim_tracing/gpc/default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package gpc

import "github.com/sarchlab/mgpusim/v3/accelsim_tracing/nvidia"

type defaultDispatcher struct {
parent *GPC
}

func newDefaultDispatcher() *defaultDispatcher {
return &defaultDispatcher{}
}

func (d *defaultDispatcher) withParent(gpc *GPC) gpcDispatcher {
d.parent = gpc
return d
}

func (d *defaultDispatcher) dispatch(tb *nvidia.ThreadBlock) {
for {
flag := false
for _, sm := range d.parent.sms {
if sm.IsFree() {
sm.Execute(tb)
flag = true
break
}
}
if flag {
break
}
}
}
17 changes: 17 additions & 0 deletions accelsim_tracing/gpc/dispatcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package gpc

import "github.com/sarchlab/mgpusim/v3/accelsim_tracing/nvidia"

type gpcDispatcher interface {
withParent(gpc *GPC) gpcDispatcher
dispatch(tb *nvidia.ThreadBlock)
}

func (g *GPC) buildDispatcher() {
switch g.meta.gpcStrategy {
case "default":
g.dispatcher = newDefaultDispatcher().withParent(g)
default:
panic("Unknown dispatcher strategy")
}
}
2 changes: 2 additions & 0 deletions accelsim_tracing/gpc/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package gpc implements the simulation components for the GPC Level.
package gpc
Loading
Loading