Skip to content

Commit

Permalink
Merge branch 'oneapi-src:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
lbushi25 authored May 1, 2024
2 parents 448870d + 633ec40 commit 4ed848e
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 36 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ option(UR_BUILD_TESTS "Build unit tests." ON)
option(UR_BUILD_TOOLS "build ur tools" ON)
option(UR_FORMAT_CPP_STYLE "format code style of C++ sources" OFF)
option(UR_DEVELOPER_MODE "enable developer checks, treats warnings as errors" OFF)
option(UR_ENABLE_FAST_SPEC_MODE "enable fast specification generation mode" OFF)
option(UR_USE_ASAN "enable AddressSanitizer" OFF)
option(UR_USE_UBSAN "enable UndefinedBehaviorSanitizer" OFF)
option(UR_USE_MSAN "enable MemorySanitizer" OFF)
Expand Down Expand Up @@ -292,7 +293,10 @@ if(UR_FORMAT_CPP_STYLE)
# Generate source from the specification
add_custom_target(generate-code USES_TERMINAL
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/scripts
COMMAND ${Python3_EXECUTABLE} run.py --api-json ${API_JSON_FILE} --clang-format=${CLANG_FORMAT}
COMMAND ${Python3_EXECUTABLE} run.py
--api-json ${API_JSON_FILE}
--clang-format=${CLANG_FORMAT}
$<$<BOOL:${UR_ENABLE_FAST_SPEC_MODE}>:--fast-mode>
COMMAND ${Python3_EXECUTABLE} json2src.py --api-json ${API_JSON_FILE} ${PROJECT_SOURCE_DIR}
)

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ List of options provided by CMake:
| UR_BUILD_TOOLS | Build tools | ON/OFF | ON |
| UR_FORMAT_CPP_STYLE | Format code style | ON/OFF | OFF |
| UR_DEVELOPER_MODE | Treat warnings as errors and enables additional checks | ON/OFF | OFF |
| UR_ENABLE_FAST_SPEC_MODE | Enable fast specification generation mode | ON/OFF | OFF |
| UR_USE_ASAN | Enable AddressSanitizer | ON/OFF | OFF |
| UR_USE_TSAN | Enable ThreadSanitizer | ON/OFF | OFF |
| UR_USE_UBSAN | Enable UndefinedBehavior Sanitizer | ON/OFF | OFF |
Expand Down
18 changes: 16 additions & 2 deletions scripts/generate_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,25 @@ def generate_layers(path, section, namespace, tags, version, specs, meta):
generates common utilities for unified_runtime
"""
def generate_common(path, section, namespace, tags, version, specs, meta):
template = "stype_map_helpers.hpp.mako"
fin = os.path.join("templates", template)

filename = "stype_map_helpers.def"
layer_dstpath = os.path.join(path, "common")
os.makedirs(layer_dstpath, exist_ok=True)
fout = os.path.join(layer_dstpath, filename)

print("Generating %s..." % fout)

loc = util.makoWrite(
fin, fout,
ver=version,
namespace=namespace,
tags=tags,
specs=specs,
meta=meta)
print("COMMON Generated %s lines of code.\n" % loc)

loc = 0
print("COMMON Generated %s lines of code.\n"%loc)

"""
Entry-point:
Expand Down
12 changes: 7 additions & 5 deletions scripts/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _make_ref(symbol, symbol_type, meta):
"""
generate a valid reStructuredText file
"""
def _generate_valid_rst(fin, fout, namespace, tags, ver, rev, meta):
def _generate_valid_rst(fin, fout, namespace, tags, ver, rev, meta, fast_mode):
ver=float(ver)
enable = True
code_block = False
Expand Down Expand Up @@ -185,13 +185,14 @@ def _generate_valid_rst(fin, fout, namespace, tags, ver, rev, meta):
ver=ver,
namespace=namespace,
tags=tags,
meta=meta)
meta=meta,
fast_mode=fast_mode)

"""
Entry-point:
generate restructuredtext documents from templates
"""
def generate_rst(docpath, section, namespace, tags, ver, rev, specs, meta):
def generate_rst(docpath, section, namespace, tags, ver, rev, specs, meta, fast_mode):
srcpath = os.path.join("./", section)
dstpath = os.path.join(docpath, "source", section)

Expand All @@ -200,7 +201,7 @@ def generate_rst(docpath, section, namespace, tags, ver, rev, specs, meta):
util.removeFiles(dstpath, "*.rst")
for fin in util.findFiles(srcpath, "*.rst"):
fout = os.path.join(dstpath, os.path.basename(fin))
loc += _generate_valid_rst(os.path.abspath(fin), fout, namespace, tags, ver, rev, meta)
loc += _generate_valid_rst(os.path.abspath(fin), fout, namespace, tags, ver, rev, meta, fast_mode)

print("Generated %s lines of reStructuredText (rst).\n"%loc)

Expand All @@ -215,7 +216,8 @@ def generate_rst(docpath, section, namespace, tags, ver, rev, specs, meta):
rev=rev,
tags=tags,
meta=meta,
specs=specs)
specs=specs,
fast_mode=fast_mode)

"""
Entry-point:
Expand Down
4 changes: 3 additions & 1 deletion scripts/run.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python3
"""
Copyright (C) 2022 Intel Corporation
Expand Down Expand Up @@ -120,6 +121,7 @@ def main():
required=False, help="specification version to generate.")
parser.add_argument("--api-json", type=str, default="unified_runtime.json", required=False, help="json output file for the spec")
parser.add_argument("--clang-format", type=str, default="clang-format", required=False, help="path to clang-format executable")
parser.add_argument('--fast-mode', action='store_true', help='Disable sections which are slow to render')
args = vars(parser.parse_args())
args['rev'] = revision()

Expand Down Expand Up @@ -175,7 +177,7 @@ def main():
raise Exception("Failed to format ur_api.h")

if args['rst']:
generate_docs.generate_rst(docpath, config['name'], config['namespace'], config['tags'], args['ver'], args['rev'], specs, input['meta'])
generate_docs.generate_rst(docpath, config['name'], config['namespace'], config['tags'], args['ver'], args['rev'], specs, input['meta'], args['fast_mode'])

if util.makeErrorCount():
print("\n%s Errors found during generation, stopping execution!"%util.makeErrorCount())
Expand Down
2 changes: 2 additions & 0 deletions scripts/templates/api_listing.mako
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ ${th.make_type_name(n, tags, obj)}
%endfor # s in specs
%if not fast_mode:
#################################################################
## Print API not part of the spec, needs to be generated separately
#################################################################
Expand Down Expand Up @@ -359,3 +360,4 @@ Print Operators
:project: UnifiedRuntime
:outline:
%endfor
%endif
22 changes: 22 additions & 0 deletions scripts/templates/stype_map_helpers.hpp.mako
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%!
import re
from templates import helper as th
%><%
n=namespace
N=n.upper()
x=tags['$x']
X=x.upper()
%>
// This file is autogenerated from the template at ${self.template.filename}

%for obj in th.extract_objs(specs, r"enum"):
%if obj["name"] == '$x_structure_type_t':
%for etor in obj['etors']:
%if 'UINT32' not in etor['name']:
template <>
struct stype_map<${x}_${etor['desc'][3:]}> : stype_map_impl<${X}_${etor['name'][3:]}> {};
%endif
%endfor
%endif
%endfor

15 changes: 3 additions & 12 deletions source/adapters/hip/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,24 +327,15 @@ ur_result_t USMHostMemoryProvider::allocateImpl(void **ResultPtr, size_t Size,
ur_usm_pool_handle_t_::ur_usm_pool_handle_t_(ur_context_handle_t Context,
ur_usm_pool_desc_t *PoolDesc)
: Context(Context) {
const void *pNext = PoolDesc->pNext;
while (pNext != nullptr) {
const ur_base_desc_t *BaseDesc = static_cast<const ur_base_desc_t *>(pNext);
switch (BaseDesc->stype) {
case UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC: {
const ur_usm_pool_limits_desc_t *Limits =
reinterpret_cast<const ur_usm_pool_limits_desc_t *>(BaseDesc);
if (PoolDesc) {
if (auto *Limits = find_stype_node<ur_usm_pool_limits_desc_t>(PoolDesc)) {
for (auto &config : DisjointPoolConfigs.Configs) {
config.MaxPoolableSize = Limits->maxPoolableSize;
config.SlabMinSize = Limits->minDriverAllocSize;
}
break;
}
default: {
} else {
throw UsmAllocationException(UR_RESULT_ERROR_INVALID_ARGUMENT);
}
}
pNext = BaseDesc->pNext;
}

auto MemProvider =
Expand Down
48 changes: 35 additions & 13 deletions source/adapters/level_zero/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <algorithm>
#include <climits>
#include <string.h>
#include <ur/ur.hpp>

#include "context.hpp"
#include "event.hpp"
Expand Down Expand Up @@ -183,9 +184,6 @@ static ur_result_t enqueueMemFillHelper(ur_command_t CommandType,
uint32_t NumEventsInWaitList,
const ur_event_handle_t *EventWaitList,
ur_event_handle_t *OutEvent) {
// Pattern size must be a power of two.
UR_ASSERT((PatternSize > 0) && ((PatternSize & (PatternSize - 1)) == 0),
UR_RESULT_ERROR_INVALID_VALUE);
auto &Device = Queue->Device;

// Make sure that pattern size matches the capability of the copy queues.
Expand Down Expand Up @@ -237,18 +235,42 @@ static ur_result_t enqueueMemFillHelper(ur_command_t CommandType,
const auto &ZeCommandList = CommandList->first;
const auto &WaitList = (*Event)->WaitList;

ZE2UR_CALL(zeCommandListAppendMemoryFill,
(ZeCommandList, Ptr, Pattern, PatternSize, Size, ZeEvent,
WaitList.Length, WaitList.ZeEventList));
// PatternSize must be a power of two for zeCommandListAppendMemoryFill.
// When it's not, the fill is emulated with zeCommandListAppendMemoryCopy.
if (isPowerOf2(PatternSize)) {
ZE2UR_CALL(zeCommandListAppendMemoryFill,
(ZeCommandList, Ptr, Pattern, PatternSize, Size, ZeEvent,
WaitList.Length, WaitList.ZeEventList));

logger::debug("calling zeCommandListAppendMemoryFill() with"
" ZeEvent {}",
ur_cast<uint64_t>(ZeEvent));
printZeEventList(WaitList);
logger::debug("calling zeCommandListAppendMemoryFill() with"
" ZeEvent {}",
ur_cast<uint64_t>(ZeEvent));
printZeEventList(WaitList);

// Execute command list asynchronously, as the event will be used
// to track down its completion.
UR_CALL(Queue->executeCommandList(CommandList, false, OkToBatch));
// Execute command list asynchronously, as the event will be used
// to track down its completion.
UR_CALL(Queue->executeCommandList(CommandList, false, OkToBatch));
} else {
// Copy pattern into every entry in memory array pointed by Ptr.
uint32_t NumOfCopySteps = Size / PatternSize;
const void *Src = Pattern;

for (uint32_t step = 0; step < NumOfCopySteps; ++step) {
void *Dst = reinterpret_cast<void *>(reinterpret_cast<uint8_t *>(Ptr) +
step * PatternSize);
ZE2UR_CALL(zeCommandListAppendMemoryCopy,
(ZeCommandList, Dst, Src, PatternSize, ZeEvent,
WaitList.Length, WaitList.ZeEventList));
}

logger::debug("calling zeCommandListAppendMemoryCopy() with"
" ZeEvent {}",
ur_cast<uint64_t>(ZeEvent));
printZeEventList(WaitList);

// Execute command list synchronously.
UR_CALL(Queue->executeCommandList(CommandList, true, OkToBatch));
}

return UR_RESULT_SUCCESS;
}
Expand Down
4 changes: 3 additions & 1 deletion source/adapters/opencl/usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
//
//===----------------------------------------------------------------------===//

#include <ur/ur.hpp>

#include "common.hpp"

inline cl_mem_alloc_flags_intel
Expand Down Expand Up @@ -239,7 +241,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill(
return mapCLErrorToUR(CLErr);
}

if (patternSize <= 128) {
if (patternSize <= 128 && isPowerOf2(patternSize)) {
clEnqueueMemFillINTEL_fn EnqueueMemFill = nullptr;
UR_RETURN_ON_FAILURE(
cl_ext::getExtFuncFromContext<clEnqueueMemFillINTEL_fn>(
Expand Down
98 changes: 98 additions & 0 deletions source/common/stype_map_helpers.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@

// This file is autogenerated from the template at templates/stype_map_helpers.hpp.mako

template <>
struct stype_map<ur_context_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_CONTEXT_PROPERTIES> {};
template <>
struct stype_map<ur_image_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_IMAGE_DESC> {};
template <>
struct stype_map<ur_buffer_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_BUFFER_PROPERTIES> {};
template <>
struct stype_map<ur_buffer_region_t> : stype_map_impl<UR_STRUCTURE_TYPE_BUFFER_REGION> {};
template <>
struct stype_map<ur_buffer_channel_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_BUFFER_CHANNEL_PROPERTIES> {};
template <>
struct stype_map<ur_buffer_alloc_location_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_BUFFER_ALLOC_LOCATION_PROPERTIES> {};
template <>
struct stype_map<ur_program_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_PROGRAM_PROPERTIES> {};
template <>
struct stype_map<ur_usm_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_USM_DESC> {};
template <>
struct stype_map<ur_usm_host_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_USM_HOST_DESC> {};
template <>
struct stype_map<ur_usm_device_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_USM_DEVICE_DESC> {};
template <>
struct stype_map<ur_usm_pool_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_USM_POOL_DESC> {};
template <>
struct stype_map<ur_usm_pool_limits_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_USM_POOL_LIMITS_DESC> {};
template <>
struct stype_map<ur_device_binary_t> : stype_map_impl<UR_STRUCTURE_TYPE_DEVICE_BINARY> {};
template <>
struct stype_map<ur_sampler_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_SAMPLER_DESC> {};
template <>
struct stype_map<ur_queue_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_QUEUE_PROPERTIES> {};
template <>
struct stype_map<ur_queue_index_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_QUEUE_INDEX_PROPERTIES> {};
template <>
struct stype_map<ur_context_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_CONTEXT_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_kernel_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_KERNEL_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_queue_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_QUEUE_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_mem_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_MEM_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_event_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_EVENT_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_platform_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_PLATFORM_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_device_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_DEVICE_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_program_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_PROGRAM_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_sampler_native_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_SAMPLER_NATIVE_PROPERTIES> {};
template <>
struct stype_map<ur_queue_native_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_QUEUE_NATIVE_DESC> {};
template <>
struct stype_map<ur_device_partition_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_DEVICE_PARTITION_PROPERTIES> {};
template <>
struct stype_map<ur_kernel_arg_mem_obj_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_KERNEL_ARG_MEM_OBJ_PROPERTIES> {};
template <>
struct stype_map<ur_physical_mem_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_PHYSICAL_MEM_PROPERTIES> {};
template <>
struct stype_map<ur_kernel_arg_pointer_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_KERNEL_ARG_POINTER_PROPERTIES> {};
template <>
struct stype_map<ur_kernel_arg_sampler_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_KERNEL_ARG_SAMPLER_PROPERTIES> {};
template <>
struct stype_map<ur_kernel_exec_info_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_KERNEL_EXEC_INFO_PROPERTIES> {};
template <>
struct stype_map<ur_kernel_arg_value_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_KERNEL_ARG_VALUE_PROPERTIES> {};
template <>
struct stype_map<ur_kernel_arg_local_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_KERNEL_ARG_LOCAL_PROPERTIES> {};
template <>
struct stype_map<ur_usm_alloc_location_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_USM_ALLOC_LOCATION_DESC> {};
template <>
struct stype_map<ur_exp_command_buffer_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_DESC> {};
template <>
struct stype_map<ur_exp_command_buffer_update_kernel_launch_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_KERNEL_LAUNCH_DESC> {};
template <>
struct stype_map<ur_exp_command_buffer_update_memobj_arg_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_MEMOBJ_ARG_DESC> {};
template <>
struct stype_map<ur_exp_command_buffer_update_pointer_arg_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_POINTER_ARG_DESC> {};
template <>
struct stype_map<ur_exp_command_buffer_update_value_arg_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_COMMAND_BUFFER_UPDATE_VALUE_ARG_DESC> {};
template <>
struct stype_map<ur_exp_sampler_mip_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_SAMPLER_MIP_PROPERTIES> {};
template <>
struct stype_map<ur_exp_interop_mem_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_INTEROP_MEM_DESC> {};
template <>
struct stype_map<ur_exp_interop_semaphore_desc_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_INTEROP_SEMAPHORE_DESC> {};
template <>
struct stype_map<ur_exp_file_descriptor_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_FILE_DESCRIPTOR> {};
template <>
struct stype_map<ur_exp_win32_handle_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_WIN32_HANDLE> {};
template <>
struct stype_map<ur_exp_sampler_addr_modes_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_SAMPLER_ADDR_MODES> {};
template <>
struct stype_map<ur_exp_sampler_cubemap_properties_t> : stype_map_impl<UR_STRUCTURE_TYPE_EXP_SAMPLER_CUBEMAP_PROPERTIES> {};

Loading

0 comments on commit 4ed848e

Please sign in to comment.