@@ -1478,6 +1478,22 @@ namespace {
14781478 return " ?" ;
14791479 }
14801480
1481+ // Returns whether a memory allocation can be directly read by host code.
1482+ static ErrResult GetMemHostAccessibility (MemDevice const & memDevice, bool & hostAccessible)
1483+ {
1484+ hostAccessible = IsCpuMemType (memDevice.memType ) || memDevice.memType == MEM_MANAGED ;
1485+ if (hostAccessible || !IsGpuMemType (memDevice.memType )) return ERR_NONE ;
1486+
1487+ #if defined(__NVCC__)
1488+ return ERR_NONE ;
1489+ #else
1490+ int isLargeBar = 0 ;
1491+ ERR_CHECK (hipDeviceGetAttribute (&isLargeBar, hipDeviceAttributeIsLargeBar, memDevice.memIndex ));
1492+ hostAccessible = (isLargeBar != 0 );
1493+ return ERR_NONE ;
1494+ #endif
1495+ }
1496+
14811497 // Allocate memory
14821498 static ErrResult AllocateMemory (MemDevice memDevice, size_t numBytes, void ** memPtr,
14831499 size_t * actualBytes = NULL ,
@@ -2820,6 +2836,7 @@ namespace {
28202836
28212837 // For GPU-Executors
28222838 SubExecParam* subExecParamGpu; // /< GPU copy of subExecutor parameters
2839+ bool subExecParamHostAccessible; // /< Host can directly read subExecParamGpu
28232840 vector<hipStream_t> streams; // /< HIP streams to launch on
28242841 vector<hipEvent_t> startEvents; // /< HIP start timing event
28252842 vector<hipEvent_t> stopEvents; // /< HIP stop timing event
@@ -4372,6 +4389,7 @@ static bool IsConfiguredGid(union ibv_gid const& gid)
43724389#endif
43734390 ERR_CHECK (AllocateMemory ({memType, exeDevice.exeIndex }, exeInfo.totalSubExecs * sizeof (SubExecParam),
43744391 (void **)&exeInfo.subExecParamGpu ));
4392+ ERR_CHECK (GetMemHostAccessibility ({memType, exeDevice.exeIndex }, exeInfo.subExecParamHostAccessible ));
43754393
43764394 // Create subexecutor parameter array for entire executor
43774395 exeInfo.subExecParamCpu .clear ();
@@ -5334,6 +5352,7 @@ static bool IsConfiguredGid(union ibv_gid const& gid)
53345352 int const xccDim,
53355353 ConfigOptions const & cfg,
53365354 int const gfxKernelIdx,
5355+ bool const subExecParamHostAccessible,
53375356 TransferResources& rss)
53385357 {
53395358 // Determine which kernel to launch
@@ -5390,9 +5409,17 @@ static bool IsConfiguredGid(union ibv_gid const& gid)
53905409 if (cfg.general .recordPerIteration ) {
53915410 rss.perIterMsec .push_back (deltaMsec);
53925411 std::set<std::pair<int ,int >> CUs;
5412+ std::vector<SubExecParam> subExecParamHost;
5413+ SubExecParam const * subExecParam = rss.subExecParamGpuPtr ;
5414+ if (!subExecParamHostAccessible) {
5415+ subExecParamHost.resize (numSubExecs);
5416+ ERR_CHECK (hipMemcpy (subExecParamHost.data (), rss.subExecParamGpuPtr ,
5417+ numSubExecs * sizeof (SubExecParam), hipMemcpyDefault));
5418+ subExecParam = subExecParamHost.data ();
5419+ }
53935420 for (int i = 0 ; i < numSubExecs; i++) {
5394- CUs.insert (std::make_pair (rss. subExecParamGpuPtr [i].xccId ,
5395- GetId (rss. subExecParamGpuPtr [i].hwId )));
5421+ CUs.insert (std::make_pair (subExecParam [i].xccId ,
5422+ GetId (subExecParam [i].hwId )));
53965423 }
53975424 rss.perIterCUs .push_back (CUs);
53985425 }
@@ -5427,6 +5454,7 @@ static bool IsConfiguredGid(union ibv_gid const& gid)
54275454 xccDim,
54285455 std::cref (cfg),
54295456 exeInfo.gfxKernelToUse ,
5457+ exeInfo.subExecParamHostAccessible ,
54305458 std::ref (exeInfo.resources [i])));
54315459 }
54325460 for (auto & asyncTransfer : asyncTransfers)
@@ -5436,7 +5464,8 @@ static bool IsConfiguredGid(union ibv_gid const& gid)
54365464 ExecuteGpuTransfer (iteration, exeInfo.totalSubExecs , exeInfo.subExecParamGpu , exeInfo.streams [0 ],
54375465 cfg.gfx .useHipEvents ? exeInfo.startEvents [0 ] : NULL ,
54385466 cfg.gfx .useHipEvents ? exeInfo.stopEvents [0 ] : NULL ,
5439- xccDim, cfg, exeInfo.gfxKernelToUse , exeInfo.resources [0 ]);
5467+ xccDim, cfg, exeInfo.gfxKernelToUse ,
5468+ exeInfo.subExecParamHostAccessible , exeInfo.resources [0 ]);
54405469 }
54415470
54425471 auto cpuDelta = std::chrono::high_resolution_clock::now () - cpuStart;
@@ -5459,6 +5488,15 @@ static bool IsConfiguredGid(union ibv_gid const& gid)
54595488 // If Transfers were combined into a single launch, figure out per-Transfer timing
54605489 // Determine timing for each of the individual transfers that were part of this launch
54615490 if (!cfg.gfx .useMultiStream ) {
5491+ std::vector<SubExecParam> subExecParamHost;
5492+ SubExecParam const * subExecParam = exeInfo.subExecParamGpu ;
5493+ if (!exeInfo.subExecParamHostAccessible ) {
5494+ subExecParamHost.resize (exeInfo.totalSubExecs );
5495+ ERR_CHECK (hipMemcpy (subExecParamHost.data (), exeInfo.subExecParamGpu ,
5496+ exeInfo.totalSubExecs * sizeof (SubExecParam), hipMemcpyDefault));
5497+ subExecParam = subExecParamHost.data ();
5498+ }
5499+
54625500 for (int i = 0 ; i < exeInfo.resources .size (); i++) {
54635501 TransferResources& rss = exeInfo.resources [i];
54645502 int64_t minStartCycle = std::numeric_limits<int64_t >::max ();
@@ -5467,11 +5505,11 @@ static bool IsConfiguredGid(union ibv_gid const& gid)
54675505
54685506 for (auto subExecIdx : rss.subExecIdx ) {
54695507 if (exeInfo.subExecParamCpu [subExecIdx].N != 0 ) {
5470- minStartCycle = std::min (minStartCycle, exeInfo. subExecParamGpu [subExecIdx].startCycle );
5471- maxStopCycle = std::max (maxStopCycle, exeInfo. subExecParamGpu [subExecIdx].stopCycle );
5508+ minStartCycle = std::min (minStartCycle, subExecParam [subExecIdx].startCycle );
5509+ maxStopCycle = std::max (maxStopCycle, subExecParam [subExecIdx].stopCycle );
54725510 if (cfg.general .recordPerIteration ) {
5473- CUs.insert (std::make_pair (exeInfo. subExecParamGpu [subExecIdx].xccId ,
5474- GetId (exeInfo. subExecParamGpu [subExecIdx].hwId )));
5511+ CUs.insert (std::make_pair (subExecParam [subExecIdx].xccId ,
5512+ GetId (subExecParam [subExecIdx].hwId )));
54755513 }
54765514 }
54775515 }
0 commit comments