Skip to content

Commit bc950e7

Browse files
committed
Use std::optional as suggested by Peter. Much better!
1 parent 794f042 commit bc950e7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/acl_usm.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
101101
// Iterate over properties.
102102
// The end of the properties list is specified with a zero.
103103
cl_mem_alloc_flags_intel alloc_flags = 0;
104-
cl_int mem_id = -1;
104+
std::optional<cl_uint> mem_id;
105105
while (properties != NULL && *properties != 0) {
106106
switch (*properties) {
107107
case CL_MEM_ALLOC_FLAGS_INTEL: {
108108
alloc_flags = *(properties + 1);
109109
} break;
110110
case CL_MEM_ALLOC_BUFFER_LOCATION_INTEL: {
111-
mem_id = (cl_int) * (properties + 1);
111+
mem_id = (cl_uint) * (properties + 1);
112112
} break;
113113
default: {
114114
UNLOCK_BAIL_INFO(CL_INVALID_PROPERTY, context, "Invalid properties");
@@ -145,9 +145,9 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
145145

146146
if (acl_get_hal()->host_alloc) {
147147
std::vector<mem_properties_t> mmd_properties;
148-
if (mem_id >= 0) {
148+
if (mem_id) {
149149
mmd_properties.push_back(AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION);
150-
mmd_properties.push_back(mem_id);
150+
mmd_properties.push_back(mem_id.value());
151151
}
152152
mmd_properties.push_back(0);
153153

@@ -394,7 +394,7 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
394394
// The end of the properties list is specified with a zero.
395395
cl_mem_alloc_flags_intel alloc_flags = 0;
396396
std::unordered_set<unsigned long long> seen_flags;
397-
cl_int mem_id = -1;
397+
std::optional<cl_uint> mem_id;
398398
while (properties != NULL && *properties != 0) {
399399
switch (*properties) {
400400
case CL_MEM_ALLOC_FLAGS_INTEL: {
@@ -417,7 +417,7 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
417417
UNLOCK_BAIL_INFO(CL_INVALID_PROPERTY, context,
418418
"Property specified multiple times");
419419
}
420-
mem_id = (cl_int) * (properties + 1);
420+
mem_id = (cl_uint) * (properties + 1);
421421
} break;
422422
default: {
423423
UNLOCK_BAIL_INFO(CL_INVALID_PROPERTY, context, "Invalid properties");
@@ -428,9 +428,9 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
428428

429429
if (acl_get_hal()->shared_alloc) {
430430
std::vector<mem_properties_t> mmd_properties;
431-
if (mem_id >= 0) {
431+
if (mem_id) {
432432
mmd_properties.push_back(AOCL_MMD_MEM_PROPERTIES_BUFFER_LOCATION);
433-
mmd_properties.push_back(mem_id);
433+
mmd_properties.push_back(mem_id.value());
434434
}
435435
mmd_properties.push_back(0);
436436

0 commit comments

Comments
 (0)