-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a shared library for printing Unified Runtime objects with a C API.
- Loading branch information
Showing
13 changed files
with
5,632 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<%! | ||
import re | ||
from templates import helper as th | ||
%><% | ||
n=namespace | ||
N=n.upper() | ||
x=tags['$x'] | ||
X=x.upper() | ||
%>/* | ||
* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
* See LICENSE.TXT | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
* | ||
* @file ${n}_print.cpp | ||
* | ||
*/ | ||
|
||
#include "${n}_print.h" | ||
#include "${n}_print.hpp" | ||
|
||
#include <sstream> | ||
#include <string.h> | ||
|
||
using namespace ${x}_print; | ||
|
||
<%def name="ss_copy(item_name)">std::stringstream ss; | ||
ss << ${item_name}; | ||
strncpy(&ss, out, size); | ||
</%def> | ||
|
||
void strncpy(std::stringstream *ss, char *out, const size_t size) { | ||
#if defined(_WIN32) | ||
strncpy_s(out, size, ss->str().c_str(), ss->str().size() + 1); | ||
#else | ||
strncpy(out, ss->str().c_str(), size); | ||
#endif | ||
} | ||
|
||
%for spec in specs: | ||
%for obj in spec['objects']: | ||
## ENUM ####################################################################### | ||
%if re.match(r"enum", obj['type']): | ||
ur_result_t ${th.make_func_name_with_prefix('urPrint', obj['name'])}(enum ${th.make_enum_name(n, tags, obj)} value, char *out, const size_t size) { | ||
${ss_copy("value")} | ||
return ${X}_RESULT_SUCCESS; | ||
} | ||
|
||
## STRUCT ##################################################################### | ||
%elif re.match(r"struct", obj['type']): | ||
ur_result_t ${th.make_func_name_with_prefix('urPrint', obj['name'])}(const ${obj['type']} ${th.make_type_name(n, tags, obj)} params, char *out, const size_t size) { | ||
${ss_copy("params")} | ||
return ${X}_RESULT_SUCCESS; | ||
} | ||
|
||
%endif | ||
%endfor # obj in spec['objects'] | ||
%endfor | ||
|
||
%for tbl in th.get_pfncbtables(specs, meta, n, tags): | ||
%for obj in tbl['functions']: | ||
<% | ||
name = th.make_pfncb_param_type(n, tags, obj) | ||
%> | ||
ur_result_t ${th.make_func_name_with_prefix('urPrint', name)}(const struct ${th.make_pfncb_param_type(n, tags, obj)} *params, char *out, const size_t size) { | ||
${ss_copy("params")} | ||
return ${X}_RESULT_SUCCESS; | ||
} | ||
|
||
%endfor | ||
%endfor | ||
|
||
ur_result_t urPrintFunctionParams(enum ur_function_t function, const void *params, char *out, const size_t size) { | ||
std::stringstream ss; | ||
switch(function) { | ||
%for tbl in th.get_pfncbtables(specs, meta, n, tags): | ||
%for obj in tbl['functions']: | ||
case ${th.make_func_etor(n, tags, obj)}: { | ||
ss << (const struct ${th.make_pfncb_param_type(n, tags, obj)} *)params; | ||
strncpy(&ss, out, size); | ||
return ${X}_RESULT_SUCCESS; | ||
} | ||
%endfor | ||
%endfor | ||
default: | ||
return ${X}_RESULT_SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<%! | ||
import re | ||
from templates import helper as th | ||
%><% | ||
n=namespace | ||
N=n.upper() | ||
x=tags['$x'] | ||
X=x.upper() | ||
%>/* | ||
* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
* See LICENSE.TXT | ||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
* | ||
* @file ${n}_print.h | ||
* | ||
*/ | ||
#ifndef ${X}_PRINT_H | ||
#define ${X}_PRINT_H 1 | ||
|
||
#include "${x}_api.h" | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
## Declarations ############################################################### | ||
%for spec in specs: | ||
%for obj in spec['objects']: | ||
%if re.match(r"(enum)", obj['type']): | ||
UR_DLLEXPORT ur_result_t UR_APICALL ${th.make_func_name_with_prefix('urPrint', obj['name'])}(enum ${th.make_enum_name(n, tags, obj)} value, char *out, const size_t size); | ||
%elif re.match(r"struct", obj['type']): | ||
UR_DLLEXPORT ur_result_t UR_APICALL ${th.make_func_name_with_prefix('urPrint', obj['name'])}(const ${obj['type']} ${th.make_type_name(n, tags, obj)} params, char *out, const size_t size); | ||
%endif | ||
%endfor # obj in spec['objects'] | ||
%endfor | ||
|
||
%for tbl in th.get_pfncbtables(specs, meta, n, tags): | ||
%for obj in tbl['functions']: | ||
<% | ||
name = th.make_pfncb_param_type(n, tags, obj) | ||
%> | ||
UR_DLLEXPORT ur_result_t UR_APICALL ${th.make_func_name_with_prefix('urPrint', name)}(const struct ${th.make_pfncb_param_type(n, tags, obj)} *params, char *out, const size_t size); | ||
%endfor | ||
%endfor | ||
|
||
UR_DLLEXPORT ur_result_t UR_APICALL urPrintFunctionParams(enum ur_function_t function, const void *params, char *out, const size_t size); | ||
|
||
#if defined(__cplusplus) | ||
} // extern "C" | ||
#endif | ||
|
||
#endif /* ${X}_PRINT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (C) 2023 Intel Corporation | ||
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. | ||
# See LICENSE.TXT | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
set(TARGET_NAME ur_print) | ||
|
||
add_ur_library(${TARGET_NAME} SHARED | ||
ur_print.h | ||
ur_print.cpp | ||
) | ||
add_library(${PROJECT_NAME}::print ALIAS ur_print) | ||
|
||
target_link_libraries(${TARGET_NAME} PRIVATE | ||
${PROJECT_NAME}::headers | ||
) | ||
|
||
target_include_directories(${TARGET_NAME} PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> | ||
$<INSTALL_INTERFACE:source/print> | ||
) | ||
|
||
install(TARGETS ${TARGET_NAME} | ||
EXPORT ${PROJECT_NAME}-targets | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT unified-runtime | ||
) | ||
|
||
install(FILES ur_print.h | ||
DESTINATION include) |
Oops, something went wrong.