@@ -1545,15 +1545,71 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMMemcpy2D(
1545
1545
}
1546
1546
1547
1547
UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite (
1548
- ur_queue_handle_t , ur_program_handle_t , const char *, bool , size_t , size_t ,
1549
- const void *, uint32_t , const ur_event_handle_t *, ur_event_handle_t *) {
1550
- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1548
+ ur_queue_handle_t hQueue, ur_program_handle_t hProgram, const char *name,
1549
+ bool blockingWrite, size_t count, size_t offset, const void *pSrc,
1550
+ uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
1551
+ ur_event_handle_t *phEvent) {
1552
+ // Since HIP requires a the global variable to be referenced by name, we use
1553
+ // metadata to find the correct name to access it by.
1554
+ auto DeviceGlobalNameIt = hProgram->GlobalIDMD .find (name);
1555
+ if (DeviceGlobalNameIt == hProgram->GlobalIDMD .end ())
1556
+ return UR_RESULT_ERROR_INVALID_VALUE;
1557
+ std::string DeviceGlobalName = DeviceGlobalNameIt->second ;
1558
+
1559
+ ur_result_t Result = UR_RESULT_SUCCESS;
1560
+ try {
1561
+ hipDeviceptr_t DeviceGlobal = 0 ;
1562
+ size_t DeviceGlobalSize = 0 ;
1563
+ UR_CHECK_ERROR (hipModuleGetGlobal (&DeviceGlobal, &DeviceGlobalSize,
1564
+ hProgram->get (),
1565
+ DeviceGlobalName.c_str ()));
1566
+
1567
+ if (offset + count > DeviceGlobalSize)
1568
+ return UR_RESULT_ERROR_INVALID_VALUE;
1569
+
1570
+ return urEnqueueUSMMemcpy (
1571
+ hQueue, blockingWrite,
1572
+ reinterpret_cast <void *>(reinterpret_cast <uint8_t *>(DeviceGlobal) +
1573
+ offset),
1574
+ pSrc, count, numEventsInWaitList, phEventWaitList, phEvent);
1575
+ } catch (ur_result_t Err) {
1576
+ Result = Err;
1577
+ }
1578
+ return Result;
1551
1579
}
1552
1580
1553
1581
UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead (
1554
- ur_queue_handle_t , ur_program_handle_t , const char *, bool , size_t , size_t ,
1555
- void *, uint32_t , const ur_event_handle_t *, ur_event_handle_t *) {
1556
- return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1582
+ ur_queue_handle_t hQueue, ur_program_handle_t hProgram, const char *name,
1583
+ bool blockingRead, size_t count, size_t offset, void *pDst,
1584
+ uint32_t numEventsInWaitList, const ur_event_handle_t *phEventWaitList,
1585
+ ur_event_handle_t *phEvent) {
1586
+ // Since HIP requires a the global variable to be referenced by name, we use
1587
+ // metadata to find the correct name to access it by.
1588
+ auto DeviceGlobalNameIt = hProgram->GlobalIDMD .find (name);
1589
+ if (DeviceGlobalNameIt == hProgram->GlobalIDMD .end ())
1590
+ return UR_RESULT_ERROR_INVALID_VALUE;
1591
+ std::string DeviceGlobalName = DeviceGlobalNameIt->second ;
1592
+
1593
+ ur_result_t Result = UR_RESULT_SUCCESS;
1594
+ try {
1595
+ hipDeviceptr_t DeviceGlobal = 0 ;
1596
+ size_t DeviceGlobalSize = 0 ;
1597
+ UR_CHECK_ERROR (hipModuleGetGlobal (&DeviceGlobal, &DeviceGlobalSize,
1598
+ hProgram->get (),
1599
+ DeviceGlobalName.c_str ()));
1600
+
1601
+ if (offset + count > DeviceGlobalSize)
1602
+ return UR_RESULT_ERROR_INVALID_VALUE;
1603
+
1604
+ return urEnqueueUSMMemcpy (
1605
+ hQueue, blockingRead, pDst,
1606
+ reinterpret_cast <const void *>(
1607
+ reinterpret_cast <uint8_t *>(DeviceGlobal) + offset),
1608
+ count, numEventsInWaitList, phEventWaitList, phEvent);
1609
+ } catch (ur_result_t Err) {
1610
+ Result = Err;
1611
+ }
1612
+ return Result;
1557
1613
}
1558
1614
1559
1615
UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe (
0 commit comments