@@ -1498,6 +1498,22 @@ namespace {
14981498 return " ?" ;
14991499 }
15001500
1501+ // Returns whether a memory allocation can be directly read by host code.
1502+ static ErrResult GetMemHostAccessibility (MemDevice const & memDevice, bool & hostAccessible)
1503+ {
1504+ hostAccessible = IsCpuMemType (memDevice.memType ) || memDevice.memType == MEM_MANAGED ;
1505+ if (hostAccessible || !IsGpuMemType (memDevice.memType )) return ERR_NONE ;
1506+
1507+ #if defined(__NVCC__)
1508+ return ERR_NONE ;
1509+ #else
1510+ int isLargeBar = 0 ;
1511+ ERR_CHECK (hipDeviceGetAttribute (&isLargeBar, hipDeviceAttributeIsLargeBar, memDevice.memIndex ));
1512+ hostAccessible = (isLargeBar != 0 );
1513+ return ERR_NONE ;
1514+ #endif
1515+ }
1516+
15011517 // Allocate memory
15021518 static ErrResult AllocateMemory (MemDevice memDevice, size_t numBytes, void ** memPtr,
15031519 size_t * actualBytes = NULL ,
@@ -2943,6 +2959,7 @@ namespace {
29432959
29442960 // For GPU-Executors
29452961 SubExecParam* subExecParamGpu; // /< GPU copy of subExecutor parameters
2962+ bool subExecParamHostAccessible; // /< Host can directly read subExecParamGpu
29462963 vector<hipStream_t> streams; // /< HIP streams to launch on
29472964 vector<hipEvent_t> startEvents; // /< HIP start timing event
29482965 vector<hipEvent_t> stopEvents; // /< HIP stop timing event
@@ -4476,6 +4493,7 @@ namespace {
44764493#endif
44774494 ERR_CHECK (AllocateMemory ({memType, exeDevice.exeIndex }, exeInfo.totalSubExecs * sizeof (SubExecParam),
44784495 (void **)&exeInfo.subExecParamGpu ));
4496+ ERR_CHECK (GetMemHostAccessibility ({memType, exeDevice.exeIndex }, exeInfo.subExecParamHostAccessible ));
44794497
44804498 // Create subexecutor parameter array for entire executor
44814499 exeInfo.subExecParamCpu .clear ();
@@ -5435,6 +5453,7 @@ namespace {
54355453 int const xccDim,
54365454 ConfigOptions const & cfg,
54375455 int const gfxKernelIdx,
5456+ bool const subExecParamHostAccessible,
54385457 TransferResources& rss)
54395458 {
54405459 // Determine which kernel to launch
@@ -5491,9 +5510,17 @@ namespace {
54915510 if (cfg.general .recordPerIteration ) {
54925511 rss.perIterMsec .push_back (deltaMsec);
54935512 std::set<std::pair<int ,int >> CUs;
5513+ std::vector<SubExecParam> subExecParamHost;
5514+ SubExecParam const * subExecParam = rss.subExecParamGpuPtr ;
5515+ if (!subExecParamHostAccessible) {
5516+ subExecParamHost.resize (numSubExecs);
5517+ ERR_CHECK (hipMemcpy (subExecParamHost.data (), rss.subExecParamGpuPtr ,
5518+ numSubExecs * sizeof (SubExecParam), hipMemcpyDefault));
5519+ subExecParam = subExecParamHost.data ();
5520+ }
54945521 for (int i = 0 ; i < numSubExecs; i++) {
5495- CUs.insert (std::make_pair (rss. subExecParamGpuPtr [i].xccId ,
5496- GetId (rss. subExecParamGpuPtr [i].hwId )));
5522+ CUs.insert (std::make_pair (subExecParam [i].xccId ,
5523+ GetId (subExecParam [i].hwId )));
54975524 }
54985525 rss.perIterCUs .push_back (CUs);
54995526 }
@@ -5528,6 +5555,7 @@ namespace {
55285555 xccDim,
55295556 std::cref (cfg),
55305557 exeInfo.gfxKernelToUse ,
5558+ exeInfo.subExecParamHostAccessible ,
55315559 std::ref (exeInfo.resources [i])));
55325560 }
55335561 for (auto & asyncTransfer : asyncTransfers)
@@ -5537,7 +5565,8 @@ namespace {
55375565 ExecuteGpuTransfer (iteration, exeInfo.totalSubExecs , exeInfo.subExecParamGpu , exeInfo.streams [0 ],
55385566 cfg.gfx .useHipEvents ? exeInfo.startEvents [0 ] : NULL ,
55395567 cfg.gfx .useHipEvents ? exeInfo.stopEvents [0 ] : NULL ,
5540- xccDim, cfg, exeInfo.gfxKernelToUse , exeInfo.resources [0 ]);
5568+ xccDim, cfg, exeInfo.gfxKernelToUse ,
5569+ exeInfo.subExecParamHostAccessible , exeInfo.resources [0 ]);
55415570 }
55425571
55435572 auto cpuDelta = std::chrono::high_resolution_clock::now () - cpuStart;
@@ -5560,6 +5589,15 @@ namespace {
55605589 // If Transfers were combined into a single launch, figure out per-Transfer timing
55615590 // Determine timing for each of the individual transfers that were part of this launch
55625591 if (!cfg.gfx .useMultiStream ) {
5592+ std::vector<SubExecParam> subExecParamHost;
5593+ SubExecParam const * subExecParam = exeInfo.subExecParamGpu ;
5594+ if (!exeInfo.subExecParamHostAccessible ) {
5595+ subExecParamHost.resize (exeInfo.totalSubExecs );
5596+ ERR_CHECK (hipMemcpy (subExecParamHost.data (), exeInfo.subExecParamGpu ,
5597+ exeInfo.totalSubExecs * sizeof (SubExecParam), hipMemcpyDefault));
5598+ subExecParam = subExecParamHost.data ();
5599+ }
5600+
55635601 for (int i = 0 ; i < exeInfo.resources .size (); i++) {
55645602 TransferResources& rss = exeInfo.resources [i];
55655603 int64_t minStartCycle = std::numeric_limits<int64_t >::max ();
@@ -5568,11 +5606,11 @@ namespace {
55685606
55695607 for (auto subExecIdx : rss.subExecIdx ) {
55705608 if (exeInfo.subExecParamCpu [subExecIdx].N != 0 ) {
5571- minStartCycle = std::min (minStartCycle, exeInfo. subExecParamGpu [subExecIdx].startCycle );
5572- maxStopCycle = std::max (maxStopCycle, exeInfo. subExecParamGpu [subExecIdx].stopCycle );
5609+ minStartCycle = std::min (minStartCycle, subExecParam [subExecIdx].startCycle );
5610+ maxStopCycle = std::max (maxStopCycle, subExecParam [subExecIdx].stopCycle );
55735611 if (cfg.general .recordPerIteration ) {
5574- CUs.insert (std::make_pair (exeInfo. subExecParamGpu [subExecIdx].xccId ,
5575- GetId (exeInfo. subExecParamGpu [subExecIdx].hwId )));
5612+ CUs.insert (std::make_pair (subExecParam [subExecIdx].xccId ,
5613+ GetId (subExecParam [subExecIdx].hwId )));
55765614 }
55775615 }
55785616 }
0 commit comments