Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions source/adapters/native_cpu/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "logger/ur_logger.hpp"
#include "ur/ur.hpp"
#include <chrono>

constexpr size_t MaxMessageSize = 256;

Expand Down Expand Up @@ -71,31 +70,3 @@ template <typename T> inline void decrementOrDelete(T *refC) {
if (refC->decrementReferenceCount() == 0)
delete refC;
}

inline uint64_t get_timestamp() {
return std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
}

namespace native_cpu {

inline void *aligned_malloc(size_t alignment, size_t size) {
void *ptr = nullptr;
#ifdef _MSC_VER
ptr = _aligned_malloc(size, alignment);
#else
ptr = std::aligned_alloc(alignment, size);
#endif
return ptr;
}

inline void aligned_free(void *ptr) {
#ifdef _MSC_VER
_aligned_free(ptr);
#else
free(ptr);
#endif
}

} // namespace native_cpu
18 changes: 14 additions & 4 deletions source/adapters/native_cpu/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ static size_t get_padding(uint32_t alignment) {
// allocation so that the pointer returned to the user
// always satisfies (ptr % align) == 0.
static inline void *malloc_impl(uint32_t alignment, size_t size) {
void *ptr = nullptr;
assert(alignment >= alignof(usm_alloc_info) &&
"memory not aligned to usm_alloc_info");
void *ptr = native_cpu::aligned_malloc(
alignment, alloc_header_size + get_padding(alignment) + size);
#ifdef _MSC_VER
ptr = _aligned_malloc(alloc_header_size + get_padding(alignment) + size,
alignment);

#else
ptr = std::aligned_alloc(alignment,
alloc_header_size + get_padding(alignment) + size);
#endif
return ptr;
}

Expand All @@ -93,8 +100,11 @@ struct ur_context_handle_t_ : RefCounted {
const native_cpu::usm_alloc_info &info = native_cpu::get_alloc_info(ptr);
UR_ASSERT(info.type != UR_USM_TYPE_UNKNOWN,
UR_RESULT_ERROR_INVALID_MEM_OBJECT);

native_cpu::aligned_free(info.base_alloc_ptr);
#ifdef _MSC_VER
_aligned_free(info.base_alloc_ptr);
#else
free(info.base_alloc_ptr);
#endif
allocations.erase(ptr);
return UR_RESULT_SUCCESS;
}
Expand Down
15 changes: 11 additions & 4 deletions source/adapters/native_cpu/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <ur_api.h>

#include "common.hpp"
#include "platform.hpp"

#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__)
Expand Down Expand Up @@ -248,6 +247,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
return ReturnValue(uint32_t{4});
case UR_DEVICE_INFO_NATIVE_VECTOR_WIDTH_HALF:
return ReturnValue(uint32_t{16});
// Imported from level_zero
case UR_DEVICE_INFO_USM_HOST_SUPPORT:
case UR_DEVICE_INFO_USM_DEVICE_SUPPORT:
case UR_DEVICE_INFO_USM_SINGLE_SHARED_SUPPORT:
Expand Down Expand Up @@ -469,12 +469,19 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceCreateWithNativeHandle(
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetGlobalTimestamps(
ur_device_handle_t hDevice, uint64_t *pDeviceTimestamp,
uint64_t *pHostTimestamp) {
std::ignore = hDevice;
std::ignore = hDevice; // todo
if (pHostTimestamp) {
*pHostTimestamp = get_timestamp();
using namespace std::chrono;
*pHostTimestamp =
duration_cast<nanoseconds>(steady_clock::now().time_since_epoch())
.count();
}
if (pDeviceTimestamp) {
*pDeviceTimestamp = get_timestamp();
// todo: calculate elapsed time properly
using namespace std::chrono;
*pDeviceTimestamp =
duration_cast<nanoseconds>(steady_clock::now().time_since_epoch())
.count();
}
return UR_RESULT_SUCCESS;
}
Expand Down
Loading
Loading