Skip to content

Commit

Permalink
[ur] Add default for virtual mem access flags
Browse files Browse the repository at this point in the history
Address [feedback](#525 (comment))
and add `UR_VIRTUAL_MEM_ACCESS_FLAG_NONE` to allow specifying a 0 value
for the access flags.
  • Loading branch information
kbenzie committed Jun 20, 2023
1 parent cfa949f commit 7a7102b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
5 changes: 3 additions & 2 deletions include/ur.py
Original file line number Diff line number Diff line change
Expand Up @@ -1324,8 +1324,9 @@ def __str__(self):
###############################################################################
## @brief Virtual memory access mode flags.
class ur_virtual_mem_access_flags_v(IntEnum):
READ_WRITE = UR_BIT(0) ## Virtual memory both read and write accessible
READ_ONLY = UR_BIT(1) ##
NONE = UR_BIT(0) ## Virtual memory has default access.
READ_WRITE = UR_BIT(1) ## Virtual memory has both read and write access.
READ_ONLY = UR_BIT(2) ## Virtual memory has read only access.

class ur_virtual_mem_access_flags_t(c_int):
def __str__(self):
Expand Down
7 changes: 4 additions & 3 deletions include/ur_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -3055,15 +3055,16 @@ urVirtualMemFree(
/// @brief Virtual memory access mode flags.
typedef uint32_t ur_virtual_mem_access_flags_t;
typedef enum ur_virtual_mem_access_flag_t {
UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE = UR_BIT(0), ///< Virtual memory both read and write accessible
UR_VIRTUAL_MEM_ACCESS_FLAG_READ_ONLY = UR_BIT(1), ///<
UR_VIRTUAL_MEM_ACCESS_FLAG_NONE = UR_BIT(0), ///< Virtual memory has default access.
UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE = UR_BIT(1), ///< Virtual memory has both read and write access.
UR_VIRTUAL_MEM_ACCESS_FLAG_READ_ONLY = UR_BIT(2), ///< Virtual memory has read only access.
/// @cond
UR_VIRTUAL_MEM_ACCESS_FLAG_FORCE_UINT32 = 0x7fffffff
/// @endcond

} ur_virtual_mem_access_flag_t;
/// @brief Bit Mask for validating ur_virtual_mem_access_flags_t
#define UR_VIRTUAL_MEM_ACCESS_FLAGS_MASK 0xfffffffc
#define UR_VIRTUAL_MEM_ACCESS_FLAGS_MASK 0xfffffff8

///////////////////////////////////////////////////////////////////////////////
/// @brief Map a virtual memory range to a physical memory handle.
Expand Down
11 changes: 7 additions & 4 deletions scripts/core/virtual_memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ desc: "Virtual memory access mode flags."
class: $xVirtualMem
name: $x_virtual_mem_access_flags_t
etors:
- name: READ_WRITE
- name: NONE
value: $X_BIT(0)
desc: "Virtual memory both read and write accessible"
- name: READ_ONLY
desc: "Virtual memory has default access."
- name: READ_WRITE
value: $X_BIT(1)
desc: ""
desc: "Virtual memory has both read and write access."
- name: READ_ONLY
value: $X_BIT(2)
desc: "Virtual memory has read only access."

--- #--------------------------------------------------------------------------
type: function
Expand Down
15 changes: 15 additions & 0 deletions source/common/ur_params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6437,6 +6437,10 @@ inline std::ostream &operator<<(std::ostream &os,
enum ur_virtual_mem_access_flag_t value) {
switch (value) {

case UR_VIRTUAL_MEM_ACCESS_FLAG_NONE:
os << "UR_VIRTUAL_MEM_ACCESS_FLAG_NONE";
break;

case UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE:
os << "UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE";
break;
Expand All @@ -6458,6 +6462,17 @@ inline void serializeFlag<ur_virtual_mem_access_flag_t>(std::ostream &os,
uint32_t val = flag;
bool first = true;

if ((val & UR_VIRTUAL_MEM_ACCESS_FLAG_NONE) ==
(uint32_t)UR_VIRTUAL_MEM_ACCESS_FLAG_NONE) {
val ^= (uint32_t)UR_VIRTUAL_MEM_ACCESS_FLAG_NONE;
if (!first) {
os << " | ";
} else {
first = false;
}
os << UR_VIRTUAL_MEM_ACCESS_FLAG_NONE;
}

if ((val & UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE) ==
(uint32_t)UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE) {
val ^= (uint32_t)UR_VIRTUAL_MEM_ACCESS_FLAG_READ_WRITE;
Expand Down

0 comments on commit 7a7102b

Please sign in to comment.