Skip to content

Commit

Permalink
added fixed latency to memcopy
Browse files Browse the repository at this point in the history
  • Loading branch information
nichosta committed Mar 6, 2024
1 parent 0f79e32 commit 0090874
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
4 changes: 3 additions & 1 deletion driver/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ func (b Builder) Build(name string) *Driver {
driver.middlewares = append(driver.middlewares, globalStorageMemoryCopyMiddleware)
} else {
defaultMemoryCopyMiddleware := &defaultMemoryCopyMiddleware{
driver: driver,
driver: driver,
cyclesPerD2H: 8500,
cyclesPerH2D: 14500,
}
driver.middlewares = append(driver.middlewares, defaultMemoryCopyMiddleware)
}
Expand Down
34 changes: 29 additions & 5 deletions driver/memorycopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import (
// communication.
type defaultMemoryCopyMiddleware struct {
driver *Driver

cyclesPerH2D int
cyclesPerD2H int
cyclesLeft int

awaitingReqs []sim.Msg
}

func (m *defaultMemoryCopyMiddleware) ProcessCommand(
Expand Down Expand Up @@ -67,7 +73,8 @@ func (m *defaultMemoryCopyMiddleware) processMemCopyH2DCommand(
rawBytes[offset:offset+sizeToCopy],
pAddr)
cmd.Reqs = append(cmd.Reqs, req)
m.driver.requestsToSend = append(m.driver.requestsToSend, req)
m.awaitingReqs = append(m.awaitingReqs, req)
// m.driver.requestsToSend = append(m.driver.requestsToSend, req)

sizeLeft -= sizeToCopy
addr += sizeToCopy
Expand All @@ -76,6 +83,8 @@ func (m *defaultMemoryCopyMiddleware) processMemCopyH2DCommand(
m.driver.logTaskToGPUInitiate(now, cmd, req)
}

m.cyclesLeft = m.cyclesPerH2D

queue.IsRunning = true

return true
Expand Down Expand Up @@ -114,7 +123,8 @@ func (m *defaultMemoryCopyMiddleware) processMemCopyD2HCommand(
m.driver.gpuPort, m.driver.GPUs[gpuID-1],
pAddr, cmd.RawData[offset:offset+sizeToCopy])
cmd.Reqs = append(cmd.Reqs, req)
m.driver.requestsToSend = append(m.driver.requestsToSend, req)
m.awaitingReqs = append(m.awaitingReqs, req)
// m.driver.requestsToSend = append(m.driver.requestsToSend, req)

sizeLeft -= sizeToCopy
addr += sizeToCopy
Expand All @@ -123,6 +133,8 @@ func (m *defaultMemoryCopyMiddleware) processMemCopyD2HCommand(
m.driver.logTaskToGPUInitiate(now, cmd, req)
}

m.cyclesLeft = m.cyclesPerD2H

queue.IsRunning = true
return true
}
Expand Down Expand Up @@ -177,17 +189,29 @@ func (m *defaultMemoryCopyMiddleware) sendFlushRequest(
func (m *defaultMemoryCopyMiddleware) Tick(
now sim.VTimeInSec,
) (madeProgress bool) {
madeProgress = false

if m.cyclesLeft > 0 {
m.cyclesLeft--
madeProgress = true
} else if m.cyclesLeft == 0 {
m.driver.requestsToSend = append(m.driver.requestsToSend, m.awaitingReqs...)
m.awaitingReqs = nil
m.cyclesLeft = -1
madeProgress = true
}

req := m.driver.gpuPort.Peek()
if req == nil {
return false
return madeProgress
}

switch req := req.(type) {
case *sim.GeneralRsp:
return m.processGeneralRsp(now, req)
madeProgress = m.processGeneralRsp(now, req)
}

return false
return madeProgress
}

func (m *defaultMemoryCopyMiddleware) processGeneralRsp(
Expand Down

0 comments on commit 0090874

Please sign in to comment.