Skip to content

Commit

Permalink
fix the driver pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
gongchen618 committed Jan 26, 2024
1 parent e2e4b6e commit 86bde55
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 75 deletions.
10 changes: 10 additions & 0 deletions accelsim_tracing/driver/benchmark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package driver

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

type Benchmark struct {
traceParser *trace.TraceParser
TraceExecs *[]trace.TraceExecs
}
37 changes: 37 additions & 0 deletions accelsim_tracing/driver/benchmark_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package driver

import (
"errors"

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

type BenchmarkBuilder struct {
fromTrace bool
traceDirPath string
}

func NewBenchmarkBuilder() *BenchmarkBuilder {
return &BenchmarkBuilder{
fromTrace: false,
traceDirPath: "",
}
}

func (b *BenchmarkBuilder) WithTraceDirPath(path string) *BenchmarkBuilder {
b.traceDirPath = path
b.fromTrace = true
return b
}

func (b *BenchmarkBuilder) Build() (*Benchmark, error) {
if !b.fromTrace {
return nil, errors.New("no trace dir path specified")
}
bm := &Benchmark{
traceParser: trace.NewTraceParser(b.traceDirPath),
TraceExecs: nil,
}
bm.TraceExecs = bm.traceParser.BuildTraceExecutions()
return bm, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@ type Driver struct {
gpu *gpu.GPU
}

func NewDriver() *Driver {
return &Driver{
benchmark: nil,
gpu: nil,
}
}

func (d *Driver) WithBenchmark(b *Benchmark) *Driver {
d.benchmark = b
return d
}

func (d *Driver) WithGPU(g *gpu.GPU) *Driver {
d.gpu = g
return d
}

func (d *Driver) Build() error {
return nil
}

func (d *Driver) Exec() error {
if d.benchmark == nil {
return errors.New("no trace parser specified")
Expand Down
32 changes: 32 additions & 0 deletions accelsim_tracing/driver/driver_builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package driver

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

type DriverBuilder struct {
benchmark *Benchmark
gpu *gpu.GPU
}

func NewDriverBuilder() *DriverBuilder {
return &DriverBuilder{
benchmark: nil,
gpu: nil,
}
}

func (d *DriverBuilder) WithBenchmark(b *Benchmark) *DriverBuilder {
d.benchmark = b
return d
}

func (d *DriverBuilder) WithGPU(g *gpu.GPU) *DriverBuilder {
d.gpu = g
return d
}

func (d *DriverBuilder) Build() (*Driver, error) {
return &Driver{
benchmark: d.benchmark,
gpu: d.gpu,
}, nil
}
36 changes: 0 additions & 36 deletions accelsim_tracing/driver/trace.go

This file was deleted.

4 changes: 2 additions & 2 deletions accelsim_tracing/gpu/gpu_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (g *GPUBuilder) WithALUConfig(aluType string, num int32) *GPUBuilder {
return g
}

func (g *GPUBuilder) Build() *GPU {
func (g *GPUBuilder) Build() (*GPU, error) {
gpu := new(GPU)
gpu.dispatcher = g.buildDispatcher()
gpu.gpcs = make([]*gpc.GPC, g.gpcCnt)
Expand All @@ -112,7 +112,7 @@ func (g *GPUBuilder) Build() *GPU {
WithALUConfig("int32", g.aluInt32CntPerSMUnit).
Build()
}
return gpu
return gpu, nil
}

func (g *GPUBuilder) buildDispatcher() GPUDispatcher {
Expand Down
33 changes: 17 additions & 16 deletions accelsim_tracing/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,21 @@ func getInputArguments() *inputArguments {
return i
}

func main() {
args := getInputArguments()

benchmarkBuilder := driver.NewBenchmarkBuilder().WithTraceDirPath(args.inputTraceDir)
myBenchmark, _ := benchmarkBuilder.Build()

myGPU := buildAmpereGPU()

driverBuilder := driver.NewDriverBuilder().WithBenchmark(myBenchmark).WithGPU(myGPU)
myDriver, _ := driverBuilder.Build()
myDriver.Exec()
}

func buildAmpereGPU() *gpu.GPU {
gpu := gpu.NewGPUBuilder().
gpuBuilder := gpu.NewGPUBuilder().
WithGPCCnt(8).
WithSMCnt(16).
WithSMUnitCnt(4).
Expand All @@ -45,19 +58,7 @@ func buildAmpereGPU() *gpu.GPU {
WithL1CacheConfig(192*1024*nvidia.BYTE).
WithL0CacheConfig(16*1024*nvidia.BYTE).
WithRegisterFileConfig(256*1024*nvidia.BYTE, 4*nvidia.BYTE).
WithALUConfig("int32", 16).
Build()
return gpu
}

func main() {
args := getInputArguments()
gpu := buildAmpereGPU()

benchmark := driver.NewBenchmark().WithTraceDirPath(args.inputTraceDir)
benchmark.Build()

driver := driver.NewDriver().WithBenchmark(benchmark).WithGPU(gpu)
driver.Build()
driver.Exec()
WithALUConfig("int32", 16)
myGPU, _ := gpuBuilder.Build()
return myGPU
}

0 comments on commit 86bde55

Please sign in to comment.