1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//===----------------------------------------------------------------------===//
// Copyright (c) 2026, Modular Inc. All rights reserved.
//
// Licensed under the Apache License v2.0 with LLVM Exceptions:
// https://llvm.org/LICENSE.txt
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
/// Creates a device of the specified type and ID.
///
/// For HOST devices, the ID is typically 0.
/// For ACCELERATOR devices, the ID specifies which GPU to use (0 for first
/// ACCELERATOR, etc.).
///
/// @param type The type of device to create (M_HOST or M_ACCELERATOR).
/// @param id The device ID. Use 0 for the default device of that type.
/// @param status The status object for reporting errors.
///
/// @returns A pointer to the device. You are responsible for the memory
/// associated with the pointer returned. The memory can be deallocated by
/// calling `M_freeDevice()`. Returns `NULL` if the device could not be created,
/// with an error message in the status.
MODULAR_API_EXPORT M_Device *;
/// Gets the type of a device.
///
/// @param device The device.
///
/// @returns The device type (M_HOST or M_ACCELERATOR).
MODULAR_API_EXPORT M_DeviceType ;
/// Gets the ID of a device.
///
/// @param device The device.
///
/// @returns The device ID.
MODULAR_API_EXPORT int ;
/// Checks if the device is a host device.
///
/// @param device The device.
///
/// @returns `1` if the device is the host, `0` otherwise.
MODULAR_API_EXPORT int ;
/// Synchronizes the device, ensuring all operations complete.
///
/// This blocks until all pending operations on the device have completed.
///
/// @param device The device to synchronize.
/// @param status The status object for reporting errors.
MODULAR_API_EXPORT void ;
/// Gets the label of a device (e.g., "cpu" or "gpu").
///
/// @param device The device.
///
/// @returns A string containing the device label. The returned string is owned
/// by the device and should not be freed. Returns `NULL` if the device is
/// invalid.
MODULAR_API_EXPORT const char *;
/// Deallocates the memory for a device. No-op if `device` is `NULL`.
///
/// @param device The device to deallocate.
MODULAR_API_EXPORT void ;
/// Returns the number of available accelerator (GPU) devices.
///
/// @returns The number of accelerator devices available on the system.
MODULAR_API_EXPORT int ;
// MAX_C_DEVICE_H