Skip to content

Commit

Permalink
use drse drinst(gpu,trace) instead of trace(gpu)
Browse files Browse the repository at this point in the history
  • Loading branch information
gongchen618 committed Dec 13, 2023
1 parent 520d885 commit 9122028
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 171 deletions.
45 changes: 0 additions & 45 deletions accelsim_tracing/benchmark/build.go

This file was deleted.

2 changes: 0 additions & 2 deletions accelsim_tracing/benchmark/doc.go

This file was deleted.

49 changes: 49 additions & 0 deletions accelsim_tracing/driver/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package driver

import (
"errors"

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

type Driver struct {
benchmark *Benchmark
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")
} else if d.gpu == nil {
return errors.New("no gpu specified")
}

for _, e := range *d.benchmark.TraceExecs {
err := e.Exec(d.gpu)
if err != nil {
return err
}
}
return nil
}
2 changes: 2 additions & 0 deletions accelsim_tracing/driver/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package driver contains the driver which links traces and the simulator
package driver
36 changes: 36 additions & 0 deletions accelsim_tracing/driver/trace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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
}
89 changes: 89 additions & 0 deletions accelsim_tracing/trace/builder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package trace

import (
"bufio"
"fmt"
"log"
"os"
"path"
"strings"

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

type TraceParser struct {
traceDirPath string
traceExecs []TraceExecs
}

type TraceExecs interface {
Type() string
Exec(*gpu.GPU) error
}

func NewTraceParser(path string) *TraceParser {
return &TraceParser{
traceDirPath: path,
traceExecs: nil,
}
}

func (t *TraceParser) BuildTraceExecutions() *[]TraceExecs {
lines := readKernelsList(t.traceDirPath)

for _, line := range lines {
te := parseListToTraceExecs(line, t)
t.traceExecs = append(t.traceExecs, te)
}

return &t.traceExecs
}

func readKernelsList(dirPath string) []string {
filePath := path.Join(dirPath, "kernelslist.g")
file, err := os.Open(filePath)
if err != nil {
log.Panic(err)
}
defer file.Close()

var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if scanner.Text() != "" {
lines = append(lines, scanner.Text())
}
}

return lines
}

func parseListToTraceExecs(rawText string, trace *TraceParser) TraceExecs {
if strings.HasPrefix(rawText, "Memcpy") {
/*
format : H2D or D2H, start, length
example : HtoD,0x7f0,0x1000
*/
res := strings.Split(rawText, ",")
m := &memCopy{
rawText: rawText,
h2d: strings.Contains(res[0], "HtoD"),
}
fmt.Sscanf(res[1], "%v", &m.startAddr)
fmt.Sscanf(res[2], "%v", &m.length)
return m
} else if strings.HasPrefix(rawText, "kernel") {
/*
format : kernel name
example : kernel_0
*/
k := &kernel{
rawText: rawText,
fileName: rawText,
filePath: path.Join(trace.traceDirPath, rawText),
}
return k
}
log.Panicf("Unknown trace group rawText: %s", rawText)
return nil
}
11 changes: 5 additions & 6 deletions accelsim_tracing/trace/kernel.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package trace

import (
"path"

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

type kernel struct { // trace execs interface
parent *Trace

rawText string
fileName string
filePath string
traceGroup *traceGroup
}
Expand All @@ -18,9 +15,11 @@ func (te *kernel) Type() string {
return "kernel"
}

func (te *kernel) Execute(gpu *gpu.GPU) error {
tg := NewTraceGroup().WithFilePath(path.Join(te.parent.traceDirPath, te.filePath))
func (te *kernel) Exec(gpu *gpu.GPU) error {
tg := NewTraceGroup().WithFilePath(te.filePath)
tg.Build()

err := tg.Exec(gpu)

return err
}
13 changes: 6 additions & 7 deletions accelsim_tracing/trace/memory_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ package trace
import "github.com/sarchlab/mgpusim/v3/accelsim_tracing/gpu"

type memCopy struct { // trace execs interface
parent *Trace

rawText string
h2d bool
startAddr uint64
length uint64
}

type memCopyParent struct {
trace *Trace
}

func (te *memCopy) Type() string {
return "memcopy"
}

func (te *memCopy) Execute(gpu *gpu.GPU) error {
func (te *memCopy) File() string {
return ""
}

func (te *memCopy) Exec(g *gpu.GPU) error {
// [todo] implement
return nil
}
63 changes: 0 additions & 63 deletions accelsim_tracing/trace/trace.go

This file was deleted.

45 changes: 0 additions & 45 deletions accelsim_tracing/trace/trace_execs.go

This file was deleted.

Loading

0 comments on commit 9122028

Please sign in to comment.