Skip to content

Commit fbaf131

Browse files
authored
Revert "[NATIVECPU] Initial implementation of events on Native CPU"
1 parent 13731c2 commit fbaf131

13 files changed

+214
-399
lines changed

source/adapters/native_cpu/common.hpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#include "logger/ur_logger.hpp"
1414
#include "ur/ur.hpp"
15-
#include <chrono>
1615

1716
constexpr size_t MaxMessageSize = 256;
1817

@@ -71,31 +70,3 @@ template <typename T> inline void decrementOrDelete(T *refC) {
7170
if (refC->decrementReferenceCount() == 0)
7271
delete refC;
7372
}
74-
75-
inline uint64_t get_timestamp() {
76-
return std::chrono::duration_cast<std::chrono::nanoseconds>(
77-
std::chrono::high_resolution_clock::now().time_since_epoch())
78-
.count();
79-
}
80-
81-
namespace native_cpu {
82-
83-
inline void *aligned_malloc(size_t alignment, size_t size) {
84-
void *ptr = nullptr;
85-
#ifdef _MSC_VER
86-
ptr = _aligned_malloc(size, alignment);
87-
#else
88-
ptr = std::aligned_alloc(alignment, size);
89-
#endif
90-
return ptr;
91-
}
92-
93-
inline void aligned_free(void *ptr) {
94-
#ifdef _MSC_VER
95-
_aligned_free(ptr);
96-
#else
97-
free(ptr);
98-
#endif
99-
}
100-
101-
} // namespace native_cpu

source/adapters/native_cpu/context.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,17 @@ static size_t get_padding(uint32_t alignment) {
6464
// allocation so that the pointer returned to the user
6565
// always satisfies (ptr % align) == 0.
6666
static inline void *malloc_impl(uint32_t alignment, size_t size) {
67+
void *ptr = nullptr;
6768
assert(alignment >= alignof(usm_alloc_info) &&
6869
"memory not aligned to usm_alloc_info");
69-
void *ptr = native_cpu::aligned_malloc(
70-
alignment, alloc_header_size + get_padding(alignment) + size);
70+
#ifdef _MSC_VER
71+
ptr = _aligned_malloc(alloc_header_size + get_padding(alignment) + size,
72+
alignment);
73+
74+
#else
75+
ptr = std::aligned_alloc(alignment,
76+
alloc_header_size + get_padding(alignment) + size);
77+
#endif
7178
return ptr;
7279
}
7380

@@ -93,8 +100,11 @@ struct ur_context_handle_t_ : RefCounted {
93100
const native_cpu::usm_alloc_info &info = native_cpu::get_alloc_info(ptr);
94101
UR_ASSERT(info.type != UR_USM_TYPE_UNKNOWN,
95102
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
96-
97-
native_cpu::aligned_free(info.base_alloc_ptr);
103+
#ifdef _MSC_VER
104+
_aligned_free(info.base_alloc_ptr);
105+
#else
106+
free(info.base_alloc_ptr);
107+
#endif
98108
allocations.erase(ptr);
99109
return UR_RESULT_SUCCESS;
100110
}

source/adapters/native_cpu/device.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <ur_api.h>
1212

13-
#include "common.hpp"
1413
#include "platform.hpp"
1514

1615
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
@@ -248,6 +247,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
248247
return ReturnValue(uint32_t{4});
249248
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF:
250249
return ReturnValue(uint32_t{16});
250+
// Imported from level_zero
251251
case UR_DEVICE_INFO_USM_HOST_SUPPORT:
252252
case UR_DEVICE_INFO_USM_DEVICE_SUPPORT:
253253
case UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT:
@@ -469,12 +469,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceCreateWithNativeHandle(
469469
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetGlobalTimestamps(
470470
ur_device_handle_t hDevice, uint64_t *pDeviceTimestamp,
471471
uint64_t *pHostTimestamp) {
472-
std::ignore = hDevice;
472+
std::ignore = hDevice; // todo
473473
if (pHostTimestamp) {
474-
*pHostTimestamp = get_timestamp();
474+
using namespace std::chrono;
475+
*pHostTimestamp =
476+
duration_cast<nanoseconds>(steady_clock::now().time_since_epoch())
477+
.count();
475478
}
476479
if (pDeviceTimestamp) {
477-
*pDeviceTimestamp = get_timestamp();
480+
// todo: calculate elapsed time properly
481+
using namespace std::chrono;
482+
*pDeviceTimestamp =
483+
duration_cast<nanoseconds>(steady_clock::now().time_since_epoch())
484+
.count();
478485
}
479486
return UR_RESULT_SUCCESS;
480487
}

0 commit comments

Comments
 (0)