|
| 1 | +<%! |
| 2 | +import re |
| 3 | +from templates import helper as th |
| 4 | +%><% |
| 5 | + n=namespace |
| 6 | + N=n.upper() |
| 7 | +
|
| 8 | + x=tags['$x'] |
| 9 | + X=x.upper() |
| 10 | + Adapter=adapter.upper() |
| 11 | +%>//===--------- ${n}_interface_loader.cpp - Level Zero Adapter ------------===// |
| 12 | +// |
| 13 | +// Copyright (C) 2024 Intel Corporation |
| 14 | +// |
| 15 | +// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM |
| 16 | +// Exceptions. See LICENSE.TXT |
| 17 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 18 | +// |
| 19 | +//===----------------------------------------------------------------------===// |
| 20 | +#include <${n}_api.h> |
| 21 | +#include <${n}_ddi.h> |
| 22 | + |
| 23 | +#include "ur_interface_loader.hpp" |
| 24 | + |
| 25 | +static ur_result_t validateProcInputs(ur_api_version_t version, void *pDdiTable) { |
| 26 | + if (nullptr == pDdiTable) { |
| 27 | + return UR_RESULT_ERROR_INVALID_NULL_POINTER; |
| 28 | + } |
| 29 | + // Pre 1.0 we enforce loader and adapter must have same version. |
| 30 | + // Post 1.0 only major version match should be required. |
| 31 | + if (version != UR_API_VERSION_CURRENT) { |
| 32 | + return UR_RESULT_ERROR_UNSUPPORTED_VERSION; |
| 33 | + } |
| 34 | + return UR_RESULT_SUCCESS; |
| 35 | +} |
| 36 | + |
| 37 | +#ifdef UR_STATIC_ADAPTER_${Adapter} |
| 38 | +namespace ${n}::${adapter} { |
| 39 | +#elif defined(__cplusplus) |
| 40 | +extern "C" { |
| 41 | +#endif |
| 42 | + |
| 43 | +%for tbl in th.get_pfntables(specs, meta, n, tags): |
| 44 | +${X}_APIEXPORT ${x}_result_t ${X}_APICALL ${tbl['export']['name']}( |
| 45 | + %for line in th.make_param_lines(n, tags, tbl['export'], format=["type", "name", "delim"]): |
| 46 | + ${line} |
| 47 | + %endfor |
| 48 | + ) |
| 49 | +{ |
| 50 | + auto result = validateProcInputs(version, pDdiTable); |
| 51 | + if (UR_RESULT_SUCCESS != result) { |
| 52 | + return result; |
| 53 | + } |
| 54 | + |
| 55 | + %for obj in tbl['functions']: |
| 56 | + pDdiTable->${th.append_ws(th.make_pfn_name(n, tags, obj), 43)} = ${n}::${adapter}::${th.make_func_name(n, tags, obj)}; |
| 57 | + %endfor |
| 58 | + |
| 59 | + return result; |
| 60 | +} |
| 61 | + |
| 62 | +%endfor |
| 63 | + |
| 64 | +#ifdef UR_STATIC_ADAPTER_${Adapter} |
| 65 | +} // namespace ur::${adapter} |
| 66 | +#elif defined(__cplusplus) |
| 67 | +} // extern "C" |
| 68 | +#endif |
| 69 | + |
| 70 | +#ifdef UR_STATIC_ADAPTER_${Adapter} |
| 71 | +namespace ur::${adapter} { |
| 72 | +ur_result_t urAdapterGetDdiTables(ur_dditable_t *ddi) { |
| 73 | + if (ddi == nullptr) { |
| 74 | + return UR_RESULT_ERROR_INVALID_NULL_POINTER; |
| 75 | + } |
| 76 | + |
| 77 | + ur_result_t result; |
| 78 | + |
| 79 | +%for tbl in th.get_pfntables(specs, meta, n, tags): |
| 80 | + result = ${n}::${adapter}::${tbl['export']['name']}( ${X}_API_VERSION_CURRENT, &ddi->${tbl['name']} ); |
| 81 | + if (result != UR_RESULT_SUCCESS) |
| 82 | + return result; |
| 83 | +%endfor |
| 84 | + |
| 85 | + return result; |
| 86 | +} |
| 87 | +} |
| 88 | +#endif |
0 commit comments