Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support a Separate GMMU Page Table #109

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"program": "${workspaceFolder}/samples/fir",
"args": [
"-timing",
"-length=8192",
"-length=81920",
"-report-all",
],
},
Expand Down
9 changes: 8 additions & 1 deletion driver/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Builder struct {
useMagicMemoryCopy bool
middlewareD2HCycles int
middlewareH2DCycles int
memorySize uint64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name this one as cpuMemorySize to avoid confusion?

}

// MakeBuilder creates a driver builder with some default configuration
Expand Down Expand Up @@ -74,6 +75,12 @@ func (b Builder) WithH2DCycles(h2dCycles int) Builder {
return b
}

// WithMemorySize sets the memory size of the CPU.
func (b Builder) WithMemorySize(memorySize uint64) Builder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, since this is for CPU, can we just say WithCPUMemorySize?

b.memorySize = memorySize
return b
}

// Build creates a driver.
func (b Builder) Build(name string) *Driver {
driver := new(Driver)
Expand Down Expand Up @@ -125,7 +132,7 @@ func (b *Builder) createCPU(d *Driver) {
Type: internal.DeviceTypeCPU,
MemState: internal.NewDeviceMemoryState(d.Log2PageSize),
}
cpu.SetTotalMemSize(4 * mem.GB)
cpu.SetTotalMemSize(b.memorySize)

d.memAllocator.RegisterDevice(cpu)
d.devices = append(d.devices, cpu)
Expand Down
12 changes: 11 additions & 1 deletion driver/driver.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package driver

import (
"fmt"
"log"
"reflect"
"runtime/debug"
Expand Down Expand Up @@ -142,6 +143,7 @@ type DeviceProperties struct {
func (d *Driver) RegisterGPU(
commandProcessorPort sim.Port,
properties DeviceProperties,
gmmuPageTable vm.PageTable,
) {
d.GPUs = append(d.GPUs, commandProcessorPort)

Expand All @@ -156,8 +158,13 @@ func (d *Driver) RegisterGPU(
}
gpuDevice.SetTotalMemSize(properties.DRAMSize)
d.memAllocator.RegisterDevice(gpuDevice)

d.devices = append(d.devices, gpuDevice)

for _, page := range d.memAllocator.GetVAddrToPageMapping() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required? I think, at the beginning, no page has already been allocated.

if page.DeviceID == uint64(gpuDevice.ID) {
gmmuPageTable.Insert(page)
}
}
}

// Tick ticks
Expand Down Expand Up @@ -455,6 +462,9 @@ func (d *Driver) distributeWGToGPUs(
panic("not all wg allocated")
}

// fmt.Sprintln("total WG: %d WG Per CU %d\n", totalWGCount, wgPerCU)
fmt.Printf("total WG: %d WG Per CU %d\n", totalWGCount, wgPerCU)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove prints


return wgDist
}

Expand Down
12 changes: 12 additions & 0 deletions driver/internal/memoryallocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type MemoryAllocator interface {
vAddr uint64,
unified bool,
) vm.Page

GetVAddrToPageMapping() map[uint64]vm.Page
}

// NewMemoryAllocator creates a new memory allocator.
Expand Down Expand Up @@ -285,3 +287,13 @@ 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 link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About empty lines. Please consider these general rules. 1. Add an empty line after defer. 2. Add an empty line before if and for. 3 Add an empty line before return.

copy[vAddr] = page
}
return copy
}
6 changes: 3 additions & 3 deletions timing/cp/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func (b Builder) Build(name string) *CommandProcessor {
tracing.CollectTrace(cp, b.visTracer)
}

if b.perfAnalyzer != nil {
b.perfAnalyzer.RegisterComponent(cp)
}
// if b.perfAnalyzer != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there some problem with perfAnalyzer? If not, let's do not comment it out.

// b.perfAnalyzer.RegisterComponent(cp)
// }

return cp
}
Expand Down
Loading