Skip to content

Commit

Permalink
create seperate gmmu pagetable
Browse files Browse the repository at this point in the history
  • Loading branch information
YuWei-CH committed Dec 2, 2024
1 parent 8233188 commit 7917540
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 27 deletions.
8 changes: 1 addition & 7 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ type DeviceProperties struct {
func (d *Driver) RegisterGPU(
commandProcessorPort sim.Port,
properties DeviceProperties,
gmmuPageTable vm.PageTable,
) {
d.GPUs = append(d.GPUs, commandProcessorPort)

Expand All @@ -154,16 +153,11 @@ func (d *Driver) RegisterGPU(
CUCount: properties.CUCount,
DRAMSize: properties.DRAMSize,
},
pageTable: vm.PageTable,
}
gpuDevice.SetTotalMemSize(properties.DRAMSize)
d.memAllocator.RegisterDevice(gpuDevice)
d.devices = append(d.devices, gpuDevice)

for _, page := range d.memAllocator.GetVAddrToPageMapping() {
if page.DeviceID == uint64(gpuDevice.ID) {
gmmuPageTable.Insert(page)
}
}
}

// Tick ticks
Expand Down
3 changes: 3 additions & 0 deletions driver/internal/device.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package internal

import "github.com/sarchlab/akita/v3/mem/vm"

// DeviceType marks the type of a device.
type DeviceType int

Expand Down Expand Up @@ -38,6 +40,7 @@ type Device struct {
nextActualGPUIndex int
MemState DeviceMemoryState
Properties DeviceProperties
pageTable vm.PageTable
}

// SetTotalMemSize sets total memory size
Expand Down
23 changes: 8 additions & 15 deletions driver/internal/memoryallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type MemoryAllocator interface {
vAddr uint64,
unified bool,
) vm.Page
GetVAddrToPageMapping() map[uint64]vm.Page
}

// NewMemoryAllocator creates a new memory allocator.
Expand Down Expand Up @@ -65,6 +64,7 @@ func (a *memoryAllocatorImpl) RegisterDevice(device *Device) {
state := device.MemState
state.setInitialAddress(a.totalStorageByteSize)
a.totalStorageByteSize += state.getStorageSize()
device.pageTable = vm.NewPageTable(a.log2PageSize)
a.devices[device.ID] = device
}

Expand Down Expand Up @@ -162,7 +162,7 @@ func (a *memoryAllocatorImpl) allocatePages(

// fmt.Printf("page.addr is %x piage Device ID is %d \n", page.PAddr, page.DeviceID)
// debug.PrintStack()
a.pageTable.Insert(page)
device.pageTable.Insert(page)
a.vAddrToPageMapping[page.VAddr] = page
}

Expand All @@ -186,8 +186,11 @@ func (a *memoryAllocatorImpl) Remap(
vAddrs = append(vAddrs, addr)
addr += pageSize
}

a.allocateMultiplePagesWithGivenVAddrs(pid, deviceID, vAddrs, false)
device := a.devices[deviceID]
pages := a.allocateMultiplePagesWithGivenVAddrs(pid, deviceID, vAddrs, false)
for _, page := range pages {
device.pageTable.Insert(page)
}
}

func (a *memoryAllocatorImpl) RemovePage(vAddr uint64) {
Expand Down Expand Up @@ -243,8 +246,8 @@ func (a *memoryAllocatorImpl) allocatePageWithGivenVAddr(
DeviceID: uint64(deviceID),
Unified: isUnified,
}
device.pageTable.Insert(page)
a.vAddrToPageMapping[page.VAddr] = page
a.pageTable.Update(page)

return page
}
Expand Down Expand Up @@ -284,13 +287,3 @@ func (a *memoryAllocatorImpl) Free(ptr uint64) {

a.removePage(ptr)
}

func (a *memoryAllocatorImpl) GetVAddrToPageMapping() map[uint64]vm.Page {
a.Lock()
defer a.Unlock()
copy := make(map[uint64]vm.Page, len(a.vAddrToPageMapping))
for vAddr, page := range a.vAddrToPageMapping {
copy[vAddr] = page
}
return copy
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/onsi/ginkgo/v2 v2.16.0
github.com/onsi/gomega v1.31.1
github.com/rs/xid v1.5.0
github.com/sarchlab/akita/v3 v3.0.0
github.com/sarchlab/akita/v3 v3.1.0
github.com/tebeka/atexit v0.3.0
gonum.org/v1/gonum v0.14.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/sarchlab/akita/v3 v3.0.0 h1:kLRhaBpDA6yXYn5suiIFGnWJ0xr/eqGDjMTMGSwaXUM=
github.com/sarchlab/akita/v3 v3.0.0/go.mod h1:p74MfNeElTYFy9H/gwsPzZQXPfw/e87/6HiIYCZexWc=
github.com/sarchlab/akita/v3 v3.1.0 h1:pt17MC5A7NqfZKFRuE9CSQh1L50YJE+/zh2x3DBt5Ow=
github.com/sarchlab/akita/v3 v3.1.0/go.mod h1:63FwQtSD9gCrOF5XGIq4Z6md3QqBgZ5yRDI5K2nGwfA=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
3 changes: 3 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go 1.22.4

use ../akita
10 changes: 10 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/ianlancetaylor/demangle v0.0.0-20220517205856-0058ec4f073c/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
2 changes: 1 addition & 1 deletion samples/runner/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ type GPU struct {
L2TLBs []TraceableComponent
MemControllers []TraceableComponent
MMUEngine *mmu.MMU
GMMUEngine *gmmu.GMMU
GMMUEngine *gmmu.Comp
GMMUCache []TraceableComponent
}
2 changes: 1 addition & 1 deletion samples/runner/timingplatform.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func (b *R9NanoPlatformBuilder) createGPU(
driver.DeviceProperties{
CUCount: b.numCUPerSA * b.numSAPerGPU,
DRAMSize: 4 * mem.GB,
}, gpuBuilder.pageTable)
})

gpu.CommandProcessor.Driver = gpuDriver.GetPortByName("GPU")

Expand Down

0 comments on commit 7917540

Please sign in to comment.