mirror of
https://github.com/siemens-mobile-hacks/llvm-c166.git
synced 2026-11-25 21:45:57 +00:00
Add the initial Context handle API to liboffload:
- olCreateContext / olDestroyContext
- olGetContextInfo / olGetContextInfoSize
- OL_ERRC_INVALID_CONTEXT error code
- OL_CONTEXT_INFO_{NUM_DEVICES,DEVICES,PLATFORM} queries
This is the first patch in a series. I decided to split the original
change into multiple smaller PRs to make the review process faster and
more manageable.
This patch introduces context management functions, but the context
handle is not used anywhere yet. The following patches will extend the
API to use contexts in:
``` c
ol_result_t olMemAlloc(ol_context_handle_t, ol_device_handle_t, ol_alloc_type_t, size_t, void**);
ol_result_t olMemFree(ol_context_handle_t, void*);
ol_result_t olGetMemInfo(ol_context_handle_t, const void*, ol_mem_info_t, size_t, void*);
ol_result_t olGetMemInfoSize(ol_context_handle_t, const void*, ol_mem_info_t, size_t*);
ol_result_t olCreateQueue(ol_context_handle_t, ol_device_handle_t, ol_queue_handle_t*);
ol_result_t olCreateProgram(ol_context_handle_t, ol_device_handle_t, const void*, size_t, ol_program_handle_t*);
```
You can also take a look at #201398, which contains the first version of
the complete change. I'm cleaning it up as I go, so the patches in this
series are not a direct 1:1 split of that PR.
92 lines
3.8 KiB
TableGen
92 lines
3.8 KiB
TableGen
//===-- Context.td - Context definitions for Offload -------*- tablegen -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains Offload API definitions related to the Context
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
def olCreateContext : Function {
|
|
let desc = "Create a context grouping the given devices.";
|
|
let details = [
|
|
"All devices must belong to the same platform.",
|
|
"A context enables resource sharing between the devices it groups and "
|
|
"isolates those resources from other contexts: resources (such as memory "
|
|
"allocations) created within a context cannot be used outside of it.",
|
|
"The returned context must be released with a subsequent call to "
|
|
"`olDestroyContext`.",
|
|
"This function is thread safe."
|
|
];
|
|
let params = [
|
|
Param<"size_t", "DevicesCount", "number of devices in `Devices`", PARAM_IN>,
|
|
Param<"ol_device_handle_t*", "Devices", "array of device handles to include in the context", PARAM_IN>,
|
|
Param<"ol_context_handle_t*", "Context", "output pointer for the created context", PARAM_OUT>
|
|
];
|
|
let returns = [
|
|
Return<"OL_ERRC_INVALID_SIZE", [
|
|
"`DevicesCount == 0`"
|
|
]>,
|
|
Return<"OL_ERRC_INVALID_DEVICE", [
|
|
"the devices in `Devices` do not all belong to the same platform"
|
|
]>
|
|
];
|
|
}
|
|
|
|
def olDestroyContext : Function {
|
|
let desc = "Destroy the context and free all underlying resources.";
|
|
let details = [
|
|
"All resources tied to the context (such as memory allocations) "
|
|
"should be released before destroying it. Any resource that is still "
|
|
"tied to the context at this point is left in an undefined state and "
|
|
"must not be used afterwards.",
|
|
"Thread safe with respect to other contexts."
|
|
];
|
|
let params = [
|
|
Param<"ol_context_handle_t", "Context", "handle of the context to destroy", PARAM_IN>
|
|
];
|
|
let returns = [];
|
|
}
|
|
|
|
def ol_context_info_t : Enum {
|
|
let desc = "Supported context info.";
|
|
let is_typed = 1;
|
|
let etors = [
|
|
TaggedEtor<"NUM_DEVICES", "size_t", "The number of devices in the context.">,
|
|
TaggedEtor<"DEVICES", "ol_device_handle_t *", "The devices in the context. The returned array has NUM_DEVICES entries.">,
|
|
TaggedEtor<"PLATFORM", "ol_platform_handle_t", "The platform associated with the context.">,
|
|
];
|
|
}
|
|
|
|
def olGetContextInfo : Function {
|
|
let desc = "Queries the given property of the context.";
|
|
let params = [
|
|
Param<"ol_context_handle_t", "Context", "handle of the context", PARAM_IN>,
|
|
Param<"ol_context_info_t", "PropName", "type of the info to retrieve", PARAM_IN>,
|
|
Param<"size_t", "PropSize", "the number of bytes pointed to by PropValue.", PARAM_IN>,
|
|
TypeTaggedParam<"void*", "PropValue", "array of bytes holding the info. "
|
|
"If Size is not equal to or greater to the real number of bytes needed to return the info "
|
|
"then the OL_ERRC_INVALID_SIZE error is returned and PropValue is not used.", PARAM_OUT,
|
|
TypeInfo<"PropName" , "PropSize">>
|
|
];
|
|
let returns = [
|
|
Return<"OL_ERRC_INVALID_SIZE", [
|
|
"`PropSize == 0`",
|
|
"If `PropSize` is less than the real number of bytes needed to return the info."
|
|
]>
|
|
];
|
|
}
|
|
|
|
def olGetContextInfoSize : Function {
|
|
let desc = "Returns the storage size of the given context query.";
|
|
let details = [];
|
|
let params = [
|
|
Param<"ol_context_handle_t", "Context", "handle of the context", PARAM_IN>,
|
|
Param<"ol_context_info_t", "PropName", "type of the info to query", PARAM_IN>,
|
|
Param<"size_t*", "PropSizeRet", "pointer to the number of bytes required to store the query", PARAM_OUT>
|
|
];
|
|
let returns = [];
|
|
}
|