configs,gpu-compute: Add support for gfx902/Raven

This patch adds support for a gfx902 Vega APU, ripping the
appropriate values for device_id from the ROCm Thunk
(src/topology.c).

Note: gfx902 isn't officially supported by ROCm. This
means that it may not work for all programs. In particular,
rocBLAS is incompatible with gfx902, so anything that uses
rocBLAS won't be able to run with gfx902.

Change-Id: I48893e7cc9c7e52275fdfd22314f371a9db8e90a
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/47530
Reviewed-by: Matt Sinclair <mattdsinclair@gmail.com>
Reviewed-by: Matthew Poremba <matthew.poremba@amd.com>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Matt Sinclair <mattdsinclair@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/configs/example/apu_se.py b/configs/example/apu_se.py
index 6f686f3..7a45952 100644
--- a/configs/example/apu_se.py
+++ b/configs/example/apu_se.py
@@ -189,7 +189,9 @@
                     "between 0-7")
 
 parser.add_argument("--gfx-version", type=str, default='gfx801',
-                    help="Gfx version for gpu: gfx801, gfx803, gfx900")
+                    choices=GfxVersion.vals,
+                    help="Gfx version for gpu"
+                    "Note: gfx902 is not fully supported by ROCm")
 
 Ruby.define_options(parser)
 
@@ -683,7 +685,7 @@
     elif args.gfx_version == 'gfx900':
         hsaTopology.createVegaTopology(args)
 else:
-    assert (args.gfx_version in ['gfx801']),\
+    assert (args.gfx_version in ['gfx801', 'gfx902']),\
             "Incorrect gfx version for APU"
     hsaTopology.createCarrizoTopology(args)
 
diff --git a/configs/example/hsaTopology.py b/configs/example/hsaTopology.py
index a4dbebb..232464e 100644
--- a/configs/example/hsaTopology.py
+++ b/configs/example/hsaTopology.py
@@ -434,14 +434,19 @@
     # must show valid kaveri gpu id or massive meltdown
     file_append((node_dir, 'gpu_id'), 2765)
 
+    gfx_dict = { "gfx801": {"name": "Carrizo\n", "id": 39028},
+                 "gfx902": {"name": "Raven\n", "id": 5597}}
+
     # must have marketing name
-    file_append((node_dir, 'name'), 'Carrizo\n')
+    file_append((node_dir, 'name'), gfx_dict[options.gfx_version]["name"])
 
     mem_banks_cnt = 1
 
     # Should be the same as the render driver filename (dri/renderD<drm_num>)
     drm_num = 128
 
+    device_id = gfx_dict[options.gfx_version]["id"]
+
     # populate global node properties
     # NOTE: SIMD count triggers a valid GPU agent creation
     node_prop = 'cpu_cores_count %s\n' % options.num_cpus                   + \
@@ -462,7 +467,7 @@
                 'simd_per_cu %s\n' % options.simds_per_cu                   + \
                 'max_slots_scratch_cu 32\n'                                 + \
                 'vendor_id 4098\n'                                          + \
-                'device_id 39028\n'                                         + \
+                'device_id %s\n' % device_id                                + \
                 'location_id 8\n'                                           + \
                 'drm_render_minor %s\n' % drm_num                           + \
                 'max_engine_clk_fcompute %s\n'                                \
diff --git a/src/gpu-compute/GPU.py b/src/gpu-compute/GPU.py
index d2f9b6e..b739e80 100644
--- a/src/gpu-compute/GPU.py
+++ b/src/gpu-compute/GPU.py
@@ -52,6 +52,7 @@
     'gfx801',
     'gfx803',
     'gfx900',
+    'gfx902',
     ]
 
 class PoolManager(SimObject):
diff --git a/src/gpu-compute/gpu_compute_driver.cc b/src/gpu-compute/gpu_compute_driver.cc
index 2fe5275..92ac641 100644
--- a/src/gpu-compute/gpu_compute_driver.cc
+++ b/src/gpu-compute/gpu_compute_driver.cc
@@ -351,6 +351,7 @@
                     break;
                   case GfxVersion::gfx803:
                   case GfxVersion::gfx900:
+                  case GfxVersion::gfx902:
                     // Taken from SVM_USE_BASE in Linux kernel
                     args->process_apertures[i].gpuvm_base = 0x1000000ull;
                     // Taken from AMDGPU_GMC_HOLE_START in Linux kernel
@@ -384,6 +385,7 @@
                 } else {
                     switch (gfxVersion) {
                       case GfxVersion::gfx801:
+                      case GfxVersion::gfx902:
                         args->process_apertures[i].gpu_id = 2765;
                         break;
                       default:
@@ -644,6 +646,7 @@
                     break;
                   case GfxVersion::gfx803:
                   case GfxVersion::gfx900:
+                  case GfxVersion::gfx902:
                     // Taken from SVM_USE_BASE in Linux kernel
                     ape_args->gpuvm_base = 0x1000000ull;
                     // Taken from AMDGPU_GMC_HOLE_START in Linux kernel
@@ -668,6 +671,7 @@
                 } else {
                     switch (gfxVersion) {
                       case GfxVersion::gfx801:
+                      case GfxVersion::gfx902:
                         ape_args->gpu_id = 2765;
                         break;
                       default:
@@ -717,7 +721,7 @@
             TypedBufferArg<kfd_ioctl_alloc_memory_of_gpu_args> args(ioc_buf);
             args.copyIn(virt_proxy);
 
-            assert(isdGPU);
+            assert(isdGPU || gfxVersion == GfxVersion::gfx902);
             assert((args->va_addr % TheISA::PageBytes) == 0);
             GEM5_VAR_USED Addr mmap_offset = 0;
 
diff --git a/src/gpu-compute/gpu_compute_driver.hh b/src/gpu-compute/gpu_compute_driver.hh
index 9441baa..6ce523e 100644
--- a/src/gpu-compute/gpu_compute_driver.hh
+++ b/src/gpu-compute/gpu_compute_driver.hh
@@ -90,8 +90,10 @@
         switch (gfxVersion) {
           case GfxVersion::gfx801:
           case GfxVersion::gfx803:
+          case GfxVersion::gfx902:
             return 4;
           case GfxVersion::gfx900:
+            // gfx900 supports large BAR, so it has a larger doorbell
             return 8;
           default:
             fatal("Invalid GPU type\n");