From 86bde557a3d4b3b09ada827700b6ddada56f1194 Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Fri, 26 Jan 2024 12:31:05 +0000 Subject: [PATCH] fix the driver pattern --- accelsim_tracing/driver/benchmark.go | 10 +++++ accelsim_tracing/driver/benchmark_builder.go | 37 +++++++++++++++++++ .../driver/{build.go => driver.go} | 21 ----------- accelsim_tracing/driver/driver_builder.go | 32 ++++++++++++++++ accelsim_tracing/driver/trace.go | 36 ------------------ accelsim_tracing/gpu/gpu_builder.go | 4 +- accelsim_tracing/tracer.go | 33 +++++++++-------- 7 files changed, 98 insertions(+), 75 deletions(-) create mode 100644 accelsim_tracing/driver/benchmark.go create mode 100644 accelsim_tracing/driver/benchmark_builder.go rename accelsim_tracing/driver/{build.go => driver.go} (61%) create mode 100644 accelsim_tracing/driver/driver_builder.go delete mode 100644 accelsim_tracing/driver/trace.go diff --git a/accelsim_tracing/driver/benchmark.go b/accelsim_tracing/driver/benchmark.go new file mode 100644 index 00000000..69719c2e --- /dev/null +++ b/accelsim_tracing/driver/benchmark.go @@ -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 +} diff --git a/accelsim_tracing/driver/benchmark_builder.go b/accelsim_tracing/driver/benchmark_builder.go new file mode 100644 index 00000000..df28824e --- /dev/null +++ b/accelsim_tracing/driver/benchmark_builder.go @@ -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 +} diff --git a/accelsim_tracing/driver/build.go b/accelsim_tracing/driver/driver.go similarity index 61% rename from accelsim_tracing/driver/build.go rename to accelsim_tracing/driver/driver.go index d4e0d23b..7050229a 100644 --- a/accelsim_tracing/driver/build.go +++ b/accelsim_tracing/driver/driver.go @@ -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") diff --git a/accelsim_tracing/driver/driver_builder.go b/accelsim_tracing/driver/driver_builder.go new file mode 100644 index 00000000..34708e2c --- /dev/null +++ b/accelsim_tracing/driver/driver_builder.go @@ -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 +} diff --git a/accelsim_tracing/driver/trace.go b/accelsim_tracing/driver/trace.go deleted file mode 100644 index 98cb5851..00000000 --- a/accelsim_tracing/driver/trace.go +++ /dev/null @@ -1,36 +0,0 @@ -package driver - -import ( - "errors" - - trace "github.com/sarchlab/mgpusim/v3/accelsim_tracing/trace" -) - -type Benchmark struct { - fromTrace bool - traceDirPath string - traceParser *trace.TraceParser - TraceExecs *[]trace.TraceExecs -} - -func NewBenchmark() *Benchmark { - return &Benchmark{ - fromTrace: false, - traceDirPath: "", - } -} - -func (b *Benchmark) WithTraceDirPath(path string) *Benchmark { - b.traceDirPath = path - b.fromTrace = true - return b -} - -func (b *Benchmark) Build() error { - if !b.fromTrace { - return errors.New("no trace dir path specified") - } - b.traceParser = trace.NewTraceParser(b.traceDirPath) - b.TraceExecs = b.traceParser.BuildTraceExecutions() - return nil -} diff --git a/accelsim_tracing/gpu/gpu_builder.go b/accelsim_tracing/gpu/gpu_builder.go index d7631a09..b4c6c1f0 100644 --- a/accelsim_tracing/gpu/gpu_builder.go +++ b/accelsim_tracing/gpu/gpu_builder.go @@ -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) @@ -112,7 +112,7 @@ func (g *GPUBuilder) Build() *GPU { WithALUConfig("int32", g.aluInt32CntPerSMUnit). Build() } - return gpu + return gpu, nil } func (g *GPUBuilder) buildDispatcher() GPUDispatcher { diff --git a/accelsim_tracing/tracer.go b/accelsim_tracing/tracer.go index c95c3a33..54ea8f1d 100644 --- a/accelsim_tracing/tracer.go +++ b/accelsim_tracing/tracer.go @@ -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). @@ -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 }