Skip to content

Commit 87634dd

Browse files
committed
[Offload] Implement remaining API for basic memory operations and kernel exec
1 parent 6720465 commit 87634dd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3424
-250
lines changed

offload/liboffload/API/Common.td

+23-4
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,38 @@ def : Handle {
6262
let desc = "Handle of context object";
6363
}
6464

65+
def : Handle {
66+
let name = "ol_queue_handle_t";
67+
let desc = "Handle of queue object";
68+
}
69+
70+
def : Handle {
71+
let name = "ol_event_handle_t";
72+
let desc = "Handle of event object";
73+
}
74+
75+
def : Handle {
76+
let name = "ol_program_handle_t";
77+
let desc = "Handle of program object";
78+
}
79+
80+
def : Handle {
81+
let name = "ol_kernel_handle_t";
82+
let desc = "Handle of kernel object";
83+
}
84+
6585
def : Enum {
6686
let name = "ol_errc_t";
6787
let desc = "Defines Return/Error codes";
6888
let etors =[
6989
Etor<"SUCCESS", "Success">,
7090
Etor<"INVALID_VALUE", "Invalid Value">,
7191
Etor<"INVALID_PLATFORM", "Invalid platform">,
72-
Etor<"DEVICE_NOT_FOUND", "Device not found">,
7392
Etor<"INVALID_DEVICE", "Invalid device">,
74-
Etor<"DEVICE_LOST", "Device hung, reset, was removed, or driver update occurred">,
75-
Etor<"UNINITIALIZED", "plugin is not initialized or specific entry-point is not implemented">,
93+
Etor<"INVALID_QUEUE", "Invalid queue">,
94+
Etor<"INVALID_EVENT", "Invalid event">,
95+
Etor<"INVALID_KERNEL_NAME", "Named kernel not found in the program binary">,
7696
Etor<"OUT_OF_RESOURCES", "Out of resources">,
77-
Etor<"UNSUPPORTED_VERSION", "generic error code for unsupported versions">,
7897
Etor<"UNSUPPORTED_FEATURE", "generic error code for unsupported features">,
7998
Etor<"INVALID_ARGUMENT", "generic error code for invalid arguments">,
8099
Etor<"INVALID_NULL_HANDLE", "handle argument is not valid">,

offload/liboffload/API/Device.td

+18-6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def : Enum {
1414
let name = "ol_device_type_t";
15-
let desc = "Supported device types";
15+
let desc = "Supported device types.";
1616
let etors =[
1717
Etor<"DEFAULT", "The default device type as preferred by the runtime">,
1818
Etor<"ALL", "Devices of all types">,
@@ -23,7 +23,7 @@ def : Enum {
2323

2424
def : Enum {
2525
let name = "ol_device_info_t";
26-
let desc = "Supported device info";
26+
let desc = "Supported device info.";
2727
let is_typed = 1;
2828
let etors =[
2929
TaggedEtor<"TYPE", "ol_device_type_t", "type of the device">,
@@ -36,7 +36,7 @@ def : Enum {
3636

3737
def : Function {
3838
let name = "olGetDeviceCount";
39-
let desc = "Retrieves the number of available devices within a platform";
39+
let desc = "Retrieves the number of available devices within a platform.";
4040
let params = [
4141
Param<"ol_platform_handle_t", "Platform", "handle of the platform instance", PARAM_IN>,
4242
Param<"uint32_t*", "NumDevices", "pointer to the number of devices.", PARAM_OUT>
@@ -46,7 +46,7 @@ def : Function {
4646

4747
def : Function {
4848
let name = "olGetDevice";
49-
let desc = "Retrieves devices within a platform";
49+
let desc = "Retrieves devices within a platform.";
5050
let details = [
5151
"Multiple calls to this function will return identical device handles, in the same order.",
5252
];
@@ -66,7 +66,7 @@ def : Function {
6666

6767
def : Function {
6868
let name = "olGetDeviceInfo";
69-
let desc = "Queries the given property of the device";
69+
let desc = "Queries the given property of the device.";
7070
let details = [];
7171
let params = [
7272
Param<"ol_device_handle_t", "Device", "handle of the device instance", PARAM_IN>,
@@ -90,7 +90,7 @@ def : Function {
9090

9191
def : Function {
9292
let name = "olGetDeviceInfoSize";
93-
let desc = "Returns the storage size of the given device query";
93+
let desc = "Returns the storage size of the given device query.";
9494
let details = [];
9595
let params = [
9696
Param<"ol_device_handle_t", "Device", "handle of the device instance", PARAM_IN>,
@@ -104,3 +104,15 @@ def : Function {
104104
Return<"OL_ERRC_INVALID_DEVICE">
105105
];
106106
}
107+
108+
def : Function {
109+
let name = "olGetHostDevice";
110+
let desc = "Return the special host device used to represent the host in memory transfer operations.";
111+
let details = [
112+
"The host device does not support queues"
113+
];
114+
let params = [
115+
Param<"ol_device_handle_t*", "Device", "Output pointer for the device">
116+
]; // TODO: Take a platform?
117+
let returns = [];
118+
}

offload/liboffload/API/Enqueue.td

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//===-- Enqueue.td - Enqueue definitions for Offload -------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains Offload API definitions related to enqueable operations
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
def : Function {
14+
let name = "olEnqueueMemcpy";
15+
let desc = "Enqueue a memcpy operation.";
16+
let details = [
17+
"For host pointers, use the device returned by olGetHostDevice",
18+
"At least one device must be a non-host device"
19+
];
20+
let params = [
21+
Param<"ol_queue_handle_t", "Queue", "handle of the queue", PARAM_IN>,
22+
Param<"void*", "DstPtr", "pointer to copy to", PARAM_IN>,
23+
Param<"ol_device_handle_t", "DstDevice", "device that DstPtr belongs to", PARAM_IN>,
24+
Param<"void*", "SrcPtr", "pointer to copy from", PARAM_IN>,
25+
Param<"ol_device_handle_t", "SrcDevice", "device that SrcPtr belongs to", PARAM_IN>,
26+
Param<"size_t", "Size", "size in bytes of data to copy", PARAM_IN>,
27+
Param<"ol_event_handle_t*", "EventOut", "optional recorded event for the enqueued operation", PARAM_OUT_OPTIONAL>
28+
];
29+
let returns = [
30+
Return<"OL_ERRC_INVALID_SIZE", ["`Size == 0`"]>
31+
];
32+
}
33+
34+
def : Struct {
35+
let name = "ol_kernel_launch_size_args_t";
36+
let desc = "Size-related arguments for a kernel launch.";
37+
let members = [
38+
StructMember<"size_t", "Dimensions", "Number of work dimensions">,
39+
StructMember<"size_t", "NumGroupsX", "Number of work groups on the X dimension">,
40+
StructMember<"size_t", "NumGroupsY", "Number of work groups on the Y dimension">,
41+
StructMember<"size_t", "NumGroupsZ", "Number of work groups on the Z dimension">,
42+
StructMember<"size_t", "GroupSizeX", "Size of a work group on the X dimension.">,
43+
StructMember<"size_t", "GroupSizeY", "Size of a work group on the Y dimension.">,
44+
StructMember<"size_t", "GroupSizeZ", "Size of a work group on the Z dimension.">
45+
];
46+
}
47+
48+
def : Function {
49+
let name = "olEnqueueKernelLaunch";
50+
let desc = "Enqueue a kernel launch with the specified size and parameters.";
51+
let details = [];
52+
let params = [
53+
Param<"ol_queue_handle_t", "Queue", "handle of the queue", PARAM_IN>,
54+
Param<"ol_kernel_handle_t", "Kernel", "handle of the kernel", PARAM_IN>,
55+
Param<"const void*", "ArgumentsData", "pointer to the kernel argument struct", PARAM_IN>,
56+
Param<"size_t", "ArgumentsSize", "size of the kernel argument struct", PARAM_IN>,
57+
Param<"const ol_kernel_launch_size_args_t*", "LaunchSizeArgs", "pointer to the struct containing launch size parameters", PARAM_IN>,
58+
Param<"ol_event_handle_t*", "EventOut", "optional recorded event for the enqueued operation", PARAM_OUT_OPTIONAL>
59+
];
60+
let returns = [];
61+
}

offload/liboffload/API/Event.td

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//===-- Event.td - Event definitions for Offload -----------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains Offload API definitions related to the event handle
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
def : Function {
14+
let name = "olRetainEvent";
15+
let desc = "Increment the event's reference count.";
16+
let details = [];
17+
let params = [
18+
Param<"ol_event_handle_t", "Event", "handle of the event", PARAM_IN>
19+
];
20+
let returns = [];
21+
}
22+
23+
def : Function {
24+
let name = "olReleaseEvent";
25+
let desc = "Decrement the event's reference count, and free it if the reference count reaches 0.";
26+
let details = [];
27+
let params = [
28+
Param<"ol_event_handle_t", "Event", "handle of the event", PARAM_IN>
29+
];
30+
let returns = [];
31+
}
32+
33+
def : Function {
34+
let name = "olWaitEvent";
35+
let desc = "Wait for the event to be complete.";
36+
let details = [];
37+
let params = [
38+
Param<"ol_event_handle_t", "Event", "handle of the event", PARAM_IN>
39+
];
40+
let returns = [];
41+
}

offload/liboffload/API/Kernel.td

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===-- Kernel.td - Kernel definitions for Offload ---------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains Offload API definitions related to the kernel handle
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
def : Function {
14+
let name = "olCreateKernel";
15+
let desc = "Create a kernel from the function identified by `KernelName` in the given program.";
16+
let details = [
17+
"The created kernel has an initial reference count of 1."
18+
];
19+
let params = [
20+
Param<"ol_program_handle_t", "Program", "handle of the program", PARAM_IN>,
21+
Param<"const char*", "KernelName", "name of the kernel entry point in the program", PARAM_IN>,
22+
Param<"ol_kernel_handle_t*", "Kernel", "output pointer for the created kernel", PARAM_OUT>
23+
];
24+
let returns = [];
25+
}
26+
27+
def : Function {
28+
let name = "olRetainKernel";
29+
let desc = "Increment the kernel's reference count.";
30+
let details = [];
31+
let params = [
32+
Param<"ol_kernel_handle_t", "Kernel", "handle of the kernel", PARAM_IN>
33+
];
34+
let returns = [];
35+
}
36+
37+
def : Function {
38+
let name = "olReleaseKernel";
39+
let desc = "Decrement the kernel's reference count, and free it if the reference count reaches 0.";
40+
let details = [];
41+
let params = [
42+
Param<"ol_kernel_handle_t", "Kernel", "handle of the kernel", PARAM_IN>
43+
];
44+
let returns = [];
45+
}

offload/liboffload/API/Memory.td

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//===-- Memory.td - Memory definitions for Offload ---------*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file contains Offload API definitions related to memory allocations
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
def : Enum {
14+
let name = "ol_alloc_type_t";
15+
let desc = "Represents the type of allocation made with olMemAlloc.";
16+
let etors = [
17+
Etor<"HOST", "Host allocation">,
18+
Etor<"DEVICE", "Device allocation">,
19+
Etor<"SHARED", "Shared allocation">
20+
];
21+
}
22+
23+
def : Function {
24+
let name = "olMemAlloc";
25+
let desc = "Creates a memory allocation on the specified device.";
26+
let params = [
27+
Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>,
28+
Param<"ol_alloc_type_t", "Type", "type of the allocation", PARAM_IN>,
29+
Param<"size_t", "Size", "size of the allocation in bytes", PARAM_IN>,
30+
Param<"void**", "AllocationOut", "output for the allocated pointer", PARAM_OUT>
31+
];
32+
let returns = [
33+
Return<"OL_ERRC_INVALID_SIZE", [
34+
"`Size == 0`"
35+
]>
36+
];
37+
}
38+
39+
def : Function {
40+
let name = "olMemFree";
41+
let desc = "Frees a memory allocation previously made by olMemAlloc.";
42+
let params = [
43+
Param<"ol_device_handle_t", "Device", "handle of the device to allocate on", PARAM_IN>,
44+
Param<"ol_alloc_type_t", "Type", "type of the allocation", PARAM_IN>,
45+
Param<"void*", "Address", "address of the allocation to free", PARAM_IN>,
46+
];
47+
let returns = [];
48+
}

offload/liboffload/API/OffloadAPI.td

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ include "APIDefs.td"
1313
include "Common.td"
1414
include "Platform.td"
1515
include "Device.td"
16+
include "Memory.td"
17+
include "Queue.td"
18+
include "Event.td"
19+
include "Enqueue.td"
20+
include "Program.td"
21+
include "Kernel.td"

offload/liboffload/API/Platform.td

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212
def : Function {
1313
let name = "olGetPlatform";
14-
let desc = "Retrieves all available platforms";
14+
let desc = "Retrieves all available platforms.";
1515
let details = [
1616
"Multiple calls to this function will return identical platforms handles, in the same order.",
1717
];
@@ -35,7 +35,7 @@ def : Function {
3535

3636
def : Function {
3737
let name = "olGetPlatformCount";
38-
let desc = "Retrieves the number of available platforms";
38+
let desc = "Retrieves the number of available platforms.";
3939
let params = [
4040
Param<"uint32_t*",
4141
"NumPlatforms", "returns the total number of platforms available.",
@@ -46,7 +46,7 @@ def : Function {
4646

4747
def : Enum {
4848
let name = "ol_platform_info_t";
49-
let desc = "Supported platform info";
49+
let desc = "Supported platform info.";
5050
let is_typed = 1;
5151
let etors = [
5252
TaggedEtor<"NAME", "char[]", "The string denoting name of the platform. The size of the info needs to be dynamically queried.">,
@@ -58,7 +58,7 @@ def : Enum {
5858

5959
def : Enum {
6060
let name = "ol_platform_backend_t";
61-
let desc = "Identifies the native backend of the platform";
61+
let desc = "Identifies the native backend of the platform.";
6262
let etors =[
6363
Etor<"UNKNOWN", "The backend is not recognized">,
6464
Etor<"CUDA", "The backend is CUDA">,
@@ -68,7 +68,7 @@ def : Enum {
6868

6969
def : Function {
7070
let name = "olGetPlatformInfo";
71-
let desc = "Queries the given property of the platform";
71+
let desc = "Queries the given property of the platform.";
7272
let details = [
7373
"`olGetPlatformInfoSize` can be used to query the storage size "
7474
"required for the given query."
@@ -96,7 +96,7 @@ def : Function {
9696

9797
def : Function {
9898
let name = "olGetPlatformInfoSize";
99-
let desc = "Returns the storage size of the given platform query";
99+
let desc = "Returns the storage size of the given platform query.";
100100
let details = [];
101101
let params = [
102102
Param<"ol_platform_handle_t", "Platform", "handle of the platform", PARAM_IN>,

0 commit comments

Comments
 (0)
close