gokashi commited on
Commit
a545837
·
verified ·
1 Parent(s): 498b714

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. deps/exla/cache/xla_extension/include/include/cpuinfo.h +2331 -0
  2. deps/exla/cache/xla_extension/include/include/dnnl.h +22 -0
  3. deps/exla/cache/xla_extension/include/include/dnnl.hpp +22 -0
  4. deps/exla/cache/xla_extension/include/include/dnnl_config.h +22 -0
  5. deps/exla/cache/xla_extension/include/include/dnnl_debug.h +22 -0
  6. deps/exla/cache/xla_extension/include/include/dnnl_ocl.h +22 -0
  7. deps/exla/cache/xla_extension/include/include/dnnl_ocl.hpp +22 -0
  8. deps/exla/cache/xla_extension/include/include/dnnl_sycl.h +22 -0
  9. deps/exla/cache/xla_extension/include/include/dnnl_sycl.hpp +22 -0
  10. deps/exla/cache/xla_extension/include/include/dnnl_sycl_types.h +22 -0
  11. deps/exla/cache/xla_extension/include/include/dnnl_threadpool.h +22 -0
  12. deps/exla/cache/xla_extension/include/include/dnnl_threadpool.hpp +22 -0
  13. deps/exla/cache/xla_extension/include/include/dnnl_threadpool_iface.hpp +22 -0
  14. deps/exla/cache/xla_extension/include/include/dnnl_types.h +22 -0
  15. deps/exla/cache/xla_extension/include/include/dnnl_version.h +22 -0
  16. deps/exla/cache/xla_extension/include/include/fxdiv.h +425 -0
  17. deps/exla/cache/xla_extension/include/include/hwloc.h +0 -0
  18. deps/exla/cache/xla_extension/include/include/hwloc/autogen/config.h +241 -0
  19. deps/exla/cache/xla_extension/include/include/hwloc/bitmap.h +494 -0
  20. deps/exla/cache/xla_extension/include/include/hwloc/cpukinds.h +193 -0
  21. deps/exla/cache/xla_extension/include/include/hwloc/deprecated.h +217 -0
  22. deps/exla/cache/xla_extension/include/include/hwloc/diff.h +289 -0
  23. deps/exla/cache/xla_extension/include/include/hwloc/distances.h +471 -0
  24. deps/exla/cache/xla_extension/include/include/hwloc/export.h +278 -0
  25. deps/exla/cache/xla_extension/include/include/hwloc/helper.h +1231 -0
  26. deps/exla/cache/xla_extension/include/include/hwloc/inlines.h +146 -0
  27. deps/exla/cache/xla_extension/include/include/hwloc/linux.h +87 -0
  28. deps/exla/cache/xla_extension/include/include/hwloc/memattrs.h +455 -0
  29. deps/exla/cache/xla_extension/include/include/hwloc/plugins.h +689 -0
  30. deps/exla/cache/xla_extension/include/include/hwloc/rename.h +901 -0
  31. deps/exla/cache/xla_extension/include/include/hwloc/shmem.h +137 -0
  32. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl.h +0 -0
  33. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl.hpp +0 -0
  34. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_common.h +175 -0
  35. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_common.hpp +479 -0
  36. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_common_types.h +257 -0
  37. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_config.h +204 -0
  38. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_config.h.in +204 -0
  39. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_debug.h +60 -0
  40. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph.h +735 -0
  41. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph.hpp +1569 -0
  42. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_ocl.h +144 -0
  43. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_ocl.hpp +147 -0
  44. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_sycl.h +94 -0
  45. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_sycl.hpp +124 -0
  46. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_types.h +465 -0
  47. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_ocl.h +247 -0
  48. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_ocl.hpp +338 -0
  49. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_ocl_types.h +51 -0
  50. deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_sycl.h +169 -0
deps/exla/cache/xla_extension/include/include/cpuinfo.h ADDED
@@ -0,0 +1,2331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #ifndef CPUINFO_H
3
+ #define CPUINFO_H
4
+
5
+ #ifndef __cplusplus
6
+ #include <stdbool.h>
7
+ #endif
8
+
9
+ #ifdef __APPLE__
10
+ #include <TargetConditionals.h>
11
+ #endif
12
+
13
+ #include <stdint.h>
14
+
15
+ /* Identify architecture and define corresponding macro */
16
+
17
+ #if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86)
18
+ #define CPUINFO_ARCH_X86 1
19
+ #endif
20
+
21
+ #if defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
22
+ #define CPUINFO_ARCH_X86_64 1
23
+ #endif
24
+
25
+ #if defined(__arm__) || defined(_M_ARM)
26
+ #define CPUINFO_ARCH_ARM 1
27
+ #endif
28
+
29
+ #if defined(__aarch64__) || defined(_M_ARM64)
30
+ #define CPUINFO_ARCH_ARM64 1
31
+ #endif
32
+
33
+ #if defined(__PPC64__) || defined(__powerpc64__) || defined(_ARCH_PPC64)
34
+ #define CPUINFO_ARCH_PPC64 1
35
+ #endif
36
+
37
+ #if defined(__asmjs__)
38
+ #define CPUINFO_ARCH_ASMJS 1
39
+ #endif
40
+
41
+ #if defined(__wasm__)
42
+ #if defined(__wasm_simd128__)
43
+ #define CPUINFO_ARCH_WASMSIMD 1
44
+ #else
45
+ #define CPUINFO_ARCH_WASM 1
46
+ #endif
47
+ #endif
48
+
49
+ #if defined(__riscv)
50
+ #if (__riscv_xlen == 32)
51
+ #define CPUINFO_ARCH_RISCV32 1
52
+ #elif (__riscv_xlen == 64)
53
+ #define CPUINFO_ARCH_RISCV64 1
54
+ #endif
55
+ #endif
56
+
57
+ /* Define other architecture-specific macros as 0 */
58
+
59
+ #ifndef CPUINFO_ARCH_X86
60
+ #define CPUINFO_ARCH_X86 0
61
+ #endif
62
+
63
+ #ifndef CPUINFO_ARCH_X86_64
64
+ #define CPUINFO_ARCH_X86_64 0
65
+ #endif
66
+
67
+ #ifndef CPUINFO_ARCH_ARM
68
+ #define CPUINFO_ARCH_ARM 0
69
+ #endif
70
+
71
+ #ifndef CPUINFO_ARCH_ARM64
72
+ #define CPUINFO_ARCH_ARM64 0
73
+ #endif
74
+
75
+ #ifndef CPUINFO_ARCH_PPC64
76
+ #define CPUINFO_ARCH_PPC64 0
77
+ #endif
78
+
79
+ #ifndef CPUINFO_ARCH_ASMJS
80
+ #define CPUINFO_ARCH_ASMJS 0
81
+ #endif
82
+
83
+ #ifndef CPUINFO_ARCH_WASM
84
+ #define CPUINFO_ARCH_WASM 0
85
+ #endif
86
+
87
+ #ifndef CPUINFO_ARCH_WASMSIMD
88
+ #define CPUINFO_ARCH_WASMSIMD 0
89
+ #endif
90
+
91
+ #ifndef CPUINFO_ARCH_RISCV32
92
+ #define CPUINFO_ARCH_RISCV32 0
93
+ #endif
94
+
95
+ #ifndef CPUINFO_ARCH_RISCV64
96
+ #define CPUINFO_ARCH_RISCV64 0
97
+ #endif
98
+
99
+ #if CPUINFO_ARCH_X86 && defined(_MSC_VER)
100
+ #define CPUINFO_ABI __cdecl
101
+ #elif CPUINFO_ARCH_X86 && defined(__GNUC__)
102
+ #define CPUINFO_ABI __attribute__((__cdecl__))
103
+ #else
104
+ #define CPUINFO_ABI
105
+ #endif
106
+
107
+ #define CPUINFO_CACHE_UNIFIED 0x00000001
108
+ #define CPUINFO_CACHE_INCLUSIVE 0x00000002
109
+ #define CPUINFO_CACHE_COMPLEX_INDEXING 0x00000004
110
+
111
+ struct cpuinfo_cache {
112
+ /** Cache size in bytes */
113
+ uint32_t size;
114
+ /** Number of ways of associativity */
115
+ uint32_t associativity;
116
+ /** Number of sets */
117
+ uint32_t sets;
118
+ /** Number of partitions */
119
+ uint32_t partitions;
120
+ /** Line size in bytes */
121
+ uint32_t line_size;
122
+ /**
123
+ * Binary characteristics of the cache (unified cache, inclusive cache,
124
+ * cache with complex indexing).
125
+ *
126
+ * @see CPUINFO_CACHE_UNIFIED, CPUINFO_CACHE_INCLUSIVE,
127
+ * CPUINFO_CACHE_COMPLEX_INDEXING
128
+ */
129
+ uint32_t flags;
130
+ /** Index of the first logical processor that shares this cache */
131
+ uint32_t processor_start;
132
+ /** Number of logical processors that share this cache */
133
+ uint32_t processor_count;
134
+ };
135
+
136
+ struct cpuinfo_trace_cache {
137
+ uint32_t uops;
138
+ uint32_t associativity;
139
+ };
140
+
141
+ #define CPUINFO_PAGE_SIZE_4KB 0x1000
142
+ #define CPUINFO_PAGE_SIZE_1MB 0x100000
143
+ #define CPUINFO_PAGE_SIZE_2MB 0x200000
144
+ #define CPUINFO_PAGE_SIZE_4MB 0x400000
145
+ #define CPUINFO_PAGE_SIZE_16MB 0x1000000
146
+ #define CPUINFO_PAGE_SIZE_1GB 0x40000000
147
+
148
+ struct cpuinfo_tlb {
149
+ uint32_t entries;
150
+ uint32_t associativity;
151
+ uint64_t pages;
152
+ };
153
+
154
+ /** Vendor of processor core design */
155
+ enum cpuinfo_vendor {
156
+ /** Processor vendor is not known to the library, or the library failed
157
+ to get vendor information from the OS. */
158
+ cpuinfo_vendor_unknown = 0,
159
+
160
+ /* Active vendors of modern CPUs */
161
+
162
+ /**
163
+ * Intel Corporation. Vendor of x86, x86-64, IA64, and ARM processor
164
+ * microarchitectures.
165
+ *
166
+ * Sold its ARM design subsidiary in 2006. The last ARM processor design
167
+ * was released in 2004.
168
+ */
169
+ cpuinfo_vendor_intel = 1,
170
+ /** Advanced Micro Devices, Inc. Vendor of x86 and x86-64 processor
171
+ microarchitectures. */
172
+ cpuinfo_vendor_amd = 2,
173
+ /** ARM Holdings plc. Vendor of ARM and ARM64 processor
174
+ microarchitectures. */
175
+ cpuinfo_vendor_arm = 3,
176
+ /** Qualcomm Incorporated. Vendor of ARM and ARM64 processor
177
+ microarchitectures. */
178
+ cpuinfo_vendor_qualcomm = 4,
179
+ /** Apple Inc. Vendor of ARM and ARM64 processor microarchitectures. */
180
+ cpuinfo_vendor_apple = 5,
181
+ /** Samsung Electronics Co., Ltd. Vendir if ARM64 processor
182
+ microarchitectures. */
183
+ cpuinfo_vendor_samsung = 6,
184
+ /** Nvidia Corporation. Vendor of ARM64-compatible processor
185
+ microarchitectures. */
186
+ cpuinfo_vendor_nvidia = 7,
187
+ /** MIPS Technologies, Inc. Vendor of MIPS processor microarchitectures.
188
+ */
189
+ cpuinfo_vendor_mips = 8,
190
+ /** International Business Machines Corporation. Vendor of PowerPC
191
+ processor microarchitectures. */
192
+ cpuinfo_vendor_ibm = 9,
193
+ /** Ingenic Semiconductor. Vendor of MIPS processor microarchitectures.
194
+ */
195
+ cpuinfo_vendor_ingenic = 10,
196
+ /**
197
+ * VIA Technologies, Inc. Vendor of x86 and x86-64 processor
198
+ * microarchitectures.
199
+ *
200
+ * Processors are designed by Centaur Technology, a subsidiary of VIA
201
+ * Technologies.
202
+ */
203
+ cpuinfo_vendor_via = 11,
204
+ /** Cavium, Inc. Vendor of ARM64 processor microarchitectures. */
205
+ cpuinfo_vendor_cavium = 12,
206
+ /** Broadcom, Inc. Vendor of ARM processor microarchitectures. */
207
+ cpuinfo_vendor_broadcom = 13,
208
+ /** Applied Micro Circuits Corporation (APM). Vendor of ARM64 processor
209
+ microarchitectures. */
210
+ cpuinfo_vendor_apm = 14,
211
+ /**
212
+ * Huawei Technologies Co., Ltd. Vendor of ARM64 processor
213
+ * microarchitectures.
214
+ *
215
+ * Processors are designed by HiSilicon, a subsidiary of Huawei.
216
+ */
217
+ cpuinfo_vendor_huawei = 15,
218
+ /**
219
+ * Hygon (Chengdu Haiguang Integrated Circuit Design Co., Ltd), Vendor
220
+ * of x86-64 processor microarchitectures.
221
+ *
222
+ * Processors are variants of AMD cores.
223
+ */
224
+ cpuinfo_vendor_hygon = 16,
225
+ /** SiFive, Inc. Vendor of RISC-V processor microarchitectures. */
226
+ cpuinfo_vendor_sifive = 17,
227
+
228
+ /* Active vendors of embedded CPUs */
229
+
230
+ /** Texas Instruments Inc. Vendor of ARM processor microarchitectures.
231
+ */
232
+ cpuinfo_vendor_texas_instruments = 30,
233
+ /** Marvell Technology Group Ltd. Vendor of ARM processor
234
+ * microarchitectures.
235
+ */
236
+ cpuinfo_vendor_marvell = 31,
237
+ /** RDC Semiconductor Co., Ltd. Vendor of x86 processor
238
+ microarchitectures. */
239
+ cpuinfo_vendor_rdc = 32,
240
+ /** DM&P Electronics Inc. Vendor of x86 processor microarchitectures. */
241
+ cpuinfo_vendor_dmp = 33,
242
+ /** Motorola, Inc. Vendor of PowerPC and ARM processor
243
+ microarchitectures. */
244
+ cpuinfo_vendor_motorola = 34,
245
+
246
+ /* Defunct CPU vendors */
247
+
248
+ /**
249
+ * Transmeta Corporation. Vendor of x86 processor microarchitectures.
250
+ *
251
+ * Now defunct. The last processor design was released in 2004.
252
+ * Transmeta processors implemented VLIW ISA and used binary translation
253
+ * to execute x86 code.
254
+ */
255
+ cpuinfo_vendor_transmeta = 50,
256
+ /**
257
+ * Cyrix Corporation. Vendor of x86 processor microarchitectures.
258
+ *
259
+ * Now defunct. The last processor design was released in 1996.
260
+ */
261
+ cpuinfo_vendor_cyrix = 51,
262
+ /**
263
+ * Rise Technology. Vendor of x86 processor microarchitectures.
264
+ *
265
+ * Now defunct. The last processor design was released in 1999.
266
+ */
267
+ cpuinfo_vendor_rise = 52,
268
+ /**
269
+ * National Semiconductor. Vendor of x86 processor microarchitectures.
270
+ *
271
+ * Sold its x86 design subsidiary in 1999. The last processor design was
272
+ * released in 1998.
273
+ */
274
+ cpuinfo_vendor_nsc = 53,
275
+ /**
276
+ * Silicon Integrated Systems. Vendor of x86 processor
277
+ * microarchitectures.
278
+ *
279
+ * Sold its x86 design subsidiary in 2001. The last processor design was
280
+ * released in 2001.
281
+ */
282
+ cpuinfo_vendor_sis = 54,
283
+ /**
284
+ * NexGen. Vendor of x86 processor microarchitectures.
285
+ *
286
+ * Now defunct. The last processor design was released in 1994.
287
+ * NexGen designed the first x86 microarchitecture which decomposed x86
288
+ * instructions into simple microoperations.
289
+ */
290
+ cpuinfo_vendor_nexgen = 55,
291
+ /**
292
+ * United Microelectronics Corporation. Vendor of x86 processor
293
+ * microarchitectures.
294
+ *
295
+ * Ceased x86 in the early 1990s. The last processor design was released
296
+ * in 1991. Designed U5C and U5D processors. Both are 486 level.
297
+ */
298
+ cpuinfo_vendor_umc = 56,
299
+ /**
300
+ * Digital Equipment Corporation. Vendor of ARM processor
301
+ * microarchitecture.
302
+ *
303
+ * Sold its ARM designs in 1997. The last processor design was released
304
+ * in 1997.
305
+ */
306
+ cpuinfo_vendor_dec = 57,
307
+ };
308
+
309
+ /**
310
+ * Processor microarchitecture
311
+ *
312
+ * Processors with different microarchitectures often have different instruction
313
+ * performance characteristics, and may have dramatically different pipeline
314
+ * organization.
315
+ */
316
+ enum cpuinfo_uarch {
317
+ /** Microarchitecture is unknown, or the library failed to get
318
+ information about the microarchitecture from OS */
319
+ cpuinfo_uarch_unknown = 0,
320
+
321
+ /** Pentium and Pentium MMX microarchitecture. */
322
+ cpuinfo_uarch_p5 = 0x00100100,
323
+ /** Intel Quark microarchitecture. */
324
+ cpuinfo_uarch_quark = 0x00100101,
325
+
326
+ /** Pentium Pro, Pentium II, and Pentium III. */
327
+ cpuinfo_uarch_p6 = 0x00100200,
328
+ /** Pentium M. */
329
+ cpuinfo_uarch_dothan = 0x00100201,
330
+ /** Intel Core microarchitecture. */
331
+ cpuinfo_uarch_yonah = 0x00100202,
332
+ /** Intel Core 2 microarchitecture on 65 nm process. */
333
+ cpuinfo_uarch_conroe = 0x00100203,
334
+ /** Intel Core 2 microarchitecture on 45 nm process. */
335
+ cpuinfo_uarch_penryn = 0x00100204,
336
+ /** Intel Nehalem and Westmere microarchitectures (Core i3/i5/i7 1st
337
+ gen). */
338
+ cpuinfo_uarch_nehalem = 0x00100205,
339
+ /** Intel Sandy Bridge microarchitecture (Core i3/i5/i7 2nd gen). */
340
+ cpuinfo_uarch_sandy_bridge = 0x00100206,
341
+ /** Intel Ivy Bridge microarchitecture (Core i3/i5/i7 3rd gen). */
342
+ cpuinfo_uarch_ivy_bridge = 0x00100207,
343
+ /** Intel Haswell microarchitecture (Core i3/i5/i7 4th gen). */
344
+ cpuinfo_uarch_haswell = 0x00100208,
345
+ /** Intel Broadwell microarchitecture. */
346
+ cpuinfo_uarch_broadwell = 0x00100209,
347
+ /** Intel Sky Lake microarchitecture (14 nm, including
348
+ Kaby/Coffee/Whiskey/Amber/Comet/Cascade/Cooper Lake). */
349
+ cpuinfo_uarch_sky_lake = 0x0010020A,
350
+ /** DEPRECATED (Intel Kaby Lake microarchitecture). */
351
+ cpuinfo_uarch_kaby_lake = 0x0010020A,
352
+ /** Intel Palm Cove microarchitecture (10 nm, Cannon Lake). */
353
+ cpuinfo_uarch_palm_cove = 0x0010020B,
354
+ /** Intel Sunny Cove microarchitecture (10 nm, Ice Lake). */
355
+ cpuinfo_uarch_sunny_cove = 0x0010020C,
356
+
357
+ /** Pentium 4 with Willamette, Northwood, or Foster cores. */
358
+ cpuinfo_uarch_willamette = 0x00100300,
359
+ /** Pentium 4 with Prescott and later cores. */
360
+ cpuinfo_uarch_prescott = 0x00100301,
361
+
362
+ /** Intel Atom on 45 nm process. */
363
+ cpuinfo_uarch_bonnell = 0x00100400,
364
+ /** Intel Atom on 32 nm process. */
365
+ cpuinfo_uarch_saltwell = 0x00100401,
366
+ /** Intel Silvermont microarchitecture (22 nm out-of-order Atom). */
367
+ cpuinfo_uarch_silvermont = 0x00100402,
368
+ /** Intel Airmont microarchitecture (14 nm out-of-order Atom). */
369
+ cpuinfo_uarch_airmont = 0x00100403,
370
+ /** Intel Goldmont microarchitecture (Denverton, Apollo Lake). */
371
+ cpuinfo_uarch_goldmont = 0x00100404,
372
+ /** Intel Goldmont Plus microarchitecture (Gemini Lake). */
373
+ cpuinfo_uarch_goldmont_plus = 0x00100405,
374
+
375
+ /** Intel Knights Ferry HPC boards. */
376
+ cpuinfo_uarch_knights_ferry = 0x00100500,
377
+ /** Intel Knights Corner HPC boards (aka Xeon Phi). */
378
+ cpuinfo_uarch_knights_corner = 0x00100501,
379
+ /** Intel Knights Landing microarchitecture (second-gen MIC). */
380
+ cpuinfo_uarch_knights_landing = 0x00100502,
381
+ /** Intel Knights Hill microarchitecture (third-gen MIC). */
382
+ cpuinfo_uarch_knights_hill = 0x00100503,
383
+ /** Intel Knights Mill Xeon Phi. */
384
+ cpuinfo_uarch_knights_mill = 0x00100504,
385
+
386
+ /** Intel/Marvell XScale series. */
387
+ cpuinfo_uarch_xscale = 0x00100600,
388
+
389
+ /** AMD K5. */
390
+ cpuinfo_uarch_k5 = 0x00200100,
391
+ /** AMD K6 and alike. */
392
+ cpuinfo_uarch_k6 = 0x00200101,
393
+ /** AMD Athlon and Duron. */
394
+ cpuinfo_uarch_k7 = 0x00200102,
395
+ /** AMD Athlon 64, Opteron 64. */
396
+ cpuinfo_uarch_k8 = 0x00200103,
397
+ /** AMD Family 10h (Barcelona, Istambul, Magny-Cours). */
398
+ cpuinfo_uarch_k10 = 0x00200104,
399
+ /**
400
+ * AMD Bulldozer microarchitecture
401
+ * Zambezi FX-series CPUs, Zurich, Valencia and Interlagos Opteron CPUs.
402
+ */
403
+ cpuinfo_uarch_bulldozer = 0x00200105,
404
+ /**
405
+ * AMD Piledriver microarchitecture
406
+ * Vishera FX-series CPUs, Trinity and Richland APUs, Delhi, Seoul, Abu
407
+ * Dhabi Opteron CPUs.
408
+ */
409
+ cpuinfo_uarch_piledriver = 0x00200106,
410
+ /** AMD Steamroller microarchitecture (Kaveri APUs). */
411
+ cpuinfo_uarch_steamroller = 0x00200107,
412
+ /** AMD Excavator microarchitecture (Carizzo APUs). */
413
+ cpuinfo_uarch_excavator = 0x00200108,
414
+ /** AMD Zen microarchitecture (12/14 nm Ryzen and EPYC CPUs). */
415
+ cpuinfo_uarch_zen = 0x00200109,
416
+ /** AMD Zen 2 microarchitecture (7 nm Ryzen and EPYC CPUs). */
417
+ cpuinfo_uarch_zen2 = 0x0020010A,
418
+ /** AMD Zen 3 microarchitecture. */
419
+ cpuinfo_uarch_zen3 = 0x0020010B,
420
+ /** AMD Zen 4 microarchitecture. */
421
+ cpuinfo_uarch_zen4 = 0x0020010C,
422
+ /** AMD Zen 5 microarchitecture. */
423
+ cpuinfo_uarch_zen5 = 0x0020010D,
424
+
425
+ /** NSC Geode and AMD Geode GX and LX. */
426
+ cpuinfo_uarch_geode = 0x00200200,
427
+ /** AMD Bobcat mobile microarchitecture. */
428
+ cpuinfo_uarch_bobcat = 0x00200201,
429
+ /** AMD Jaguar mobile microarchitecture. */
430
+ cpuinfo_uarch_jaguar = 0x00200202,
431
+ /** AMD Puma mobile microarchitecture. */
432
+ cpuinfo_uarch_puma = 0x00200203,
433
+
434
+ /** ARM7 series. */
435
+ cpuinfo_uarch_arm7 = 0x00300100,
436
+ /** ARM9 series. */
437
+ cpuinfo_uarch_arm9 = 0x00300101,
438
+ /** ARM 1136, ARM 1156, ARM 1176, or ARM 11MPCore. */
439
+ cpuinfo_uarch_arm11 = 0x00300102,
440
+
441
+ /** ARM Cortex-A5. */
442
+ cpuinfo_uarch_cortex_a5 = 0x00300205,
443
+ /** ARM Cortex-A7. */
444
+ cpuinfo_uarch_cortex_a7 = 0x00300207,
445
+ /** ARM Cortex-A8. */
446
+ cpuinfo_uarch_cortex_a8 = 0x00300208,
447
+ /** ARM Cortex-A9. */
448
+ cpuinfo_uarch_cortex_a9 = 0x00300209,
449
+ /** ARM Cortex-A12. */
450
+ cpuinfo_uarch_cortex_a12 = 0x00300212,
451
+ /** ARM Cortex-A15. */
452
+ cpuinfo_uarch_cortex_a15 = 0x00300215,
453
+ /** ARM Cortex-A17. */
454
+ cpuinfo_uarch_cortex_a17 = 0x00300217,
455
+
456
+ /** ARM Cortex-A32. */
457
+ cpuinfo_uarch_cortex_a32 = 0x00300332,
458
+ /** ARM Cortex-A35. */
459
+ cpuinfo_uarch_cortex_a35 = 0x00300335,
460
+ /** ARM Cortex-A53. */
461
+ cpuinfo_uarch_cortex_a53 = 0x00300353,
462
+ /** ARM Cortex-A55 revision 0 (restricted dual-issue capabilities
463
+ compared to revision 1+). */
464
+ cpuinfo_uarch_cortex_a55r0 = 0x00300354,
465
+ /** ARM Cortex-A55. */
466
+ cpuinfo_uarch_cortex_a55 = 0x00300355,
467
+ /** ARM Cortex-A57. */
468
+ cpuinfo_uarch_cortex_a57 = 0x00300357,
469
+ /** ARM Cortex-A65. */
470
+ cpuinfo_uarch_cortex_a65 = 0x00300365,
471
+ /** ARM Cortex-A72. */
472
+ cpuinfo_uarch_cortex_a72 = 0x00300372,
473
+ /** ARM Cortex-A73. */
474
+ cpuinfo_uarch_cortex_a73 = 0x00300373,
475
+ /** ARM Cortex-A75. */
476
+ cpuinfo_uarch_cortex_a75 = 0x00300375,
477
+ /** ARM Cortex-A76. */
478
+ cpuinfo_uarch_cortex_a76 = 0x00300376,
479
+ /** ARM Cortex-A77. */
480
+ cpuinfo_uarch_cortex_a77 = 0x00300377,
481
+ /** ARM Cortex-A78. */
482
+ cpuinfo_uarch_cortex_a78 = 0x00300378,
483
+
484
+ /** ARM Neoverse N1. */
485
+ cpuinfo_uarch_neoverse_n1 = 0x00300400,
486
+ /** ARM Neoverse E1. */
487
+ cpuinfo_uarch_neoverse_e1 = 0x00300401,
488
+ /** ARM Neoverse V1. */
489
+ cpuinfo_uarch_neoverse_v1 = 0x00300402,
490
+ /** ARM Neoverse N2. */
491
+ cpuinfo_uarch_neoverse_n2 = 0x00300403,
492
+ /** ARM Neoverse V2. */
493
+ cpuinfo_uarch_neoverse_v2 = 0x00300404,
494
+
495
+ /** ARM Cortex-X1. */
496
+ cpuinfo_uarch_cortex_x1 = 0x00300501,
497
+ /** ARM Cortex-X2. */
498
+ cpuinfo_uarch_cortex_x2 = 0x00300502,
499
+ /** ARM Cortex-X3. */
500
+ cpuinfo_uarch_cortex_x3 = 0x00300503,
501
+ /** ARM Cortex-X4. */
502
+ cpuinfo_uarch_cortex_x4 = 0x00300504,
503
+
504
+ /** ARM Cortex-A510. */
505
+ cpuinfo_uarch_cortex_a510 = 0x00300551,
506
+ /** ARM Cortex-A520. */
507
+ cpuinfo_uarch_cortex_a520 = 0x00300552,
508
+ /** ARM Cortex-A710. */
509
+ cpuinfo_uarch_cortex_a710 = 0x00300571,
510
+ /** ARM Cortex-A715. */
511
+ cpuinfo_uarch_cortex_a715 = 0x00300572,
512
+ /** ARM Cortex-A720. */
513
+ cpuinfo_uarch_cortex_a720 = 0x00300573,
514
+
515
+ /** Qualcomm Scorpion. */
516
+ cpuinfo_uarch_scorpion = 0x00400100,
517
+ /** Qualcomm Krait. */
518
+ cpuinfo_uarch_krait = 0x00400101,
519
+ /** Qualcomm Kryo. */
520
+ cpuinfo_uarch_kryo = 0x00400102,
521
+ /** Qualcomm Falkor. */
522
+ cpuinfo_uarch_falkor = 0x00400103,
523
+ /** Qualcomm Saphira. */
524
+ cpuinfo_uarch_saphira = 0x00400104,
525
+ /** Qualcomm Oryon. */
526
+ cpuinfo_uarch_oryon = 0x00400105,
527
+
528
+ /** Nvidia Denver. */
529
+ cpuinfo_uarch_denver = 0x00500100,
530
+ /** Nvidia Denver 2. */
531
+ cpuinfo_uarch_denver2 = 0x00500101,
532
+ /** Nvidia Carmel. */
533
+ cpuinfo_uarch_carmel = 0x00500102,
534
+
535
+ /** Samsung Exynos M1 (Exynos 8890 big cores). */
536
+ cpuinfo_uarch_exynos_m1 = 0x00600100,
537
+ /** Samsung Exynos M2 (Exynos 8895 big cores). */
538
+ cpuinfo_uarch_exynos_m2 = 0x00600101,
539
+ /** Samsung Exynos M3 (Exynos 9810 big cores). */
540
+ cpuinfo_uarch_exynos_m3 = 0x00600102,
541
+ /** Samsung Exynos M4 (Exynos 9820 big cores). */
542
+ cpuinfo_uarch_exynos_m4 = 0x00600103,
543
+ /** Samsung Exynos M5 (Exynos 9830 big cores). */
544
+ cpuinfo_uarch_exynos_m5 = 0x00600104,
545
+
546
+ /* Deprecated synonym for Cortex-A76 */
547
+ cpuinfo_uarch_cortex_a76ae = 0x00300376,
548
+ /* Deprecated names for Exynos. */
549
+ cpuinfo_uarch_mongoose_m1 = 0x00600100,
550
+ cpuinfo_uarch_mongoose_m2 = 0x00600101,
551
+ cpuinfo_uarch_meerkat_m3 = 0x00600102,
552
+ cpuinfo_uarch_meerkat_m4 = 0x00600103,
553
+
554
+ /** Apple A6 and A6X processors. */
555
+ cpuinfo_uarch_swift = 0x00700100,
556
+ /** Apple A7 processor. */
557
+ cpuinfo_uarch_cyclone = 0x00700101,
558
+ /** Apple A8 and A8X processor. */
559
+ cpuinfo_uarch_typhoon = 0x00700102,
560
+ /** Apple A9 and A9X processor. */
561
+ cpuinfo_uarch_twister = 0x00700103,
562
+ /** Apple A10 and A10X processor. */
563
+ cpuinfo_uarch_hurricane = 0x00700104,
564
+ /** Apple A11 processor (big cores). */
565
+ cpuinfo_uarch_monsoon = 0x00700105,
566
+ /** Apple A11 processor (little cores). */
567
+ cpuinfo_uarch_mistral = 0x00700106,
568
+ /** Apple A12 processor (big cores). */
569
+ cpuinfo_uarch_vortex = 0x00700107,
570
+ /** Apple A12 processor (little cores). */
571
+ cpuinfo_uarch_tempest = 0x00700108,
572
+ /** Apple A13 processor (big cores). */
573
+ cpuinfo_uarch_lightning = 0x00700109,
574
+ /** Apple A13 processor (little cores). */
575
+ cpuinfo_uarch_thunder = 0x0070010A,
576
+ /** Apple A14 / M1 processor (big cores). */
577
+ cpuinfo_uarch_firestorm = 0x0070010B,
578
+ /** Apple A14 / M1 processor (little cores). */
579
+ cpuinfo_uarch_icestorm = 0x0070010C,
580
+ /** Apple A15 / M2 processor (big cores). */
581
+ cpuinfo_uarch_avalanche = 0x0070010D,
582
+ /** Apple A15 / M2 processor (little cores). */
583
+ cpuinfo_uarch_blizzard = 0x0070010E,
584
+
585
+ /** Cavium ThunderX. */
586
+ cpuinfo_uarch_thunderx = 0x00800100,
587
+ /** Cavium ThunderX2 (originally Broadcom Vulkan). */
588
+ cpuinfo_uarch_thunderx2 = 0x00800200,
589
+
590
+ /** Marvell PJ4. */
591
+ cpuinfo_uarch_pj4 = 0x00900100,
592
+
593
+ /** Broadcom Brahma B15. */
594
+ cpuinfo_uarch_brahma_b15 = 0x00A00100,
595
+ /** Broadcom Brahma B53. */
596
+ cpuinfo_uarch_brahma_b53 = 0x00A00101,
597
+
598
+ /** Applied Micro X-Gene. */
599
+ cpuinfo_uarch_xgene = 0x00B00100,
600
+
601
+ /* Hygon Dhyana (a modification of AMD Zen for Chinese market). */
602
+ cpuinfo_uarch_dhyana = 0x01000100,
603
+
604
+ /** HiSilicon TaiShan v110 (Huawei Kunpeng 920 series processors). */
605
+ cpuinfo_uarch_taishan_v110 = 0x00C00100,
606
+ };
607
+
608
+ struct cpuinfo_processor {
609
+ /** SMT (hyperthread) ID within a core */
610
+ uint32_t smt_id;
611
+ /** Core containing this logical processor */
612
+ const struct cpuinfo_core* core;
613
+ /** Cluster of cores containing this logical processor */
614
+ const struct cpuinfo_cluster* cluster;
615
+ /** Physical package containing this logical processor */
616
+ const struct cpuinfo_package* package;
617
+ #if defined(__linux__)
618
+ /**
619
+ * Linux-specific ID for the logical processor:
620
+ * - Linux kernel exposes information about this logical processor in
621
+ * /sys/devices/system/cpu/cpu<linux_id>/
622
+ * - Bit <linux_id> in the cpu_set_t identifies this logical processor
623
+ */
624
+ int linux_id;
625
+ #endif
626
+ #if defined(_WIN32) || defined(__CYGWIN__)
627
+ /** Windows-specific ID for the group containing the logical processor.
628
+ */
629
+ uint16_t windows_group_id;
630
+ /**
631
+ * Windows-specific ID of the logical processor within its group:
632
+ * - Bit <windows_processor_id> in the KAFFINITY mask identifies this
633
+ * logical processor within its group.
634
+ */
635
+ uint16_t windows_processor_id;
636
+ #endif
637
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
638
+ /** APIC ID (unique x86-specific ID of the logical processor) */
639
+ uint32_t apic_id;
640
+ #endif
641
+ struct {
642
+ /** Level 1 instruction cache */
643
+ const struct cpuinfo_cache* l1i;
644
+ /** Level 1 data cache */
645
+ const struct cpuinfo_cache* l1d;
646
+ /** Level 2 unified or data cache */
647
+ const struct cpuinfo_cache* l2;
648
+ /** Level 3 unified or data cache */
649
+ const struct cpuinfo_cache* l3;
650
+ /** Level 4 unified or data cache */
651
+ const struct cpuinfo_cache* l4;
652
+ } cache;
653
+ };
654
+
655
+ struct cpuinfo_core {
656
+ /** Index of the first logical processor on this core. */
657
+ uint32_t processor_start;
658
+ /** Number of logical processors on this core */
659
+ uint32_t processor_count;
660
+ /** Core ID within a package */
661
+ uint32_t core_id;
662
+ /** Cluster containing this core */
663
+ const struct cpuinfo_cluster* cluster;
664
+ /** Physical package containing this core. */
665
+ const struct cpuinfo_package* package;
666
+ /** Vendor of the CPU microarchitecture for this core */
667
+ enum cpuinfo_vendor vendor;
668
+ /** CPU microarchitecture for this core */
669
+ enum cpuinfo_uarch uarch;
670
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
671
+ /** Value of CPUID leaf 1 EAX register for this core */
672
+ uint32_t cpuid;
673
+ #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
674
+ /** Value of Main ID Register (MIDR) for this core */
675
+ uint32_t midr;
676
+ #endif
677
+ /** Clock rate (non-Turbo) of the core, in Hz */
678
+ uint64_t frequency;
679
+ };
680
+
681
+ struct cpuinfo_cluster {
682
+ /** Index of the first logical processor in the cluster */
683
+ uint32_t processor_start;
684
+ /** Number of logical processors in the cluster */
685
+ uint32_t processor_count;
686
+ /** Index of the first core in the cluster */
687
+ uint32_t core_start;
688
+ /** Number of cores on the cluster */
689
+ uint32_t core_count;
690
+ /** Cluster ID within a package */
691
+ uint32_t cluster_id;
692
+ /** Physical package containing the cluster */
693
+ const struct cpuinfo_package* package;
694
+ /** CPU microarchitecture vendor of the cores in the cluster */
695
+ enum cpuinfo_vendor vendor;
696
+ /** CPU microarchitecture of the cores in the cluster */
697
+ enum cpuinfo_uarch uarch;
698
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
699
+ /** Value of CPUID leaf 1 EAX register of the cores in the cluster */
700
+ uint32_t cpuid;
701
+ #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
702
+ /** Value of Main ID Register (MIDR) of the cores in the cluster */
703
+ uint32_t midr;
704
+ #endif
705
+ /** Clock rate (non-Turbo) of the cores in the cluster, in Hz */
706
+ uint64_t frequency;
707
+ };
708
+
709
+ #define CPUINFO_PACKAGE_NAME_MAX 48
710
+
711
+ struct cpuinfo_package {
712
+ /** SoC or processor chip model name */
713
+ char name[CPUINFO_PACKAGE_NAME_MAX];
714
+ /** Index of the first logical processor on this physical package */
715
+ uint32_t processor_start;
716
+ /** Number of logical processors on this physical package */
717
+ uint32_t processor_count;
718
+ /** Index of the first core on this physical package */
719
+ uint32_t core_start;
720
+ /** Number of cores on this physical package */
721
+ uint32_t core_count;
722
+ /** Index of the first cluster of cores on this physical package */
723
+ uint32_t cluster_start;
724
+ /** Number of clusters of cores on this physical package */
725
+ uint32_t cluster_count;
726
+ };
727
+
728
+ struct cpuinfo_uarch_info {
729
+ /** Type of CPU microarchitecture */
730
+ enum cpuinfo_uarch uarch;
731
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
732
+ /** Value of CPUID leaf 1 EAX register for the microarchitecture */
733
+ uint32_t cpuid;
734
+ #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
735
+ /** Value of Main ID Register (MIDR) for the microarchitecture */
736
+ uint32_t midr;
737
+ #endif
738
+ /** Number of logical processors with the microarchitecture */
739
+ uint32_t processor_count;
740
+ /** Number of cores with the microarchitecture */
741
+ uint32_t core_count;
742
+ };
743
+
744
+ #ifdef __cplusplus
745
+ extern "C" {
746
+ #endif
747
+
748
+ bool CPUINFO_ABI cpuinfo_initialize(void);
749
+
750
+ void CPUINFO_ABI cpuinfo_deinitialize(void);
751
+
752
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
753
+ /* This structure is not a part of stable API. Use cpuinfo_has_x86_* functions
754
+ * instead. */
755
+ struct cpuinfo_x86_isa {
756
+ #if CPUINFO_ARCH_X86
757
+ bool rdtsc;
758
+ #endif
759
+ bool rdtscp;
760
+ bool rdpid;
761
+ bool sysenter;
762
+ #if CPUINFO_ARCH_X86
763
+ bool syscall;
764
+ #endif
765
+ bool msr;
766
+ bool clzero;
767
+ bool clflush;
768
+ bool clflushopt;
769
+ bool mwait;
770
+ bool mwaitx;
771
+ #if CPUINFO_ARCH_X86
772
+ bool emmx;
773
+ #endif
774
+ bool fxsave;
775
+ bool xsave;
776
+ #if CPUINFO_ARCH_X86
777
+ bool fpu;
778
+ bool mmx;
779
+ bool mmx_plus;
780
+ #endif
781
+ bool three_d_now;
782
+ bool three_d_now_plus;
783
+ #if CPUINFO_ARCH_X86
784
+ bool three_d_now_geode;
785
+ #endif
786
+ bool prefetch;
787
+ bool prefetchw;
788
+ bool prefetchwt1;
789
+ #if CPUINFO_ARCH_X86
790
+ bool daz;
791
+ bool sse;
792
+ bool sse2;
793
+ #endif
794
+ bool sse3;
795
+ bool ssse3;
796
+ bool sse4_1;
797
+ bool sse4_2;
798
+ bool sse4a;
799
+ bool misaligned_sse;
800
+ bool avx;
801
+ bool avxvnni;
802
+ bool fma3;
803
+ bool fma4;
804
+ bool xop;
805
+ bool f16c;
806
+ bool avx2;
807
+ bool avx512f;
808
+ bool avx512pf;
809
+ bool avx512er;
810
+ bool avx512cd;
811
+ bool avx512dq;
812
+ bool avx512bw;
813
+ bool avx512vl;
814
+ bool avx512ifma;
815
+ bool avx512vbmi;
816
+ bool avx512vbmi2;
817
+ bool avx512bitalg;
818
+ bool avx512vpopcntdq;
819
+ bool avx512vnni;
820
+ bool avx512bf16;
821
+ bool avx512fp16;
822
+ bool avx512vp2intersect;
823
+ bool avx512_4vnniw;
824
+ bool avx512_4fmaps;
825
+ bool avx10_1;
826
+ bool avx10_2;
827
+ bool amx_bf16;
828
+ bool amx_tile;
829
+ bool amx_int8;
830
+ bool amx_fp16;
831
+ bool avx_vnni_int8;
832
+ bool avx_vnni_int16;
833
+ bool avx_ne_convert;
834
+ bool hle;
835
+ bool rtm;
836
+ bool xtest;
837
+ bool mpx;
838
+ #if CPUINFO_ARCH_X86
839
+ bool cmov;
840
+ bool cmpxchg8b;
841
+ #endif
842
+ bool cmpxchg16b;
843
+ bool clwb;
844
+ bool movbe;
845
+ #if CPUINFO_ARCH_X86_64
846
+ bool lahf_sahf;
847
+ #endif
848
+ bool fs_gs_base;
849
+ bool lzcnt;
850
+ bool popcnt;
851
+ bool tbm;
852
+ bool bmi;
853
+ bool bmi2;
854
+ bool adx;
855
+ bool aes;
856
+ bool vaes;
857
+ bool pclmulqdq;
858
+ bool vpclmulqdq;
859
+ bool gfni;
860
+ bool rdrand;
861
+ bool rdseed;
862
+ bool sha;
863
+ bool rng;
864
+ bool ace;
865
+ bool ace2;
866
+ bool phe;
867
+ bool pmm;
868
+ bool lwp;
869
+ };
870
+
871
+ extern struct cpuinfo_x86_isa cpuinfo_isa;
872
+ #endif
873
+
874
+ static inline bool cpuinfo_has_x86_rdtsc(void) {
875
+ #if CPUINFO_ARCH_X86_64
876
+ return true;
877
+ #elif CPUINFO_ARCH_X86
878
+ #if defined(__ANDROID__)
879
+ return true;
880
+ #else
881
+ return cpuinfo_isa.rdtsc;
882
+ #endif
883
+ #else
884
+ return false;
885
+ #endif
886
+ }
887
+
888
+ static inline bool cpuinfo_has_x86_rdtscp(void) {
889
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
890
+ return cpuinfo_isa.rdtscp;
891
+ #else
892
+ return false;
893
+ #endif
894
+ }
895
+
896
+ static inline bool cpuinfo_has_x86_rdpid(void) {
897
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
898
+ return cpuinfo_isa.rdpid;
899
+ #else
900
+ return false;
901
+ #endif
902
+ }
903
+
904
+ static inline bool cpuinfo_has_x86_clzero(void) {
905
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
906
+ return cpuinfo_isa.clzero;
907
+ #else
908
+ return false;
909
+ #endif
910
+ }
911
+
912
+ static inline bool cpuinfo_has_x86_mwait(void) {
913
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
914
+ return cpuinfo_isa.mwait;
915
+ #else
916
+ return false;
917
+ #endif
918
+ }
919
+
920
+ static inline bool cpuinfo_has_x86_mwaitx(void) {
921
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
922
+ return cpuinfo_isa.mwaitx;
923
+ #else
924
+ return false;
925
+ #endif
926
+ }
927
+
928
+ static inline bool cpuinfo_has_x86_fxsave(void) {
929
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
930
+ return cpuinfo_isa.fxsave;
931
+ #else
932
+ return false;
933
+ #endif
934
+ }
935
+
936
+ static inline bool cpuinfo_has_x86_xsave(void) {
937
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
938
+ return cpuinfo_isa.xsave;
939
+ #else
940
+ return false;
941
+ #endif
942
+ }
943
+
944
+ static inline bool cpuinfo_has_x86_fpu(void) {
945
+ #if CPUINFO_ARCH_X86_64
946
+ return true;
947
+ #elif CPUINFO_ARCH_X86
948
+ #if defined(__ANDROID__)
949
+ return true;
950
+ #else
951
+ return cpuinfo_isa.fpu;
952
+ #endif
953
+ #else
954
+ return false;
955
+ #endif
956
+ }
957
+
958
+ static inline bool cpuinfo_has_x86_mmx(void) {
959
+ #if CPUINFO_ARCH_X86_64
960
+ return true;
961
+ #elif CPUINFO_ARCH_X86
962
+ #if defined(__ANDROID__)
963
+ return true;
964
+ #else
965
+ return cpuinfo_isa.mmx;
966
+ #endif
967
+ #else
968
+ return false;
969
+ #endif
970
+ }
971
+
972
+ static inline bool cpuinfo_has_x86_mmx_plus(void) {
973
+ #if CPUINFO_ARCH_X86_64
974
+ return true;
975
+ #elif CPUINFO_ARCH_X86
976
+ #if defined(__ANDROID__)
977
+ return true;
978
+ #else
979
+ return cpuinfo_isa.mmx_plus;
980
+ #endif
981
+ #else
982
+ return false;
983
+ #endif
984
+ }
985
+
986
+ static inline bool cpuinfo_has_x86_3dnow(void) {
987
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
988
+ return cpuinfo_isa.three_d_now;
989
+ #else
990
+ return false;
991
+ #endif
992
+ }
993
+
994
+ static inline bool cpuinfo_has_x86_3dnow_plus(void) {
995
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
996
+ return cpuinfo_isa.three_d_now_plus;
997
+ #else
998
+ return false;
999
+ #endif
1000
+ }
1001
+
1002
+ static inline bool cpuinfo_has_x86_3dnow_geode(void) {
1003
+ #if CPUINFO_ARCH_X86_64
1004
+ return false;
1005
+ #elif CPUINFO_ARCH_X86
1006
+ #if defined(__ANDROID__)
1007
+ return false;
1008
+ #else
1009
+ return cpuinfo_isa.three_d_now_geode;
1010
+ #endif
1011
+ #else
1012
+ return false;
1013
+ #endif
1014
+ }
1015
+
1016
+ static inline bool cpuinfo_has_x86_prefetch(void) {
1017
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1018
+ return cpuinfo_isa.prefetch;
1019
+ #else
1020
+ return false;
1021
+ #endif
1022
+ }
1023
+
1024
+ static inline bool cpuinfo_has_x86_prefetchw(void) {
1025
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1026
+ return cpuinfo_isa.prefetchw;
1027
+ #else
1028
+ return false;
1029
+ #endif
1030
+ }
1031
+
1032
+ static inline bool cpuinfo_has_x86_prefetchwt1(void) {
1033
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1034
+ return cpuinfo_isa.prefetchwt1;
1035
+ #else
1036
+ return false;
1037
+ #endif
1038
+ }
1039
+
1040
+ static inline bool cpuinfo_has_x86_daz(void) {
1041
+ #if CPUINFO_ARCH_X86_64
1042
+ return true;
1043
+ #elif CPUINFO_ARCH_X86
1044
+ #if defined(__ANDROID__)
1045
+ return true;
1046
+ #else
1047
+ return cpuinfo_isa.daz;
1048
+ #endif
1049
+ #else
1050
+ return false;
1051
+ #endif
1052
+ }
1053
+
1054
+ static inline bool cpuinfo_has_x86_sse(void) {
1055
+ #if CPUINFO_ARCH_X86_64
1056
+ return true;
1057
+ #elif CPUINFO_ARCH_X86
1058
+ #if defined(__ANDROID__)
1059
+ return true;
1060
+ #else
1061
+ return cpuinfo_isa.sse;
1062
+ #endif
1063
+ #else
1064
+ return false;
1065
+ #endif
1066
+ }
1067
+
1068
+ static inline bool cpuinfo_has_x86_sse2(void) {
1069
+ #if CPUINFO_ARCH_X86_64
1070
+ return true;
1071
+ #elif CPUINFO_ARCH_X86
1072
+ #if defined(__ANDROID__)
1073
+ return true;
1074
+ #else
1075
+ return cpuinfo_isa.sse2;
1076
+ #endif
1077
+ #else
1078
+ return false;
1079
+ #endif
1080
+ }
1081
+
1082
+ static inline bool cpuinfo_has_x86_sse3(void) {
1083
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1084
+ #if defined(__ANDROID__)
1085
+ return true;
1086
+ #else
1087
+ return cpuinfo_isa.sse3;
1088
+ #endif
1089
+ #else
1090
+ return false;
1091
+ #endif
1092
+ }
1093
+
1094
+ static inline bool cpuinfo_has_x86_ssse3(void) {
1095
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1096
+ #if defined(__ANDROID__)
1097
+ return true;
1098
+ #else
1099
+ return cpuinfo_isa.ssse3;
1100
+ #endif
1101
+ #else
1102
+ return false;
1103
+ #endif
1104
+ }
1105
+
1106
+ static inline bool cpuinfo_has_x86_sse4_1(void) {
1107
+ #if CPUINFO_ARCH_X86_64
1108
+ #if defined(__ANDROID__)
1109
+ return true;
1110
+ #else
1111
+ return cpuinfo_isa.sse4_1;
1112
+ #endif
1113
+ #elif CPUINFO_ARCH_X86
1114
+ return cpuinfo_isa.sse4_1;
1115
+ #else
1116
+ return false;
1117
+ #endif
1118
+ }
1119
+
1120
+ static inline bool cpuinfo_has_x86_sse4_2(void) {
1121
+ #if CPUINFO_ARCH_X86_64
1122
+ #if defined(__ANDROID__)
1123
+ return true;
1124
+ #else
1125
+ return cpuinfo_isa.sse4_2;
1126
+ #endif
1127
+ #elif CPUINFO_ARCH_X86
1128
+ return cpuinfo_isa.sse4_2;
1129
+ #else
1130
+ return false;
1131
+ #endif
1132
+ }
1133
+
1134
+ static inline bool cpuinfo_has_x86_sse4a(void) {
1135
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1136
+ return cpuinfo_isa.sse4a;
1137
+ #else
1138
+ return false;
1139
+ #endif
1140
+ }
1141
+
1142
+ static inline bool cpuinfo_has_x86_misaligned_sse(void) {
1143
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1144
+ return cpuinfo_isa.misaligned_sse;
1145
+ #else
1146
+ return false;
1147
+ #endif
1148
+ }
1149
+
1150
+ static inline bool cpuinfo_has_x86_avx(void) {
1151
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1152
+ return cpuinfo_isa.avx;
1153
+ #else
1154
+ return false;
1155
+ #endif
1156
+ }
1157
+
1158
+ static inline bool cpuinfo_has_x86_avxvnni(void) {
1159
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1160
+ return cpuinfo_isa.avxvnni;
1161
+ #else
1162
+ return false;
1163
+ #endif
1164
+ }
1165
+
1166
+ static inline bool cpuinfo_has_x86_fma3(void) {
1167
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1168
+ return cpuinfo_isa.fma3;
1169
+ #else
1170
+ return false;
1171
+ #endif
1172
+ }
1173
+
1174
+ static inline bool cpuinfo_has_x86_fma4(void) {
1175
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1176
+ return cpuinfo_isa.fma4;
1177
+ #else
1178
+ return false;
1179
+ #endif
1180
+ }
1181
+
1182
+ static inline bool cpuinfo_has_x86_xop(void) {
1183
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1184
+ return cpuinfo_isa.xop;
1185
+ #else
1186
+ return false;
1187
+ #endif
1188
+ }
1189
+
1190
+ static inline bool cpuinfo_has_x86_f16c(void) {
1191
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1192
+ return cpuinfo_isa.f16c;
1193
+ #else
1194
+ return false;
1195
+ #endif
1196
+ }
1197
+
1198
+ static inline bool cpuinfo_has_x86_avx2(void) {
1199
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1200
+ return cpuinfo_isa.avx2;
1201
+ #else
1202
+ return false;
1203
+ #endif
1204
+ }
1205
+
1206
+ static inline bool cpuinfo_has_x86_avx512f(void) {
1207
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1208
+ return cpuinfo_isa.avx512f;
1209
+ #else
1210
+ return false;
1211
+ #endif
1212
+ }
1213
+
1214
+ static inline bool cpuinfo_has_x86_avx512pf(void) {
1215
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1216
+ return cpuinfo_isa.avx512pf;
1217
+ #else
1218
+ return false;
1219
+ #endif
1220
+ }
1221
+
1222
+ static inline bool cpuinfo_has_x86_avx512er(void) {
1223
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1224
+ return cpuinfo_isa.avx512er;
1225
+ #else
1226
+ return false;
1227
+ #endif
1228
+ }
1229
+
1230
+ static inline bool cpuinfo_has_x86_avx512cd(void) {
1231
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1232
+ return cpuinfo_isa.avx512cd;
1233
+ #else
1234
+ return false;
1235
+ #endif
1236
+ }
1237
+
1238
+ static inline bool cpuinfo_has_x86_avx512dq(void) {
1239
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1240
+ return cpuinfo_isa.avx512dq;
1241
+ #else
1242
+ return false;
1243
+ #endif
1244
+ }
1245
+
1246
+ static inline bool cpuinfo_has_x86_avx512bw(void) {
1247
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1248
+ return cpuinfo_isa.avx512bw;
1249
+ #else
1250
+ return false;
1251
+ #endif
1252
+ }
1253
+
1254
+ static inline bool cpuinfo_has_x86_avx512vl(void) {
1255
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1256
+ return cpuinfo_isa.avx512vl;
1257
+ #else
1258
+ return false;
1259
+ #endif
1260
+ }
1261
+
1262
+ static inline bool cpuinfo_has_x86_avx512ifma(void) {
1263
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1264
+ return cpuinfo_isa.avx512ifma;
1265
+ #else
1266
+ return false;
1267
+ #endif
1268
+ }
1269
+
1270
+ static inline bool cpuinfo_has_x86_avx512vbmi(void) {
1271
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1272
+ return cpuinfo_isa.avx512vbmi;
1273
+ #else
1274
+ return false;
1275
+ #endif
1276
+ }
1277
+
1278
+ static inline bool cpuinfo_has_x86_avx512vbmi2(void) {
1279
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1280
+ return cpuinfo_isa.avx512vbmi2;
1281
+ #else
1282
+ return false;
1283
+ #endif
1284
+ }
1285
+
1286
+ static inline bool cpuinfo_has_x86_avx512bitalg(void) {
1287
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1288
+ return cpuinfo_isa.avx512bitalg;
1289
+ #else
1290
+ return false;
1291
+ #endif
1292
+ }
1293
+
1294
+ static inline bool cpuinfo_has_x86_avx512vpopcntdq(void) {
1295
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1296
+ return cpuinfo_isa.avx512vpopcntdq;
1297
+ #else
1298
+ return false;
1299
+ #endif
1300
+ }
1301
+
1302
+ static inline bool cpuinfo_has_x86_avx512vnni(void) {
1303
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1304
+ return cpuinfo_isa.avx512vnni;
1305
+ #else
1306
+ return false;
1307
+ #endif
1308
+ }
1309
+
1310
+ static inline bool cpuinfo_has_x86_avx512bf16(void) {
1311
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1312
+ return cpuinfo_isa.avx512bf16;
1313
+ #else
1314
+ return false;
1315
+ #endif
1316
+ }
1317
+
1318
+ static inline bool cpuinfo_has_x86_avx512fp16(void) {
1319
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1320
+ return cpuinfo_isa.avx512fp16;
1321
+ #else
1322
+ return false;
1323
+ #endif
1324
+ }
1325
+
1326
+ static inline bool cpuinfo_has_x86_avx512vp2intersect(void) {
1327
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1328
+ return cpuinfo_isa.avx512vp2intersect;
1329
+ #else
1330
+ return false;
1331
+ #endif
1332
+ }
1333
+
1334
+ static inline bool cpuinfo_has_x86_avx512_4vnniw(void) {
1335
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1336
+ return cpuinfo_isa.avx512_4vnniw;
1337
+ #else
1338
+ return false;
1339
+ #endif
1340
+ }
1341
+
1342
+ static inline bool cpuinfo_has_x86_avx512_4fmaps(void) {
1343
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1344
+ return cpuinfo_isa.avx512_4fmaps;
1345
+ #else
1346
+ return false;
1347
+ #endif
1348
+ }
1349
+
1350
+ /* [NOTE] Intel Advanced Matrix Extensions (AMX) detection
1351
+ *
1352
+ * I. AMX is a new extensions to the x86 ISA to work on matrices, consists of
1353
+ * 1) 2-dimentional registers (tiles), hold sub-matrices from larger matrices in memory
1354
+ * 2) Accelerator called Tile Matrix Multiply (TMUL), contains instructions operating on tiles
1355
+ *
1356
+ * II. Platforms that supports AMX:
1357
+ * +-----------------+-----+----------+----------+----------+----------+
1358
+ * | Platforms | Gen | amx-bf16 | amx-tile | amx-int8 | amx-fp16 |
1359
+ * +-----------------+-----+----------+----------+----------+----------+
1360
+ * | Sapphire Rapids | 4th | YES | YES | YES | NO |
1361
+ * +-----------------+-----+----------+----------+----------+----------+
1362
+ * | Emerald Rapids | 5th | YES | YES | YES | NO |
1363
+ * +-----------------+-----+----------+----------+----------+----------+
1364
+ * | Granite Rapids | 6th | YES | YES | YES | YES |
1365
+ * +-----------------+-----+----------+----------+----------+----------+
1366
+ *
1367
+ * Reference: https://www.intel.com/content/www/us/en/products/docs
1368
+ * /accelerator-engines/advanced-matrix-extensions/overview.html
1369
+ */
1370
+ static inline bool cpuinfo_has_x86_amx_bf16(void) {
1371
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1372
+ return cpuinfo_isa.amx_bf16;
1373
+ #else
1374
+ return false;
1375
+ #endif
1376
+ }
1377
+
1378
+ static inline bool cpuinfo_has_x86_amx_tile(void) {
1379
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1380
+ return cpuinfo_isa.amx_tile;
1381
+ #else
1382
+ return false;
1383
+ #endif
1384
+ }
1385
+
1386
+ static inline bool cpuinfo_has_x86_amx_int8(void) {
1387
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1388
+ return cpuinfo_isa.amx_int8;
1389
+ #else
1390
+ return false;
1391
+ #endif
1392
+ }
1393
+
1394
+ static inline bool cpuinfo_has_x86_amx_fp16(void) {
1395
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1396
+ return cpuinfo_isa.amx_fp16;
1397
+ #else
1398
+ return false;
1399
+ #endif
1400
+ }
1401
+
1402
+ /*
1403
+ * Intel AVX Vector Neural Network Instructions (VNNI) INT8
1404
+ * Supported Platfroms: Sierra Forest, Arrow Lake, Lunar Lake
1405
+ */
1406
+ static inline bool cpuinfo_has_x86_avx_vnni_int8(void) {
1407
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1408
+ return cpuinfo_isa.avx_vnni_int8;
1409
+ #else
1410
+ return false;
1411
+ #endif
1412
+ }
1413
+
1414
+ /*
1415
+ * Intel AVX Vector Neural Network Instructions (VNNI) INT16
1416
+ * Supported Platfroms: Arrow Lake, Lunar Lake
1417
+ */
1418
+ static inline bool cpuinfo_has_x86_avx_vnni_int16(void) {
1419
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1420
+ return cpuinfo_isa.avx_vnni_int16;
1421
+ #else
1422
+ return false;
1423
+ #endif
1424
+ }
1425
+
1426
+ /*
1427
+ * A new set of instructions, which can convert low precision floating point
1428
+ * like BF16/FP16 to high precision floating point FP32, as well as convert FP32
1429
+ * elements to BF16. This instruction allows the platform to have improved AI
1430
+ * capabilities and better compatibility.
1431
+ *
1432
+ * Supported Platforms: Sierra Forest, Arrow Lake, Lunar Lake
1433
+ */
1434
+ static inline bool cpuinfo_has_x86_avx_ne_convert(void) {
1435
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1436
+ return cpuinfo_isa.avx_ne_convert;
1437
+ #else
1438
+ return false;
1439
+ #endif
1440
+ }
1441
+
1442
+ static inline bool cpuinfo_has_x86_avx10_1(void) {
1443
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1444
+ return cpuinfo_isa.avx10_1;
1445
+ #else
1446
+ return false;
1447
+ #endif
1448
+ }
1449
+
1450
+ static inline bool cpuinfo_has_x86_avx10_2(void) {
1451
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1452
+ return cpuinfo_isa.avx10_2;
1453
+ #else
1454
+ return false;
1455
+ #endif
1456
+ }
1457
+
1458
+ static inline bool cpuinfo_has_x86_hle(void) {
1459
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1460
+ return cpuinfo_isa.hle;
1461
+ #else
1462
+ return false;
1463
+ #endif
1464
+ }
1465
+
1466
+ static inline bool cpuinfo_has_x86_rtm(void) {
1467
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1468
+ return cpuinfo_isa.rtm;
1469
+ #else
1470
+ return false;
1471
+ #endif
1472
+ }
1473
+
1474
+ static inline bool cpuinfo_has_x86_xtest(void) {
1475
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1476
+ return cpuinfo_isa.xtest;
1477
+ #else
1478
+ return false;
1479
+ #endif
1480
+ }
1481
+
1482
+ static inline bool cpuinfo_has_x86_mpx(void) {
1483
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1484
+ return cpuinfo_isa.mpx;
1485
+ #else
1486
+ return false;
1487
+ #endif
1488
+ }
1489
+
1490
+ static inline bool cpuinfo_has_x86_cmov(void) {
1491
+ #if CPUINFO_ARCH_X86_64
1492
+ return true;
1493
+ #elif CPUINFO_ARCH_X86
1494
+ return cpuinfo_isa.cmov;
1495
+ #else
1496
+ return false;
1497
+ #endif
1498
+ }
1499
+
1500
+ static inline bool cpuinfo_has_x86_cmpxchg8b(void) {
1501
+ #if CPUINFO_ARCH_X86_64
1502
+ return true;
1503
+ #elif CPUINFO_ARCH_X86
1504
+ return cpuinfo_isa.cmpxchg8b;
1505
+ #else
1506
+ return false;
1507
+ #endif
1508
+ }
1509
+
1510
+ static inline bool cpuinfo_has_x86_cmpxchg16b(void) {
1511
+ #if CPUINFO_ARCH_X86_64
1512
+ return cpuinfo_isa.cmpxchg16b;
1513
+ #else
1514
+ return false;
1515
+ #endif
1516
+ }
1517
+
1518
+ static inline bool cpuinfo_has_x86_clwb(void) {
1519
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1520
+ return cpuinfo_isa.clwb;
1521
+ #else
1522
+ return false;
1523
+ #endif
1524
+ }
1525
+
1526
+ static inline bool cpuinfo_has_x86_movbe(void) {
1527
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1528
+ return cpuinfo_isa.movbe;
1529
+ #else
1530
+ return false;
1531
+ #endif
1532
+ }
1533
+
1534
+ static inline bool cpuinfo_has_x86_lahf_sahf(void) {
1535
+ #if CPUINFO_ARCH_X86
1536
+ return true;
1537
+ #elif CPUINFO_ARCH_X86_64
1538
+ return cpuinfo_isa.lahf_sahf;
1539
+ #else
1540
+ return false;
1541
+ #endif
1542
+ }
1543
+
1544
+ static inline bool cpuinfo_has_x86_lzcnt(void) {
1545
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1546
+ return cpuinfo_isa.lzcnt;
1547
+ #else
1548
+ return false;
1549
+ #endif
1550
+ }
1551
+
1552
+ static inline bool cpuinfo_has_x86_popcnt(void) {
1553
+ #if CPUINFO_ARCH_X86_64
1554
+ #if defined(__ANDROID__)
1555
+ return true;
1556
+ #else
1557
+ return cpuinfo_isa.popcnt;
1558
+ #endif
1559
+ #elif CPUINFO_ARCH_X86
1560
+ return cpuinfo_isa.popcnt;
1561
+ #else
1562
+ return false;
1563
+ #endif
1564
+ }
1565
+
1566
+ static inline bool cpuinfo_has_x86_tbm(void) {
1567
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1568
+ return cpuinfo_isa.tbm;
1569
+ #else
1570
+ return false;
1571
+ #endif
1572
+ }
1573
+
1574
+ static inline bool cpuinfo_has_x86_bmi(void) {
1575
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1576
+ return cpuinfo_isa.bmi;
1577
+ #else
1578
+ return false;
1579
+ #endif
1580
+ }
1581
+
1582
+ static inline bool cpuinfo_has_x86_bmi2(void) {
1583
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1584
+ return cpuinfo_isa.bmi2;
1585
+ #else
1586
+ return false;
1587
+ #endif
1588
+ }
1589
+
1590
+ static inline bool cpuinfo_has_x86_adx(void) {
1591
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1592
+ return cpuinfo_isa.adx;
1593
+ #else
1594
+ return false;
1595
+ #endif
1596
+ }
1597
+
1598
+ static inline bool cpuinfo_has_x86_aes(void) {
1599
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1600
+ return cpuinfo_isa.aes;
1601
+ #else
1602
+ return false;
1603
+ #endif
1604
+ }
1605
+
1606
+ static inline bool cpuinfo_has_x86_vaes(void) {
1607
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1608
+ return cpuinfo_isa.vaes;
1609
+ #else
1610
+ return false;
1611
+ #endif
1612
+ }
1613
+
1614
+ static inline bool cpuinfo_has_x86_pclmulqdq(void) {
1615
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1616
+ return cpuinfo_isa.pclmulqdq;
1617
+ #else
1618
+ return false;
1619
+ #endif
1620
+ }
1621
+
1622
+ static inline bool cpuinfo_has_x86_vpclmulqdq(void) {
1623
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1624
+ return cpuinfo_isa.vpclmulqdq;
1625
+ #else
1626
+ return false;
1627
+ #endif
1628
+ }
1629
+
1630
+ static inline bool cpuinfo_has_x86_gfni(void) {
1631
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1632
+ return cpuinfo_isa.gfni;
1633
+ #else
1634
+ return false;
1635
+ #endif
1636
+ }
1637
+
1638
+ static inline bool cpuinfo_has_x86_rdrand(void) {
1639
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1640
+ return cpuinfo_isa.rdrand;
1641
+ #else
1642
+ return false;
1643
+ #endif
1644
+ }
1645
+
1646
+ static inline bool cpuinfo_has_x86_rdseed(void) {
1647
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1648
+ return cpuinfo_isa.rdseed;
1649
+ #else
1650
+ return false;
1651
+ #endif
1652
+ }
1653
+
1654
+ static inline bool cpuinfo_has_x86_sha(void) {
1655
+ #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
1656
+ return cpuinfo_isa.sha;
1657
+ #else
1658
+ return false;
1659
+ #endif
1660
+ }
1661
+
1662
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1663
+ /* This structure is not a part of stable API. Use cpuinfo_has_arm_* functions
1664
+ * instead. */
1665
+ struct cpuinfo_arm_isa {
1666
+ #if CPUINFO_ARCH_ARM
1667
+ bool thumb;
1668
+ bool thumb2;
1669
+ bool thumbee;
1670
+ bool jazelle;
1671
+ bool armv5e;
1672
+ bool armv6;
1673
+ bool armv6k;
1674
+ bool armv7;
1675
+ bool armv7mp;
1676
+ bool armv8;
1677
+ bool idiv;
1678
+
1679
+ bool vfpv2;
1680
+ bool vfpv3;
1681
+ bool d32;
1682
+ bool fp16;
1683
+ bool fma;
1684
+
1685
+ bool wmmx;
1686
+ bool wmmx2;
1687
+ bool neon;
1688
+ #endif
1689
+ #if CPUINFO_ARCH_ARM64
1690
+ bool atomics;
1691
+ bool bf16;
1692
+ bool sve;
1693
+ bool sve2;
1694
+ bool i8mm;
1695
+ bool sme;
1696
+ bool sme2;
1697
+ bool sme2p1;
1698
+ bool sme_i16i32;
1699
+ bool sme_bi32i32;
1700
+ bool sme_b16b16;
1701
+ bool sme_f16f16;
1702
+ uint32_t svelen;
1703
+ uint32_t smelen;
1704
+ #endif
1705
+ bool rdm;
1706
+ bool fp16arith;
1707
+ bool dot;
1708
+ bool jscvt;
1709
+ bool fcma;
1710
+ bool fhm;
1711
+
1712
+ bool aes;
1713
+ bool sha1;
1714
+ bool sha2;
1715
+ bool pmull;
1716
+ bool crc32;
1717
+ };
1718
+
1719
+ extern struct cpuinfo_arm_isa cpuinfo_isa;
1720
+ #endif
1721
+
1722
+ static inline bool cpuinfo_has_arm_thumb(void) {
1723
+ #if CPUINFO_ARCH_ARM
1724
+ return cpuinfo_isa.thumb;
1725
+ #else
1726
+ return false;
1727
+ #endif
1728
+ }
1729
+
1730
+ static inline bool cpuinfo_has_arm_thumb2(void) {
1731
+ #if CPUINFO_ARCH_ARM
1732
+ return cpuinfo_isa.thumb2;
1733
+ #else
1734
+ return false;
1735
+ #endif
1736
+ }
1737
+
1738
+ static inline bool cpuinfo_has_arm_v5e(void) {
1739
+ #if CPUINFO_ARCH_ARM
1740
+ return cpuinfo_isa.armv5e;
1741
+ #else
1742
+ return false;
1743
+ #endif
1744
+ }
1745
+
1746
+ static inline bool cpuinfo_has_arm_v6(void) {
1747
+ #if CPUINFO_ARCH_ARM
1748
+ return cpuinfo_isa.armv6;
1749
+ #else
1750
+ return false;
1751
+ #endif
1752
+ }
1753
+
1754
+ static inline bool cpuinfo_has_arm_v6k(void) {
1755
+ #if CPUINFO_ARCH_ARM
1756
+ return cpuinfo_isa.armv6k;
1757
+ #else
1758
+ return false;
1759
+ #endif
1760
+ }
1761
+
1762
+ static inline bool cpuinfo_has_arm_v7(void) {
1763
+ #if CPUINFO_ARCH_ARM
1764
+ return cpuinfo_isa.armv7;
1765
+ #else
1766
+ return false;
1767
+ #endif
1768
+ }
1769
+
1770
+ static inline bool cpuinfo_has_arm_v7mp(void) {
1771
+ #if CPUINFO_ARCH_ARM
1772
+ return cpuinfo_isa.armv7mp;
1773
+ #else
1774
+ return false;
1775
+ #endif
1776
+ }
1777
+
1778
+ static inline bool cpuinfo_has_arm_v8(void) {
1779
+ #if CPUINFO_ARCH_ARM64
1780
+ return true;
1781
+ #elif CPUINFO_ARCH_ARM
1782
+ return cpuinfo_isa.armv8;
1783
+ #else
1784
+ return false;
1785
+ #endif
1786
+ }
1787
+
1788
+ static inline bool cpuinfo_has_arm_idiv(void) {
1789
+ #if CPUINFO_ARCH_ARM64
1790
+ return true;
1791
+ #elif CPUINFO_ARCH_ARM
1792
+ return cpuinfo_isa.idiv;
1793
+ #else
1794
+ return false;
1795
+ #endif
1796
+ }
1797
+
1798
+ static inline bool cpuinfo_has_arm_vfpv2(void) {
1799
+ #if CPUINFO_ARCH_ARM
1800
+ return cpuinfo_isa.vfpv2;
1801
+ #else
1802
+ return false;
1803
+ #endif
1804
+ }
1805
+
1806
+ static inline bool cpuinfo_has_arm_vfpv3(void) {
1807
+ #if CPUINFO_ARCH_ARM64
1808
+ return true;
1809
+ #elif CPUINFO_ARCH_ARM
1810
+ return cpuinfo_isa.vfpv3;
1811
+ #else
1812
+ return false;
1813
+ #endif
1814
+ }
1815
+
1816
+ static inline bool cpuinfo_has_arm_vfpv3_d32(void) {
1817
+ #if CPUINFO_ARCH_ARM64
1818
+ return true;
1819
+ #elif CPUINFO_ARCH_ARM
1820
+ return cpuinfo_isa.vfpv3 && cpuinfo_isa.d32;
1821
+ #else
1822
+ return false;
1823
+ #endif
1824
+ }
1825
+
1826
+ static inline bool cpuinfo_has_arm_vfpv3_fp16(void) {
1827
+ #if CPUINFO_ARCH_ARM64
1828
+ return true;
1829
+ #elif CPUINFO_ARCH_ARM
1830
+ return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16;
1831
+ #else
1832
+ return false;
1833
+ #endif
1834
+ }
1835
+
1836
+ static inline bool cpuinfo_has_arm_vfpv3_fp16_d32(void) {
1837
+ #if CPUINFO_ARCH_ARM64
1838
+ return true;
1839
+ #elif CPUINFO_ARCH_ARM
1840
+ return cpuinfo_isa.vfpv3 && cpuinfo_isa.fp16 && cpuinfo_isa.d32;
1841
+ #else
1842
+ return false;
1843
+ #endif
1844
+ }
1845
+
1846
+ static inline bool cpuinfo_has_arm_vfpv4(void) {
1847
+ #if CPUINFO_ARCH_ARM64
1848
+ return true;
1849
+ #elif CPUINFO_ARCH_ARM
1850
+ return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma;
1851
+ #else
1852
+ return false;
1853
+ #endif
1854
+ }
1855
+
1856
+ static inline bool cpuinfo_has_arm_vfpv4_d32(void) {
1857
+ #if CPUINFO_ARCH_ARM64
1858
+ return true;
1859
+ #elif CPUINFO_ARCH_ARM
1860
+ return cpuinfo_isa.vfpv3 && cpuinfo_isa.fma && cpuinfo_isa.d32;
1861
+ #else
1862
+ return false;
1863
+ #endif
1864
+ }
1865
+
1866
+ static inline bool cpuinfo_has_arm_fp16_arith(void) {
1867
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1868
+ return cpuinfo_isa.fp16arith;
1869
+ #else
1870
+ return false;
1871
+ #endif
1872
+ }
1873
+
1874
+ static inline bool cpuinfo_has_arm_bf16(void) {
1875
+ #if CPUINFO_ARCH_ARM64
1876
+ return cpuinfo_isa.bf16;
1877
+ #else
1878
+ return false;
1879
+ #endif
1880
+ }
1881
+
1882
+ static inline bool cpuinfo_has_arm_wmmx(void) {
1883
+ #if CPUINFO_ARCH_ARM
1884
+ return cpuinfo_isa.wmmx;
1885
+ #else
1886
+ return false;
1887
+ #endif
1888
+ }
1889
+
1890
+ static inline bool cpuinfo_has_arm_wmmx2(void) {
1891
+ #if CPUINFO_ARCH_ARM
1892
+ return cpuinfo_isa.wmmx2;
1893
+ #else
1894
+ return false;
1895
+ #endif
1896
+ }
1897
+
1898
+ static inline bool cpuinfo_has_arm_neon(void) {
1899
+ #if CPUINFO_ARCH_ARM64
1900
+ return true;
1901
+ #elif CPUINFO_ARCH_ARM
1902
+ return cpuinfo_isa.neon;
1903
+ #else
1904
+ return false;
1905
+ #endif
1906
+ }
1907
+
1908
+ static inline bool cpuinfo_has_arm_neon_fp16(void) {
1909
+ #if CPUINFO_ARCH_ARM64
1910
+ return true;
1911
+ #elif CPUINFO_ARCH_ARM
1912
+ return cpuinfo_isa.neon && cpuinfo_isa.fp16;
1913
+ #else
1914
+ return false;
1915
+ #endif
1916
+ }
1917
+
1918
+ static inline bool cpuinfo_has_arm_neon_fma(void) {
1919
+ #if CPUINFO_ARCH_ARM64
1920
+ return true;
1921
+ #elif CPUINFO_ARCH_ARM
1922
+ return cpuinfo_isa.neon && cpuinfo_isa.fma;
1923
+ #else
1924
+ return false;
1925
+ #endif
1926
+ }
1927
+
1928
+ static inline bool cpuinfo_has_arm_neon_v8(void) {
1929
+ #if CPUINFO_ARCH_ARM64
1930
+ return true;
1931
+ #elif CPUINFO_ARCH_ARM
1932
+ return cpuinfo_isa.neon && cpuinfo_isa.armv8;
1933
+ #else
1934
+ return false;
1935
+ #endif
1936
+ }
1937
+
1938
+ static inline bool cpuinfo_has_arm_atomics(void) {
1939
+ #if CPUINFO_ARCH_ARM64
1940
+ return cpuinfo_isa.atomics;
1941
+ #else
1942
+ return false;
1943
+ #endif
1944
+ }
1945
+
1946
+ static inline bool cpuinfo_has_arm_neon_rdm(void) {
1947
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1948
+ return cpuinfo_isa.rdm;
1949
+ #else
1950
+ return false;
1951
+ #endif
1952
+ }
1953
+
1954
+ static inline bool cpuinfo_has_arm_neon_fp16_arith(void) {
1955
+ #if CPUINFO_ARCH_ARM
1956
+ return cpuinfo_isa.neon && cpuinfo_isa.fp16arith;
1957
+ #elif CPUINFO_ARCH_ARM64
1958
+ return cpuinfo_isa.fp16arith;
1959
+ #else
1960
+ return false;
1961
+ #endif
1962
+ }
1963
+
1964
+ static inline bool cpuinfo_has_arm_fhm(void) {
1965
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1966
+ return cpuinfo_isa.fhm;
1967
+ #else
1968
+ return false;
1969
+ #endif
1970
+ }
1971
+
1972
+ static inline bool cpuinfo_has_arm_neon_dot(void) {
1973
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1974
+ return cpuinfo_isa.dot;
1975
+ #else
1976
+ return false;
1977
+ #endif
1978
+ }
1979
+
1980
+ static inline bool cpuinfo_has_arm_neon_bf16(void) {
1981
+ #if CPUINFO_ARCH_ARM64
1982
+ return cpuinfo_isa.bf16;
1983
+ #else
1984
+ return false;
1985
+ #endif
1986
+ }
1987
+
1988
+ static inline bool cpuinfo_has_arm_jscvt(void) {
1989
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1990
+ return cpuinfo_isa.jscvt;
1991
+ #else
1992
+ return false;
1993
+ #endif
1994
+ }
1995
+
1996
+ static inline bool cpuinfo_has_arm_fcma(void) {
1997
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
1998
+ return cpuinfo_isa.fcma;
1999
+ #else
2000
+ return false;
2001
+ #endif
2002
+ }
2003
+
2004
+ static inline bool cpuinfo_has_arm_i8mm(void) {
2005
+ #if CPUINFO_ARCH_ARM64
2006
+ return cpuinfo_isa.i8mm;
2007
+ #else
2008
+ return false;
2009
+ #endif
2010
+ }
2011
+
2012
+ static inline bool cpuinfo_has_arm_aes(void) {
2013
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
2014
+ return cpuinfo_isa.aes;
2015
+ #else
2016
+ return false;
2017
+ #endif
2018
+ }
2019
+
2020
+ static inline bool cpuinfo_has_arm_sha1(void) {
2021
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
2022
+ return cpuinfo_isa.sha1;
2023
+ #else
2024
+ return false;
2025
+ #endif
2026
+ }
2027
+
2028
+ static inline bool cpuinfo_has_arm_sha2(void) {
2029
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
2030
+ return cpuinfo_isa.sha2;
2031
+ #else
2032
+ return false;
2033
+ #endif
2034
+ }
2035
+
2036
+ static inline bool cpuinfo_has_arm_pmull(void) {
2037
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
2038
+ return cpuinfo_isa.pmull;
2039
+ #else
2040
+ return false;
2041
+ #endif
2042
+ }
2043
+
2044
+ static inline bool cpuinfo_has_arm_crc32(void) {
2045
+ #if CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
2046
+ return cpuinfo_isa.crc32;
2047
+ #else
2048
+ return false;
2049
+ #endif
2050
+ }
2051
+
2052
+ static inline bool cpuinfo_has_arm_sve(void) {
2053
+ #if CPUINFO_ARCH_ARM64
2054
+ return cpuinfo_isa.sve;
2055
+ #else
2056
+ return false;
2057
+ #endif
2058
+ }
2059
+
2060
+ static inline bool cpuinfo_has_arm_sve_bf16(void) {
2061
+ #if CPUINFO_ARCH_ARM64
2062
+ return cpuinfo_isa.sve && cpuinfo_isa.bf16;
2063
+ #else
2064
+ return false;
2065
+ #endif
2066
+ }
2067
+
2068
+ static inline bool cpuinfo_has_arm_sve2(void) {
2069
+ #if CPUINFO_ARCH_ARM64
2070
+ return cpuinfo_isa.sve2;
2071
+ #else
2072
+ return false;
2073
+ #endif
2074
+ }
2075
+
2076
+ // Function to get the max SVE vector length on ARM CPU's which support SVE.
2077
+ static inline uint32_t cpuinfo_get_max_arm_sve_length(void) {
2078
+ #if CPUINFO_ARCH_ARM64
2079
+ return cpuinfo_isa.svelen * 8; // bytes * 8 = bit length(vector length)
2080
+ #else
2081
+ return 0;
2082
+ #endif
2083
+ }
2084
+
2085
+ // Function to get the max SME vector length on ARM CPU's which support SME.
2086
+ static inline uint32_t cpuinfo_get_max_arm_sme_length(void) {
2087
+ #if CPUINFO_ARCH_ARM64
2088
+ return cpuinfo_isa.smelen * 8; // bytes * 8 = bit length(vector length)
2089
+ #else
2090
+ return 0;
2091
+ #endif
2092
+ }
2093
+
2094
+ static inline bool cpuinfo_has_arm_sme(void) {
2095
+ #if CPUINFO_ARCH_ARM64
2096
+ return cpuinfo_isa.sme;
2097
+ #else
2098
+ return false;
2099
+ #endif
2100
+ }
2101
+
2102
+ static inline bool cpuinfo_has_arm_sme2(void) {
2103
+ #if CPUINFO_ARCH_ARM64
2104
+ return cpuinfo_isa.sme2;
2105
+ #else
2106
+ return false;
2107
+ #endif
2108
+ }
2109
+
2110
+ static inline bool cpuinfo_has_arm_sme2p1(void) {
2111
+ #if CPUINFO_ARCH_ARM64
2112
+ return cpuinfo_isa.sme2p1;
2113
+ #else
2114
+ return false;
2115
+ #endif
2116
+ }
2117
+
2118
+ static inline bool cpuinfo_has_arm_sme_i16i32(void) {
2119
+ #if CPUINFO_ARCH_ARM64
2120
+ return cpuinfo_isa.sme_i16i32;
2121
+ #else
2122
+ return false;
2123
+ #endif
2124
+ }
2125
+
2126
+ static inline bool cpuinfo_has_arm_sme_bi32i32(void) {
2127
+ #if CPUINFO_ARCH_ARM64
2128
+ return cpuinfo_isa.sme_bi32i32;
2129
+ #else
2130
+ return false;
2131
+ #endif
2132
+ }
2133
+
2134
+ static inline bool cpuinfo_has_arm_sme_b16b16(void) {
2135
+ #if CPUINFO_ARCH_ARM64
2136
+ return cpuinfo_isa.sme_b16b16;
2137
+ #else
2138
+ return false;
2139
+ #endif
2140
+ }
2141
+
2142
+ static inline bool cpuinfo_has_arm_sme_f16f16(void) {
2143
+ #if CPUINFO_ARCH_ARM64
2144
+ return cpuinfo_isa.sme_f16f16;
2145
+ #else
2146
+ return false;
2147
+ #endif
2148
+ }
2149
+
2150
+ #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
2151
+ /* This structure is not a part of stable API. Use cpuinfo_has_riscv_* functions
2152
+ * instead. */
2153
+ struct cpuinfo_riscv_isa {
2154
+ /**
2155
+ * Keep fields in line with the canonical order as defined by
2156
+ * Section 27.11 Subset Naming Convention.
2157
+ */
2158
+ /* RV32I/64I/128I Base ISA. */
2159
+ bool i;
2160
+ #if CPUINFO_ARCH_RISCV32
2161
+ /* RV32E Base ISA. */
2162
+ bool e;
2163
+ #endif
2164
+ /* Integer Multiply/Divide Extension. */
2165
+ bool m;
2166
+ /* Atomic Extension. */
2167
+ bool a;
2168
+ /* Single-Precision Floating-Point Extension. */
2169
+ bool f;
2170
+ /* Double-Precision Floating-Point Extension. */
2171
+ bool d;
2172
+ /* Compressed Extension. */
2173
+ bool c;
2174
+ /* Vector Extension. */
2175
+ bool v;
2176
+ };
2177
+
2178
+ extern struct cpuinfo_riscv_isa cpuinfo_isa;
2179
+ #endif
2180
+
2181
+ static inline bool cpuinfo_has_riscv_i(void) {
2182
+ #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
2183
+ return cpuinfo_isa.i;
2184
+ #else
2185
+ return false;
2186
+ #endif
2187
+ }
2188
+
2189
+ static inline bool cpuinfo_has_riscv_e(void) {
2190
+ #if CPUINFO_ARCH_RISCV32
2191
+ return cpuinfo_isa.e;
2192
+ #else
2193
+ return false;
2194
+ #endif
2195
+ }
2196
+
2197
+ static inline bool cpuinfo_has_riscv_m(void) {
2198
+ #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
2199
+ return cpuinfo_isa.m;
2200
+ #else
2201
+ return false;
2202
+ #endif
2203
+ }
2204
+
2205
+ static inline bool cpuinfo_has_riscv_a(void) {
2206
+ #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
2207
+ return cpuinfo_isa.a;
2208
+ #else
2209
+ return false;
2210
+ #endif
2211
+ }
2212
+
2213
+ static inline bool cpuinfo_has_riscv_f(void) {
2214
+ #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
2215
+ return cpuinfo_isa.f;
2216
+ #else
2217
+ return false;
2218
+ #endif
2219
+ }
2220
+
2221
+ static inline bool cpuinfo_has_riscv_d(void) {
2222
+ #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
2223
+ return cpuinfo_isa.d;
2224
+ #else
2225
+ return false;
2226
+ #endif
2227
+ }
2228
+
2229
+ static inline bool cpuinfo_has_riscv_g(void) {
2230
+ // The 'G' extension is simply shorthand for 'IMAFD'.
2231
+ return cpuinfo_has_riscv_i() && cpuinfo_has_riscv_m() && cpuinfo_has_riscv_a() && cpuinfo_has_riscv_f() &&
2232
+ cpuinfo_has_riscv_d();
2233
+ }
2234
+
2235
+ static inline bool cpuinfo_has_riscv_c(void) {
2236
+ #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
2237
+ return cpuinfo_isa.c;
2238
+ #else
2239
+ return false;
2240
+ #endif
2241
+ }
2242
+
2243
+ static inline bool cpuinfo_has_riscv_v(void) {
2244
+ #if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
2245
+ return cpuinfo_isa.v;
2246
+ #else
2247
+ return false;
2248
+ #endif
2249
+ }
2250
+
2251
+ const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processors(void);
2252
+ const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_cores(void);
2253
+ const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_clusters(void);
2254
+ const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_packages(void);
2255
+ const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarchs(void);
2256
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_caches(void);
2257
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_caches(void);
2258
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_caches(void);
2259
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_caches(void);
2260
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_caches(void);
2261
+
2262
+ const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_processor(uint32_t index);
2263
+ const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_core(uint32_t index);
2264
+ const struct cpuinfo_cluster* CPUINFO_ABI cpuinfo_get_cluster(uint32_t index);
2265
+ const struct cpuinfo_package* CPUINFO_ABI cpuinfo_get_package(uint32_t index);
2266
+ const struct cpuinfo_uarch_info* CPUINFO_ABI cpuinfo_get_uarch(uint32_t index);
2267
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1i_cache(uint32_t index);
2268
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l1d_cache(uint32_t index);
2269
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l2_cache(uint32_t index);
2270
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l3_cache(uint32_t index);
2271
+ const struct cpuinfo_cache* CPUINFO_ABI cpuinfo_get_l4_cache(uint32_t index);
2272
+
2273
+ uint32_t CPUINFO_ABI cpuinfo_get_processors_count(void);
2274
+ uint32_t CPUINFO_ABI cpuinfo_get_cores_count(void);
2275
+ uint32_t CPUINFO_ABI cpuinfo_get_clusters_count(void);
2276
+ uint32_t CPUINFO_ABI cpuinfo_get_packages_count(void);
2277
+ uint32_t CPUINFO_ABI cpuinfo_get_uarchs_count(void);
2278
+ uint32_t CPUINFO_ABI cpuinfo_get_l1i_caches_count(void);
2279
+ uint32_t CPUINFO_ABI cpuinfo_get_l1d_caches_count(void);
2280
+ uint32_t CPUINFO_ABI cpuinfo_get_l2_caches_count(void);
2281
+ uint32_t CPUINFO_ABI cpuinfo_get_l3_caches_count(void);
2282
+ uint32_t CPUINFO_ABI cpuinfo_get_l4_caches_count(void);
2283
+
2284
+ /**
2285
+ * Returns upper bound on cache size.
2286
+ */
2287
+ uint32_t CPUINFO_ABI cpuinfo_get_max_cache_size(void);
2288
+
2289
+ /**
2290
+ * Identify the logical processor that executes the current thread.
2291
+ *
2292
+ * There is no guarantee that the thread will stay on the same logical processor
2293
+ * for any time. Callers should treat the result as only a hint, and be prepared
2294
+ * to handle NULL return value.
2295
+ */
2296
+ const struct cpuinfo_processor* CPUINFO_ABI cpuinfo_get_current_processor(void);
2297
+
2298
+ /**
2299
+ * Identify the core that executes the current thread.
2300
+ *
2301
+ * There is no guarantee that the thread will stay on the same core for any
2302
+ * time. Callers should treat the result as only a hint, and be prepared to
2303
+ * handle NULL return value.
2304
+ */
2305
+ const struct cpuinfo_core* CPUINFO_ABI cpuinfo_get_current_core(void);
2306
+
2307
+ /**
2308
+ * Identify the microarchitecture index of the core that executes the current
2309
+ * thread. If the system does not support such identification, the function
2310
+ * returns 0.
2311
+ *
2312
+ * There is no guarantee that the thread will stay on the same type of core for
2313
+ * any time. Callers should treat the result as only a hint.
2314
+ */
2315
+ uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index(void);
2316
+
2317
+ /**
2318
+ * Identify the microarchitecture index of the core that executes the current
2319
+ * thread. If the system does not support such identification, the function
2320
+ * returns the user-specified default value.
2321
+ *
2322
+ * There is no guarantee that the thread will stay on the same type of core for
2323
+ * any time. Callers should treat the result as only a hint.
2324
+ */
2325
+ uint32_t CPUINFO_ABI cpuinfo_get_current_uarch_index_with_default(uint32_t default_uarch_index);
2326
+
2327
+ #ifdef __cplusplus
2328
+ } /* extern "C" */
2329
+ #endif
2330
+
2331
+ #endif /* CPUINFO_H */
deps/exla/cache/xla_extension/include/include/dnnl.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_H
18
+ #define DNNL_H
19
+
20
+ #include "oneapi/dnnl/dnnl.h"
21
+
22
+ #endif /* DNNL_H */
deps/exla/cache/xla_extension/include/include/dnnl.hpp ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_HPP
18
+ #define DNNL_HPP
19
+
20
+ #include "oneapi/dnnl/dnnl.hpp"
21
+
22
+ #endif /* DNNL_HPP */
deps/exla/cache/xla_extension/include/include/dnnl_config.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_CONFIG_H
18
+ #define DNNL_CONFIG_H
19
+
20
+ #include "oneapi/dnnl/dnnl_config.h"
21
+
22
+ #endif /* DNNL_CONFIG_H */
deps/exla/cache/xla_extension/include/include/dnnl_debug.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_DEBUG_H
18
+ #define DNNL_DEBUG_H
19
+
20
+ #include "oneapi/dnnl/dnnl_debug.h"
21
+
22
+ #endif /* DNNL_DEBUG_H */
deps/exla/cache/xla_extension/include/include/dnnl_ocl.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_OCL_H
18
+ #define DNNL_OCL_H
19
+
20
+ #include "oneapi/dnnl/dnnl_ocl.h"
21
+
22
+ #endif /* DNNL_OCL_H */
deps/exla/cache/xla_extension/include/include/dnnl_ocl.hpp ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_OCL_HPP
18
+ #define DNNL_OCL_HPP
19
+
20
+ #include "oneapi/dnnl/dnnl_ocl.hpp"
21
+
22
+ #endif /* DNNL_OCL_HPP */
deps/exla/cache/xla_extension/include/include/dnnl_sycl.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_SYCL_H
18
+ #define DNNL_SYCL_H
19
+
20
+ #include "oneapi/dnnl/dnnl_sycl.h"
21
+
22
+ #endif /* DNNL_SYCL_H */
deps/exla/cache/xla_extension/include/include/dnnl_sycl.hpp ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_SYCL_HPP
18
+ #define DNNL_SYCL_HPP
19
+
20
+ #include "oneapi/dnnl/dnnl_sycl.hpp"
21
+
22
+ #endif /* DNNL_SYCL_HPP */
deps/exla/cache/xla_extension/include/include/dnnl_sycl_types.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_SYCL_TYPES_H
18
+ #define DNNL_SYCL_TYPES_H
19
+
20
+ #include "oneapi/dnnl/dnnl_sycl_types.h"
21
+
22
+ #endif /* DNNL_SYCL_TYPES_H */
deps/exla/cache/xla_extension/include/include/dnnl_threadpool.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_THREADPOOL_H
18
+ #define DNNL_THREADPOOL_H
19
+
20
+ #include "oneapi/dnnl/dnnl_threadpool.h"
21
+
22
+ #endif /* DNNL_THREADPOOL_H */
deps/exla/cache/xla_extension/include/include/dnnl_threadpool.hpp ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_THREADPOOL_HPP
18
+ #define DNNL_THREADPOOL_HPP
19
+
20
+ #include "oneapi/dnnl/dnnl_threadpool.hpp"
21
+
22
+ #endif /* DNNL_THREADPOOL_HPP */
deps/exla/cache/xla_extension/include/include/dnnl_threadpool_iface.hpp ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_THREADPOOL_IFACE_HPP
18
+ #define DNNL_THREADPOOL_IFACE_HPP
19
+
20
+ #include "oneapi/dnnl/dnnl_threadpool_iface.hpp"
21
+
22
+ #endif /* DNNL_THREADPOOL_IFACE_HPP */
deps/exla/cache/xla_extension/include/include/dnnl_types.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_TYPES_H
18
+ #define DNNL_TYPES_H
19
+
20
+ #include "oneapi/dnnl/dnnl_types.h"
21
+
22
+ #endif /* DNNL_TYPES_H */
deps/exla/cache/xla_extension/include/include/dnnl_version.h ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef DNNL_VERSION_H
18
+ #define DNNL_VERSION_H
19
+
20
+ #include "oneapi/dnnl/dnnl_version.h"
21
+
22
+ #endif /* DNNL_VERSION_H */
deps/exla/cache/xla_extension/include/include/fxdiv.h ADDED
@@ -0,0 +1,425 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #pragma once
2
+ #ifndef FXDIV_H
3
+ #define FXDIV_H
4
+
5
+ #if defined(__cplusplus) && (__cplusplus >= 201103L)
6
+ #include <cstddef>
7
+ #include <cstdint>
8
+ #include <climits>
9
+ #elif !defined(__OPENCL_VERSION__)
10
+ #include <stddef.h>
11
+ #include <stdint.h>
12
+ #include <limits.h>
13
+ #endif
14
+
15
+ #if defined(_MSC_VER)
16
+ #include <intrin.h>
17
+ #if defined(_M_IX86) || defined(_M_X64)
18
+ #include <immintrin.h>
19
+ #endif
20
+ #endif
21
+
22
+ #ifndef FXDIV_USE_INLINE_ASSEMBLY
23
+ #define FXDIV_USE_INLINE_ASSEMBLY 0
24
+ #endif
25
+
26
+ static inline uint64_t fxdiv_mulext_uint32_t(uint32_t a, uint32_t b) {
27
+ #if defined(_MSC_VER) && defined(_M_IX86)
28
+ return (uint64_t) __emulu((unsigned int) a, (unsigned int) b);
29
+ #else
30
+ return (uint64_t) a * (uint64_t) b;
31
+ #endif
32
+ }
33
+
34
+ static inline uint32_t fxdiv_mulhi_uint32_t(uint32_t a, uint32_t b) {
35
+ #if defined(__OPENCL_VERSION__)
36
+ return mul_hi(a, b);
37
+ #elif defined(__CUDA_ARCH__)
38
+ return (uint32_t) __umulhi((unsigned int) a, (unsigned int) b);
39
+ #elif defined(_MSC_VER) && defined(_M_IX86)
40
+ return (uint32_t) (__emulu((unsigned int) a, (unsigned int) b) >> 32);
41
+ #elif defined(_MSC_VER) && defined(_M_ARM)
42
+ return (uint32_t) _MulUnsignedHigh((unsigned long) a, (unsigned long) b);
43
+ #else
44
+ return (uint32_t) (((uint64_t) a * (uint64_t) b) >> 32);
45
+ #endif
46
+ }
47
+
48
+ static inline uint64_t fxdiv_mulhi_uint64_t(uint64_t a, uint64_t b) {
49
+ #if defined(__OPENCL_VERSION__)
50
+ return mul_hi(a, b);
51
+ #elif defined(__CUDA_ARCH__)
52
+ return (uint64_t) __umul64hi((unsigned long long) a, (unsigned long long) b);
53
+ #elif defined(_MSC_VER) && defined(_M_X64)
54
+ return (uint64_t) __umulh((unsigned __int64) a, (unsigned __int64) b);
55
+ #elif defined(__GNUC__) && defined(__SIZEOF_INT128__)
56
+ return (uint64_t) (((((unsigned __int128) a) * ((unsigned __int128) b))) >> 64);
57
+ #else
58
+ const uint32_t a_lo = (uint32_t) a;
59
+ const uint32_t a_hi = (uint32_t) (a >> 32);
60
+ const uint32_t b_lo = (uint32_t) b;
61
+ const uint32_t b_hi = (uint32_t) (b >> 32);
62
+
63
+ const uint64_t t = fxdiv_mulext_uint32_t(a_hi, b_lo) +
64
+ (uint64_t) fxdiv_mulhi_uint32_t(a_lo, b_lo);
65
+ return fxdiv_mulext_uint32_t(a_hi, b_hi) + (t >> 32) +
66
+ ((fxdiv_mulext_uint32_t(a_lo, b_hi) + (uint64_t) (uint32_t) t) >> 32);
67
+ #endif
68
+ }
69
+
70
+ static inline size_t fxdiv_mulhi_size_t(size_t a, size_t b) {
71
+ #if SIZE_MAX == UINT32_MAX
72
+ return (size_t) fxdiv_mulhi_uint32_t((uint32_t) a, (uint32_t) b);
73
+ #elif SIZE_MAX == UINT64_MAX
74
+ return (size_t) fxdiv_mulhi_uint64_t((uint64_t) a, (uint64_t) b);
75
+ #else
76
+ #error Unsupported platform
77
+ #endif
78
+ }
79
+
80
+ struct fxdiv_divisor_uint32_t {
81
+ uint32_t value;
82
+ uint32_t m;
83
+ uint8_t s1;
84
+ uint8_t s2;
85
+ };
86
+
87
+ struct fxdiv_result_uint32_t {
88
+ uint32_t quotient;
89
+ uint32_t remainder;
90
+ };
91
+
92
+ struct fxdiv_divisor_uint64_t {
93
+ uint64_t value;
94
+ uint64_t m;
95
+ uint8_t s1;
96
+ uint8_t s2;
97
+ };
98
+
99
+ struct fxdiv_result_uint64_t {
100
+ uint64_t quotient;
101
+ uint64_t remainder;
102
+ };
103
+
104
+ struct fxdiv_divisor_size_t {
105
+ size_t value;
106
+ size_t m;
107
+ uint8_t s1;
108
+ uint8_t s2;
109
+ };
110
+
111
+ struct fxdiv_result_size_t {
112
+ size_t quotient;
113
+ size_t remainder;
114
+ };
115
+
116
+ static inline struct fxdiv_divisor_uint32_t fxdiv_init_uint32_t(uint32_t d) {
117
+ struct fxdiv_divisor_uint32_t result = { d };
118
+ if (d == 1) {
119
+ result.m = UINT32_C(1);
120
+ result.s1 = 0;
121
+ result.s2 = 0;
122
+ } else {
123
+ #if defined(__OPENCL_VERSION__)
124
+ const uint32_t l_minus_1 = 31 - clz(d - 1);
125
+ #elif defined(__CUDA_ARCH__)
126
+ const uint32_t l_minus_1 = 31 - __clz((int) (d - 1));
127
+ #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64))
128
+ unsigned long l_minus_1;
129
+ _BitScanReverse(&l_minus_1, (unsigned long) (d - 1));
130
+ #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) && FXDIV_USE_INLINE_ASSEMBLY
131
+ uint32_t l_minus_1;
132
+ __asm__("BSRL %[d_minus_1], %[l_minus_1]"
133
+ : [l_minus_1] "=r" (l_minus_1)
134
+ : [d_minus_1] "r" (d - 1)
135
+ : "cc");
136
+ #elif defined(__GNUC__)
137
+ const uint32_t l_minus_1 = 31 - __builtin_clz(d - 1);
138
+ #else
139
+ /* Based on Algorithm 2 from Hacker's delight */
140
+
141
+ uint32_t l_minus_1 = 0;
142
+ uint32_t x = d - 1;
143
+ uint32_t y = x >> 16;
144
+ if (y != 0) {
145
+ l_minus_1 += 16;
146
+ x = y;
147
+ }
148
+ y = x >> 8;
149
+ if (y != 0) {
150
+ l_minus_1 += 8;
151
+ x = y;
152
+ }
153
+ y = x >> 4;
154
+ if (y != 0) {
155
+ l_minus_1 += 4;
156
+ x = y;
157
+ }
158
+ y = x >> 2;
159
+ if (y != 0) {
160
+ l_minus_1 += 2;
161
+ x = y;
162
+ }
163
+ if ((x & 2) != 0) {
164
+ l_minus_1 += 1;
165
+ }
166
+ #endif
167
+ uint32_t u_hi = (UINT32_C(2) << (uint32_t) l_minus_1) - d;
168
+
169
+ /* Division of 64-bit number u_hi:UINT32_C(0) by 32-bit number d, 32-bit quotient output q */
170
+ #if defined(__GNUC__) && defined(__i386__) && FXDIV_USE_INLINE_ASSEMBLY
171
+ uint32_t q;
172
+ __asm__("DIVL %[d]"
173
+ : "=a" (q), "+d" (u_hi)
174
+ : [d] "r" (d), "a" (0)
175
+ : "cc");
176
+ #elif (defined(_MSC_VER) && _MSC_VER >= 1920) && !defined(__clang__) && !defined(__INTEL_COMPILER) && (defined(_M_IX86) || defined(_M_X64))
177
+ unsigned int remainder;
178
+ const uint32_t q = (uint32_t) _udiv64((unsigned __int64) ((uint64_t) u_hi << 32), (unsigned int) d, &remainder);
179
+ #else
180
+ const uint32_t q = ((uint64_t) u_hi << 32) / d;
181
+ #endif
182
+
183
+ result.m = q + UINT32_C(1);
184
+ result.s1 = 1;
185
+ result.s2 = (uint8_t) l_minus_1;
186
+ }
187
+ return result;
188
+ }
189
+
190
+ static inline struct fxdiv_divisor_uint64_t fxdiv_init_uint64_t(uint64_t d) {
191
+ struct fxdiv_divisor_uint64_t result = { d };
192
+ if (d == 1) {
193
+ result.m = UINT64_C(1);
194
+ result.s1 = 0;
195
+ result.s2 = 0;
196
+ } else {
197
+ #if defined(__OPENCL_VERSION__)
198
+ const uint32_t nlz_d = clz(d);
199
+ const uint32_t l_minus_1 = 63 - clz(d - 1);
200
+ #elif defined(__CUDA_ARCH__)
201
+ const uint32_t nlz_d = __clzll((long long) d);
202
+ const uint32_t l_minus_1 = 63 - __clzll((long long) (d - 1));
203
+ #elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_ARM64))
204
+ unsigned long l_minus_1;
205
+ _BitScanReverse64(&l_minus_1, (unsigned __int64) (d - 1));
206
+ unsigned long bsr_d;
207
+ _BitScanReverse64(&bsr_d, (unsigned __int64) d);
208
+ const uint32_t nlz_d = bsr_d ^ 0x3F;
209
+ #elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_ARM))
210
+ const uint64_t d_minus_1 = d - 1;
211
+ const uint8_t d_is_power_of_2 = (d & d_minus_1) == 0;
212
+ unsigned long l_minus_1;
213
+ if ((uint32_t) (d_minus_1 >> 32) == 0) {
214
+ _BitScanReverse(&l_minus_1, (unsigned long) d_minus_1);
215
+ } else {
216
+ _BitScanReverse(&l_minus_1, (unsigned long) (uint32_t) (d_minus_1 >> 32));
217
+ l_minus_1 += 32;
218
+ }
219
+ const uint32_t nlz_d = ((uint8_t) l_minus_1 ^ UINT8_C(0x3F)) - d_is_power_of_2;
220
+ #elif defined(__GNUC__) && defined(__x86_64__) && FXDIV_USE_INLINE_ASSEMBLY
221
+ uint64_t l_minus_1;
222
+ __asm__("BSRQ %[d_minus_1], %[l_minus_1]"
223
+ : [l_minus_1] "=r" (l_minus_1)
224
+ : [d_minus_1] "r" (d - 1)
225
+ : "cc");
226
+ #elif defined(__GNUC__)
227
+ const uint32_t l_minus_1 = 63 - __builtin_clzll(d - 1);
228
+ const uint32_t nlz_d = __builtin_clzll(d);
229
+ #else
230
+ /* Based on Algorithm 2 from Hacker's delight */
231
+ const uint64_t d_minus_1 = d - 1;
232
+ const uint32_t d_is_power_of_2 = (d & d_minus_1) == 0;
233
+ uint32_t l_minus_1 = 0;
234
+ uint32_t x = (uint32_t) d_minus_1;
235
+ uint32_t y = d_minus_1 >> 32;
236
+ if (y != 0) {
237
+ l_minus_1 += 32;
238
+ x = y;
239
+ }
240
+ y = x >> 16;
241
+ if (y != 0) {
242
+ l_minus_1 += 16;
243
+ x = y;
244
+ }
245
+ y = x >> 8;
246
+ if (y != 0) {
247
+ l_minus_1 += 8;
248
+ x = y;
249
+ }
250
+ y = x >> 4;
251
+ if (y != 0) {
252
+ l_minus_1 += 4;
253
+ x = y;
254
+ }
255
+ y = x >> 2;
256
+ if (y != 0) {
257
+ l_minus_1 += 2;
258
+ x = y;
259
+ }
260
+ if ((x & 2) != 0) {
261
+ l_minus_1 += 1;
262
+ }
263
+ const uint32_t nlz_d = (l_minus_1 ^ UINT32_C(0x3F)) - d_is_power_of_2;
264
+ #endif
265
+ uint64_t u_hi = (UINT64_C(2) << (uint32_t) l_minus_1) - d;
266
+
267
+ /* Division of 128-bit number u_hi:UINT64_C(0) by 64-bit number d, 64-bit quotient output q */
268
+ #if defined(__GNUC__) && defined(__x86_64__) && FXDIV_USE_INLINE_ASSEMBLY
269
+ uint64_t q;
270
+ __asm__("DIVQ %[d]"
271
+ : "=a" (q), "+d" (u_hi)
272
+ : [d] "r" (d), "a" (UINT64_C(0))
273
+ : "cc");
274
+ #elif 0 && defined(__GNUC__) && defined(__SIZEOF_INT128__)
275
+ /* GCC, Clang, and Intel Compiler fail to inline optimized implementation and call into support library for 128-bit division */
276
+ const uint64_t q = (uint64_t) (((unsigned __int128) u_hi << 64) / ((unsigned __int128) d));
277
+ #elif (defined(_MSC_VER) && _MSC_VER >= 1920) && !defined(__clang__) && !defined(__INTEL_COMPILER) && defined(_M_X64)
278
+ unsigned __int64 remainder;
279
+ const uint64_t q = (uint64_t) _udiv128((unsigned __int64) u_hi, 0, (unsigned __int64) d, &remainder);
280
+ #else
281
+ /* Implementation based on code from Hacker's delight */
282
+
283
+ /* Normalize divisor and shift divident left */
284
+ d <<= nlz_d;
285
+ u_hi <<= nlz_d;
286
+ /* Break divisor up into two 32-bit digits */
287
+ const uint64_t d_hi = (uint32_t) (d >> 32);
288
+ const uint32_t d_lo = (uint32_t) d;
289
+
290
+ /* Compute the first quotient digit, q1 */
291
+ uint64_t q1 = u_hi / d_hi;
292
+ uint64_t r1 = u_hi - q1 * d_hi;
293
+
294
+ while ((q1 >> 32) != 0 || fxdiv_mulext_uint32_t((uint32_t) q1, d_lo) > (r1 << 32)) {
295
+ q1 -= 1;
296
+ r1 += d_hi;
297
+ if ((r1 >> 32) != 0) {
298
+ break;
299
+ }
300
+ }
301
+
302
+ /* Multiply and subtract. */
303
+ u_hi = (u_hi << 32) - q1 * d;
304
+
305
+ /* Compute the second quotient digit, q0 */
306
+ uint64_t q0 = u_hi / d_hi;
307
+ uint64_t r0 = u_hi - q0 * d_hi;
308
+
309
+ while ((q0 >> 32) != 0 || fxdiv_mulext_uint32_t((uint32_t) q0, d_lo) > (r0 << 32)) {
310
+ q0 -= 1;
311
+ r0 += d_hi;
312
+ if ((r0 >> 32) != 0) {
313
+ break;
314
+ }
315
+ }
316
+ const uint64_t q = (q1 << 32) | (uint32_t) q0;
317
+ #endif
318
+ result.m = q + UINT64_C(1);
319
+ result.s1 = 1;
320
+ result.s2 = (uint8_t) l_minus_1;
321
+ }
322
+ return result;
323
+ }
324
+
325
+ static inline struct fxdiv_divisor_size_t fxdiv_init_size_t(size_t d) {
326
+ #if SIZE_MAX == UINT32_MAX
327
+ const struct fxdiv_divisor_uint32_t uint_result = fxdiv_init_uint32_t((uint32_t) d);
328
+ #elif SIZE_MAX == UINT64_MAX
329
+ const struct fxdiv_divisor_uint64_t uint_result = fxdiv_init_uint64_t((uint64_t) d);
330
+ #else
331
+ #error Unsupported platform
332
+ #endif
333
+ struct fxdiv_divisor_size_t size_result = {
334
+ (size_t) uint_result.value,
335
+ (size_t) uint_result.m,
336
+ uint_result.s1,
337
+ uint_result.s2
338
+ };
339
+ return size_result;
340
+ }
341
+
342
+ static inline uint32_t fxdiv_quotient_uint32_t(uint32_t n, const struct fxdiv_divisor_uint32_t divisor) {
343
+ const uint32_t t = fxdiv_mulhi_uint32_t(n, divisor.m);
344
+ return (t + ((n - t) >> divisor.s1)) >> divisor.s2;
345
+ }
346
+
347
+ static inline uint64_t fxdiv_quotient_uint64_t(uint64_t n, const struct fxdiv_divisor_uint64_t divisor) {
348
+ const uint64_t t = fxdiv_mulhi_uint64_t(n, divisor.m);
349
+ return (t + ((n - t) >> divisor.s1)) >> divisor.s2;
350
+ }
351
+
352
+ static inline size_t fxdiv_quotient_size_t(size_t n, const struct fxdiv_divisor_size_t divisor) {
353
+ #if SIZE_MAX == UINT32_MAX
354
+ const struct fxdiv_divisor_uint32_t uint32_divisor = {
355
+ (uint32_t) divisor.value,
356
+ (uint32_t) divisor.m,
357
+ divisor.s1,
358
+ divisor.s2
359
+ };
360
+ return fxdiv_quotient_uint32_t((uint32_t) n, uint32_divisor);
361
+ #elif SIZE_MAX == UINT64_MAX
362
+ const struct fxdiv_divisor_uint64_t uint64_divisor = {
363
+ (uint64_t) divisor.value,
364
+ (uint64_t) divisor.m,
365
+ divisor.s1,
366
+ divisor.s2
367
+ };
368
+ return fxdiv_quotient_uint64_t((uint64_t) n, uint64_divisor);
369
+ #else
370
+ #error Unsupported platform
371
+ #endif
372
+ }
373
+
374
+ static inline uint32_t fxdiv_remainder_uint32_t(uint32_t n, const struct fxdiv_divisor_uint32_t divisor) {
375
+ const uint32_t quotient = fxdiv_quotient_uint32_t(n, divisor);
376
+ return n - quotient * divisor.value;
377
+ }
378
+
379
+ static inline uint64_t fxdiv_remainder_uint64_t(uint64_t n, const struct fxdiv_divisor_uint64_t divisor) {
380
+ const uint64_t quotient = fxdiv_quotient_uint64_t(n, divisor);
381
+ return n - quotient * divisor.value;
382
+ }
383
+
384
+ static inline size_t fxdiv_remainder_size_t(size_t n, const struct fxdiv_divisor_size_t divisor) {
385
+ const size_t quotient = fxdiv_quotient_size_t(n, divisor);
386
+ return n - quotient * divisor.value;
387
+ }
388
+
389
+ static inline uint32_t fxdiv_round_down_uint32_t(uint32_t n, const struct fxdiv_divisor_uint32_t granularity) {
390
+ const uint32_t quotient = fxdiv_quotient_uint32_t(n, granularity);
391
+ return quotient * granularity.value;
392
+ }
393
+
394
+ static inline uint64_t fxdiv_round_down_uint64_t(uint64_t n, const struct fxdiv_divisor_uint64_t granularity) {
395
+ const uint64_t quotient = fxdiv_quotient_uint64_t(n, granularity);
396
+ return quotient * granularity.value;
397
+ }
398
+
399
+ static inline size_t fxdiv_round_down_size_t(size_t n, const struct fxdiv_divisor_size_t granularity) {
400
+ const size_t quotient = fxdiv_quotient_size_t(n, granularity);
401
+ return quotient * granularity.value;
402
+ }
403
+
404
+ static inline struct fxdiv_result_uint32_t fxdiv_divide_uint32_t(uint32_t n, const struct fxdiv_divisor_uint32_t divisor) {
405
+ const uint32_t quotient = fxdiv_quotient_uint32_t(n, divisor);
406
+ const uint32_t remainder = n - quotient * divisor.value;
407
+ struct fxdiv_result_uint32_t result = { quotient, remainder };
408
+ return result;
409
+ }
410
+
411
+ static inline struct fxdiv_result_uint64_t fxdiv_divide_uint64_t(uint64_t n, const struct fxdiv_divisor_uint64_t divisor) {
412
+ const uint64_t quotient = fxdiv_quotient_uint64_t(n, divisor);
413
+ const uint64_t remainder = n - quotient * divisor.value;
414
+ struct fxdiv_result_uint64_t result = { quotient, remainder };
415
+ return result;
416
+ }
417
+
418
+ static inline struct fxdiv_result_size_t fxdiv_divide_size_t(size_t n, const struct fxdiv_divisor_size_t divisor) {
419
+ const size_t quotient = fxdiv_quotient_size_t(n, divisor);
420
+ const size_t remainder = n - quotient * divisor.value;
421
+ struct fxdiv_result_size_t result = { quotient, remainder };
422
+ return result;
423
+ }
424
+
425
+ #endif /* FXDIV_H */
deps/exla/cache/xla_extension/include/include/hwloc.h ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/include/hwloc/autogen/config.h ADDED
@@ -0,0 +1,241 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* -*- c -*-
2
+ * Copyright © 2009 CNRS
3
+ * Copyright © 2009-2022 Inria. All rights reserved.
4
+ * Copyright © 2009-2012 Université Bordeaux
5
+ * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
6
+ * See COPYING in top-level directory.
7
+ */
8
+
9
+ /* The configuration file */
10
+
11
+ #ifndef HWLOC_CONFIG_H
12
+ #define HWLOC_CONFIG_H
13
+
14
+ #define HWLOC_VERSION "2.0.3"
15
+ #define HWLOC_VERSION_MAJOR 2
16
+ #define HWLOC_VERSION_MINOR 0
17
+ #define HWLOC_VERSION_RELEASE 3
18
+ #define HWLOC_VERSION_GREEK ""
19
+
20
+ #undef HWLOC_PCI_COMPONENT_BUILTIN
21
+ #undef HWLOC_OPENCL_COMPONENT_BUILTIN
22
+ #undef HWLOC_CUDA_COMPONENT_BUILTIN
23
+ #undef HWLOC_NVML_COMPONENT_BUILTIN
24
+ #undef HWLOC_RSMI_COMPONENT_BUILTIN
25
+ #undef HWLOC_LEVELZERO_COMPONENT_BUILTIN
26
+ #undef HWLOC_GL_COMPONENT_BUILTIN
27
+ #undef HWLOC_XML_LIBXML_COMPONENT_BUILTIN
28
+
29
+ #if (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
30
+ # define __hwloc_restrict __restrict
31
+ #else
32
+ # if __STDC_VERSION__ >= 199901L
33
+ # define __hwloc_restrict restrict
34
+ # else
35
+ # define __hwloc_restrict
36
+ # endif
37
+ #endif
38
+
39
+ /* Note that if we're compiling C++, then just use the "inline"
40
+ keyword, since it's part of C++ */
41
+ #if defined(c_plusplus) || defined(__cplusplus)
42
+ # define __hwloc_inline inline
43
+ #elif defined(_MSC_VER) || defined(__HP_cc)
44
+ # define __hwloc_inline __inline
45
+ #else
46
+ # define __hwloc_inline __inline__
47
+ #endif
48
+
49
+ /*
50
+ * Note: this is public. We can not assume anything from the compiler used
51
+ * by the application and thus the HWLOC_HAVE_* macros below are not
52
+ * fetched from the autoconf result here. We only automatically use a few
53
+ * well-known easy cases.
54
+ */
55
+
56
+ /* Some handy constants to make the logic below a little more readable */
57
+ #if defined(__cplusplus) && \
58
+ (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR >= 4))
59
+ #define GXX_ABOVE_3_4 1
60
+ #else
61
+ #define GXX_ABOVE_3_4 0
62
+ #endif
63
+
64
+ #if !defined(__cplusplus) && \
65
+ (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95))
66
+ #define GCC_ABOVE_2_95 1
67
+ #else
68
+ #define GCC_ABOVE_2_95 0
69
+ #endif
70
+
71
+ #if !defined(__cplusplus) && \
72
+ (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
73
+ #define GCC_ABOVE_2_96 1
74
+ #else
75
+ #define GCC_ABOVE_2_96 0
76
+ #endif
77
+
78
+ #if !defined(__cplusplus) && \
79
+ (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
80
+ #define GCC_ABOVE_3_3 1
81
+ #else
82
+ #define GCC_ABOVE_3_3 0
83
+ #endif
84
+
85
+ #if !defined(__cplusplus) && \
86
+ (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
87
+ #define GCC_ABOVE_3_4 1
88
+ #else
89
+ #define GCC_ABOVE_3_4 0
90
+ #endif
91
+
92
+ /* Maybe before gcc 2.95 too */
93
+ #ifdef HWLOC_HAVE_ATTRIBUTE_UNUSED
94
+ #define __HWLOC_HAVE_ATTRIBUTE_UNUSED HWLOC_HAVE_ATTRIBUTE_UNUSED
95
+ #elif defined(__GNUC__)
96
+ # define __HWLOC_HAVE_ATTRIBUTE_UNUSED (GXX_ABOVE_3_4 || GCC_ABOVE_2_95)
97
+ #else
98
+ # define __HWLOC_HAVE_ATTRIBUTE_UNUSED 0
99
+ #endif
100
+ #if __HWLOC_HAVE_ATTRIBUTE_UNUSED
101
+ # define __hwloc_attribute_unused __attribute__((__unused__))
102
+ #else
103
+ # define __hwloc_attribute_unused
104
+ #endif
105
+
106
+ #ifdef HWLOC_HAVE_ATTRIBUTE_MALLOC
107
+ #define __HWLOC_HAVE_ATTRIBUTE_MALLOC HWLOC_HAVE_ATTRIBUTE_MALLOC
108
+ #elif defined(__GNUC__)
109
+ # define __HWLOC_HAVE_ATTRIBUTE_MALLOC (GXX_ABOVE_3_4 || GCC_ABOVE_2_96)
110
+ #else
111
+ # define __HWLOC_HAVE_ATTRIBUTE_MALLOC 0
112
+ #endif
113
+ #if __HWLOC_HAVE_ATTRIBUTE_MALLOC
114
+ # define __hwloc_attribute_malloc __attribute__((__malloc__))
115
+ #else
116
+ # define __hwloc_attribute_malloc
117
+ #endif
118
+
119
+ #ifdef HWLOC_HAVE_ATTRIBUTE_CONST
120
+ #define __HWLOC_HAVE_ATTRIBUTE_CONST HWLOC_HAVE_ATTRIBUTE_CONST
121
+ #elif defined(__GNUC__)
122
+ # define __HWLOC_HAVE_ATTRIBUTE_CONST (GXX_ABOVE_3_4 || GCC_ABOVE_2_95)
123
+ #else
124
+ # define __HWLOC_HAVE_ATTRIBUTE_CONST 0
125
+ #endif
126
+ #if __HWLOC_HAVE_ATTRIBUTE_CONST
127
+ # define __hwloc_attribute_const __attribute__((__const__))
128
+ #else
129
+ # define __hwloc_attribute_const
130
+ #endif
131
+
132
+ #ifdef HWLOC_HAVE_ATTRIBUTE_PURE
133
+ #define __HWLOC_HAVE_ATTRIBUTE_PURE HWLOC_HAVE_ATTRIBUTE_PURE
134
+ #elif defined(__GNUC__)
135
+ # define __HWLOC_HAVE_ATTRIBUTE_PURE (GXX_ABOVE_3_4 || GCC_ABOVE_2_96)
136
+ #else
137
+ # define __HWLOC_HAVE_ATTRIBUTE_PURE 0
138
+ #endif
139
+ #if __HWLOC_HAVE_ATTRIBUTE_PURE
140
+ # define __hwloc_attribute_pure __attribute__((__pure__))
141
+ #else
142
+ # define __hwloc_attribute_pure
143
+ #endif
144
+
145
+ #ifndef __hwloc_attribute_deprecated /* allow the user to disable these warnings by defining this macro to nothing */
146
+ #ifdef HWLOC_HAVE_ATTRIBUTE_DEPRECATED
147
+ #define __HWLOC_HAVE_ATTRIBUTE_DEPRECATED HWLOC_HAVE_ATTRIBUTE_DEPRECATED
148
+ #elif defined(__GNUC__)
149
+ # define __HWLOC_HAVE_ATTRIBUTE_DEPRECATED (GXX_ABOVE_3_4 || GCC_ABOVE_3_3)
150
+ #else
151
+ # define __HWLOC_HAVE_ATTRIBUTE_DEPRECATED 0
152
+ #endif
153
+ #if __HWLOC_HAVE_ATTRIBUTE_DEPRECATED
154
+ # define __hwloc_attribute_deprecated __attribute__((__deprecated__))
155
+ #else
156
+ # define __hwloc_attribute_deprecated
157
+ #endif
158
+ #endif
159
+
160
+ #ifdef HWLOC_HAVE_ATTRIBUTE_MAY_ALIAS
161
+ #define __HWLOC_HAVE_ATTRIBUTE_MAY_ALIAS HWLOC_HAVE_ATTRIBUTE_MAY_ALIAS
162
+ #elif defined(__GNUC__)
163
+ # define __HWLOC_HAVE_ATTRIBUTE_MAY_ALIAS (GXX_ABOVE_3_4 || GCC_ABOVE_3_3)
164
+ #else
165
+ # define __HWLOC_HAVE_ATTRIBUTE_MAY_ALIAS 0
166
+ #endif
167
+ #if __HWLOC_HAVE_ATTRIBUTE_MAY_ALIAS
168
+ # define __hwloc_attribute_may_alias __attribute__((__may_alias__))
169
+ #else
170
+ # define __hwloc_attribute_may_alias
171
+ #endif
172
+
173
+ #ifdef HWLOC_HAVE_ATTRIBUTE_WARN_UNUSED_RESULT
174
+ #define __HWLOC_HAVE_ATTRIBUTE_WARN_UNUSED_RESULT HWLOC_HAVE_ATTRIBUTE_WARN_UNUSED_RESULT
175
+ #elif defined(__GNUC__)
176
+ # define __HWLOC_HAVE_ATTRIBUTE_WARN_UNUSED_RESULT (GXX_ABOVE_3_4 || GCC_ABOVE_3_4)
177
+ #else
178
+ # define __HWLOC_HAVE_ATTRIBUTE_WARN_UNUSED_RESULT 0
179
+ #endif
180
+ #if __HWLOC_HAVE_ATTRIBUTE_WARN_UNUSED_RESULT
181
+ # define __hwloc_attribute_warn_unused_result __attribute__((__warn_unused_result__))
182
+ #else
183
+ # define __hwloc_attribute_warn_unused_result
184
+ #endif
185
+
186
+ #ifdef HWLOC_C_HAVE_VISIBILITY
187
+ # if HWLOC_C_HAVE_VISIBILITY
188
+ # define HWLOC_DECLSPEC __attribute__((__visibility__("default")))
189
+ # else
190
+ # define HWLOC_DECLSPEC
191
+ # endif
192
+ #else
193
+ # define HWLOC_DECLSPEC
194
+ #endif
195
+
196
+ /* Defined to 1 on Linux */
197
+ #define HWLOC_LINUX_SYS 1
198
+
199
+ /* Defined to 1 if the CPU_SET macro works */
200
+ #undef HWLOC_HAVE_CPU_SET
201
+
202
+ /* Defined to 1 if you have the `windows.h' header. */
203
+ #undef HWLOC_HAVE_WINDOWS_H
204
+ #define hwloc_pid_t pid_t
205
+ #define hwloc_thread_t pthread_t
206
+
207
+ #ifdef HWLOC_HAVE_WINDOWS_H
208
+
209
+ # include <windows.h>
210
+ typedef DWORDLONG hwloc_uint64_t;
211
+
212
+ #else /* HWLOC_HAVE_WINDOWS_H */
213
+
214
+ # ifdef hwloc_thread_t
215
+ # include <pthread.h>
216
+ # endif /* hwloc_thread_t */
217
+
218
+ /* Defined to 1 if you have the <stdint.h> header file. */
219
+ # define HWLOC_HAVE_STDINT_H 1
220
+
221
+ # include <unistd.h>
222
+ # ifdef HWLOC_HAVE_STDINT_H
223
+ # include <stdint.h>
224
+ # endif
225
+ typedef uint64_t hwloc_uint64_t;
226
+
227
+ #endif /* HWLOC_HAVE_WINDOWS_H */
228
+
229
+ /* Define to 1 if --enable-32bits-pci-domain is called. */
230
+ #undef HWLOC_HAVE_32BITS_PCI_DOMAIN
231
+
232
+ /* Whether we need to re-define all the hwloc public symbols or not */
233
+ #define HWLOC_SYM_TRANSFORM 0
234
+
235
+ /* The hwloc symbol prefix */
236
+ #define HWLOC_SYM_PREFIX hwloc_
237
+
238
+ /* The hwloc symbol prefix in all caps */
239
+ #define HWLOC_SYM_PREFIX_CAPS HWLOC_
240
+
241
+ #endif /* HWLOC_CONFIG_H */
deps/exla/cache/xla_extension/include/include/hwloc/bitmap.h ADDED
@@ -0,0 +1,494 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2009 CNRS
3
+ * Copyright © 2009-2020 Inria. All rights reserved.
4
+ * Copyright © 2009-2012 Université Bordeaux
5
+ * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
6
+ * See COPYING in top-level directory.
7
+ */
8
+
9
+ /** \file
10
+ * \brief The bitmap API, for use in hwloc itself.
11
+ */
12
+
13
+ #ifndef HWLOC_BITMAP_H
14
+ #define HWLOC_BITMAP_H
15
+
16
+ #include "hwloc/autogen/config.h"
17
+
18
+ #include <assert.h>
19
+
20
+
21
+ #ifdef __cplusplus
22
+ extern "C" {
23
+ #endif
24
+
25
+
26
+ /** \defgroup hwlocality_bitmap The bitmap API
27
+ *
28
+ * The ::hwloc_bitmap_t type represents a set of integers (positive or null).
29
+ * A bitmap may be of infinite size (all bits are set after some point).
30
+ * A bitmap may even be full if all bits are set.
31
+ *
32
+ * Bitmaps are used by hwloc for sets of OS processors
33
+ * (which may actually be hardware threads) as by ::hwloc_cpuset_t
34
+ * (a typedef for ::hwloc_bitmap_t), or sets of NUMA memory nodes
35
+ * as ::hwloc_nodeset_t (also a typedef for ::hwloc_bitmap_t).
36
+ * Those are used for cpuset and nodeset fields in the ::hwloc_obj structure,
37
+ * see \ref hwlocality_object_sets.
38
+ *
39
+ * <em>Both CPU and node sets are always indexed by OS physical number.</em>
40
+ * However users should usually not build CPU and node sets manually
41
+ * (e.g. with hwloc_bitmap_set()).
42
+ * One should rather use existing object sets and combine them with
43
+ * hwloc_bitmap_or(), etc.
44
+ * For instance, binding the current thread on a pair of cores may be performed with:
45
+ * \code
46
+ * hwloc_obj_t core1 = ... , core2 = ... ;
47
+ * hwloc_bitmap_t set = hwloc_bitmap_alloc();
48
+ * hwloc_bitmap_or(set, core1->cpuset, core2->cpuset);
49
+ * hwloc_set_cpubind(topology, set, HWLOC_CPUBIND_THREAD);
50
+ * hwloc_bitmap_free(set);
51
+ * \endcode
52
+ *
53
+ * \note Most functions below return an int that may be negative in case of
54
+ * error. The usual error case would be an internal failure to realloc/extend
55
+ * the storage of the bitmap (\p errno would be set to \c ENOMEM).
56
+ *
57
+ * \note Several examples of using the bitmap API are available under the
58
+ * doc/examples/ directory in the source tree.
59
+ * Regression tests such as tests/hwloc/hwloc_bitmap*.c also make intensive use
60
+ * of this API.
61
+ * @{
62
+ */
63
+
64
+
65
+ /** \brief
66
+ * Set of bits represented as an opaque pointer to an internal bitmap.
67
+ */
68
+ typedef struct hwloc_bitmap_s * hwloc_bitmap_t;
69
+ /** \brief a non-modifiable ::hwloc_bitmap_t */
70
+ typedef const struct hwloc_bitmap_s * hwloc_const_bitmap_t;
71
+
72
+
73
+ /*
74
+ * Bitmap allocation, freeing and copying.
75
+ */
76
+
77
+ /** \brief Allocate a new empty bitmap.
78
+ *
79
+ * \returns A valid bitmap or \c NULL.
80
+ *
81
+ * The bitmap should be freed by a corresponding call to
82
+ * hwloc_bitmap_free().
83
+ */
84
+ HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc(void) __hwloc_attribute_malloc;
85
+
86
+ /** \brief Allocate a new full bitmap. */
87
+ HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_alloc_full(void) __hwloc_attribute_malloc;
88
+
89
+ /** \brief Free bitmap \p bitmap.
90
+ *
91
+ * If \p bitmap is \c NULL, no operation is performed.
92
+ */
93
+ HWLOC_DECLSPEC void hwloc_bitmap_free(hwloc_bitmap_t bitmap);
94
+
95
+ /** \brief Duplicate bitmap \p bitmap by allocating a new bitmap and copying \p bitmap contents.
96
+ *
97
+ * If \p bitmap is \c NULL, \c NULL is returned.
98
+ */
99
+ HWLOC_DECLSPEC hwloc_bitmap_t hwloc_bitmap_dup(hwloc_const_bitmap_t bitmap) __hwloc_attribute_malloc;
100
+
101
+ /** \brief Copy the contents of bitmap \p src into the already allocated bitmap \p dst */
102
+ HWLOC_DECLSPEC int hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t src);
103
+
104
+
105
+ /*
106
+ * Bitmap/String Conversion
107
+ */
108
+
109
+ /** \brief Stringify a bitmap.
110
+ *
111
+ * Up to \p buflen characters may be written in buffer \p buf.
112
+ *
113
+ * If \p buflen is 0, \p buf may safely be \c NULL.
114
+ *
115
+ * \return the number of character that were actually written if not truncating,
116
+ * or that would have been written (not including the ending \\0).
117
+ */
118
+ HWLOC_DECLSPEC int hwloc_bitmap_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
119
+
120
+ /** \brief Stringify a bitmap into a newly allocated string.
121
+ *
122
+ * \return -1 on error.
123
+ */
124
+ HWLOC_DECLSPEC int hwloc_bitmap_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
125
+
126
+ /** \brief Parse a bitmap string and stores it in bitmap \p bitmap.
127
+ */
128
+ HWLOC_DECLSPEC int hwloc_bitmap_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
129
+
130
+ /** \brief Stringify a bitmap in the list format.
131
+ *
132
+ * Lists are comma-separated indexes or ranges.
133
+ * Ranges are dash separated indexes.
134
+ * The last range may not have an ending indexes if the bitmap is infinitely set.
135
+ *
136
+ * Up to \p buflen characters may be written in buffer \p buf.
137
+ *
138
+ * If \p buflen is 0, \p buf may safely be \c NULL.
139
+ *
140
+ * \return the number of character that were actually written if not truncating,
141
+ * or that would have been written (not including the ending \\0).
142
+ */
143
+ HWLOC_DECLSPEC int hwloc_bitmap_list_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
144
+
145
+ /** \brief Stringify a bitmap into a newly allocated list string.
146
+ *
147
+ * \return -1 on error.
148
+ */
149
+ HWLOC_DECLSPEC int hwloc_bitmap_list_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
150
+
151
+ /** \brief Parse a list string and stores it in bitmap \p bitmap.
152
+ */
153
+ HWLOC_DECLSPEC int hwloc_bitmap_list_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
154
+
155
+ /** \brief Stringify a bitmap in the taskset-specific format.
156
+ *
157
+ * The taskset command manipulates bitmap strings that contain a single
158
+ * (possible very long) hexadecimal number starting with 0x.
159
+ *
160
+ * Up to \p buflen characters may be written in buffer \p buf.
161
+ *
162
+ * If \p buflen is 0, \p buf may safely be \c NULL.
163
+ *
164
+ * \return the number of character that were actually written if not truncating,
165
+ * or that would have been written (not including the ending \\0).
166
+ */
167
+ HWLOC_DECLSPEC int hwloc_bitmap_taskset_snprintf(char * __hwloc_restrict buf, size_t buflen, hwloc_const_bitmap_t bitmap);
168
+
169
+ /** \brief Stringify a bitmap into a newly allocated taskset-specific string.
170
+ *
171
+ * \return -1 on error.
172
+ */
173
+ HWLOC_DECLSPEC int hwloc_bitmap_taskset_asprintf(char ** strp, hwloc_const_bitmap_t bitmap);
174
+
175
+ /** \brief Parse a taskset-specific bitmap string and stores it in bitmap \p bitmap.
176
+ */
177
+ HWLOC_DECLSPEC int hwloc_bitmap_taskset_sscanf(hwloc_bitmap_t bitmap, const char * __hwloc_restrict string);
178
+
179
+
180
+ /*
181
+ * Building bitmaps.
182
+ */
183
+
184
+ /** \brief Empty the bitmap \p bitmap */
185
+ HWLOC_DECLSPEC void hwloc_bitmap_zero(hwloc_bitmap_t bitmap);
186
+
187
+ /** \brief Fill bitmap \p bitmap with all possible indexes (even if those objects don't exist or are otherwise unavailable) */
188
+ HWLOC_DECLSPEC void hwloc_bitmap_fill(hwloc_bitmap_t bitmap);
189
+
190
+ /** \brief Empty the bitmap \p bitmap and add bit \p id */
191
+ HWLOC_DECLSPEC int hwloc_bitmap_only(hwloc_bitmap_t bitmap, unsigned id);
192
+
193
+ /** \brief Fill the bitmap \p and clear the index \p id */
194
+ HWLOC_DECLSPEC int hwloc_bitmap_allbut(hwloc_bitmap_t bitmap, unsigned id);
195
+
196
+ /** \brief Setup bitmap \p bitmap from unsigned long \p mask */
197
+ HWLOC_DECLSPEC int hwloc_bitmap_from_ulong(hwloc_bitmap_t bitmap, unsigned long mask);
198
+
199
+ /** \brief Setup bitmap \p bitmap from unsigned long \p mask used as \p i -th subset */
200
+ HWLOC_DECLSPEC int hwloc_bitmap_from_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask);
201
+
202
+ /** \brief Setup bitmap \p bitmap from unsigned longs \p masks used as first \p nr subsets */
203
+ HWLOC_DECLSPEC int hwloc_bitmap_from_ulongs(hwloc_bitmap_t bitmap, unsigned nr, const unsigned long *masks);
204
+
205
+
206
+ /*
207
+ * Modifying bitmaps.
208
+ */
209
+
210
+ /** \brief Add index \p id in bitmap \p bitmap */
211
+ HWLOC_DECLSPEC int hwloc_bitmap_set(hwloc_bitmap_t bitmap, unsigned id);
212
+
213
+ /** \brief Add indexes from \p begin to \p end in bitmap \p bitmap.
214
+ *
215
+ * If \p end is \c -1, the range is infinite.
216
+ */
217
+ HWLOC_DECLSPEC int hwloc_bitmap_set_range(hwloc_bitmap_t bitmap, unsigned begin, int end);
218
+
219
+ /** \brief Replace \p i -th subset of bitmap \p bitmap with unsigned long \p mask */
220
+ HWLOC_DECLSPEC int hwloc_bitmap_set_ith_ulong(hwloc_bitmap_t bitmap, unsigned i, unsigned long mask);
221
+
222
+ /** \brief Remove index \p id from bitmap \p bitmap */
223
+ HWLOC_DECLSPEC int hwloc_bitmap_clr(hwloc_bitmap_t bitmap, unsigned id);
224
+
225
+ /** \brief Remove indexes from \p begin to \p end in bitmap \p bitmap.
226
+ *
227
+ * If \p end is \c -1, the range is infinite.
228
+ */
229
+ HWLOC_DECLSPEC int hwloc_bitmap_clr_range(hwloc_bitmap_t bitmap, unsigned begin, int end);
230
+
231
+ /** \brief Keep a single index among those set in bitmap \p bitmap
232
+ *
233
+ * May be useful before binding so that the process does not
234
+ * have a chance of migrating between multiple processors
235
+ * in the original mask.
236
+ * Instead of running the task on any PU inside the given CPU set,
237
+ * the operating system scheduler will be forced to run it on a single
238
+ * of these PUs.
239
+ * It avoids a migration overhead and cache-line ping-pongs between PUs.
240
+ *
241
+ * \note This function is NOT meant to distribute multiple processes
242
+ * within a single CPU set. It always return the same single bit when
243
+ * called multiple times on the same input set. hwloc_distrib() may
244
+ * be used for generating CPU sets to distribute multiple tasks below
245
+ * a single multi-PU object.
246
+ *
247
+ * \note This function cannot be applied to an object set directly. It
248
+ * should be applied to a copy (which may be obtained with hwloc_bitmap_dup()).
249
+ */
250
+ HWLOC_DECLSPEC int hwloc_bitmap_singlify(hwloc_bitmap_t bitmap);
251
+
252
+
253
+ /*
254
+ * Consulting bitmaps.
255
+ */
256
+
257
+ /** \brief Convert the beginning part of bitmap \p bitmap into unsigned long \p mask */
258
+ HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ulong(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
259
+
260
+ /** \brief Convert the \p i -th subset of bitmap \p bitmap into unsigned long mask */
261
+ HWLOC_DECLSPEC unsigned long hwloc_bitmap_to_ith_ulong(hwloc_const_bitmap_t bitmap, unsigned i) __hwloc_attribute_pure;
262
+
263
+ /** \brief Convert the first \p nr subsets of bitmap \p bitmap into the array of \p nr unsigned long \p masks
264
+ *
265
+ * \p nr may be determined earlier with hwloc_bitmap_nr_ulongs().
266
+ *
267
+ * \return 0
268
+ */
269
+ HWLOC_DECLSPEC int hwloc_bitmap_to_ulongs(hwloc_const_bitmap_t bitmap, unsigned nr, unsigned long *masks);
270
+
271
+ /** \brief Return the number of unsigned longs required for storing bitmap \p bitmap entirely
272
+ *
273
+ * This is the number of contiguous unsigned longs from the very first bit of the bitmap
274
+ * (even if unset) up to the last set bit.
275
+ * This is useful for knowing the \p nr parameter to pass to hwloc_bitmap_to_ulongs()
276
+ * (or which calls to hwloc_bitmap_to_ith_ulong() are needed)
277
+ * to entirely convert a bitmap into multiple unsigned longs.
278
+ *
279
+ * When called on the output of hwloc_topology_get_topology_cpuset(),
280
+ * the returned number is large enough for all cpusets of the topology.
281
+ *
282
+ * \return -1 if \p bitmap is infinite.
283
+ */
284
+ HWLOC_DECLSPEC int hwloc_bitmap_nr_ulongs(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
285
+
286
+ /** \brief Test whether index \p id is part of bitmap \p bitmap.
287
+ *
288
+ * \return 1 if the bit at index \p id is set in bitmap \p bitmap, 0 otherwise.
289
+ */
290
+ HWLOC_DECLSPEC int hwloc_bitmap_isset(hwloc_const_bitmap_t bitmap, unsigned id) __hwloc_attribute_pure;
291
+
292
+ /** \brief Test whether bitmap \p bitmap is empty
293
+ *
294
+ * \return 1 if bitmap is empty, 0 otherwise.
295
+ */
296
+ HWLOC_DECLSPEC int hwloc_bitmap_iszero(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
297
+
298
+ /** \brief Test whether bitmap \p bitmap is completely full
299
+ *
300
+ * \return 1 if bitmap is full, 0 otherwise.
301
+ *
302
+ * \note A full bitmap is always infinitely set.
303
+ */
304
+ HWLOC_DECLSPEC int hwloc_bitmap_isfull(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
305
+
306
+ /** \brief Compute the first index (least significant bit) in bitmap \p bitmap
307
+ *
308
+ * \return -1 if no index is set in \p bitmap.
309
+ */
310
+ HWLOC_DECLSPEC int hwloc_bitmap_first(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
311
+
312
+ /** \brief Compute the next index in bitmap \p bitmap which is after index \p prev
313
+ *
314
+ * If \p prev is -1, the first index is returned.
315
+ *
316
+ * \return -1 if no index with higher index is set in \p bitmap.
317
+ */
318
+ HWLOC_DECLSPEC int hwloc_bitmap_next(hwloc_const_bitmap_t bitmap, int prev) __hwloc_attribute_pure;
319
+
320
+ /** \brief Compute the last index (most significant bit) in bitmap \p bitmap
321
+ *
322
+ * \return -1 if no index is set in \p bitmap, or if \p bitmap is infinitely set.
323
+ */
324
+ HWLOC_DECLSPEC int hwloc_bitmap_last(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
325
+
326
+ /** \brief Compute the "weight" of bitmap \p bitmap (i.e., number of
327
+ * indexes that are in the bitmap).
328
+ *
329
+ * \return the number of indexes that are in the bitmap.
330
+ *
331
+ * \return -1 if \p bitmap is infinitely set.
332
+ */
333
+ HWLOC_DECLSPEC int hwloc_bitmap_weight(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
334
+
335
+ /** \brief Compute the first unset index (least significant bit) in bitmap \p bitmap
336
+ *
337
+ * \return -1 if no index is unset in \p bitmap.
338
+ */
339
+ HWLOC_DECLSPEC int hwloc_bitmap_first_unset(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
340
+
341
+ /** \brief Compute the next unset index in bitmap \p bitmap which is after index \p prev
342
+ *
343
+ * If \p prev is -1, the first unset index is returned.
344
+ *
345
+ * \return -1 if no index with higher index is unset in \p bitmap.
346
+ */
347
+ HWLOC_DECLSPEC int hwloc_bitmap_next_unset(hwloc_const_bitmap_t bitmap, int prev) __hwloc_attribute_pure;
348
+
349
+ /** \brief Compute the last unset index (most significant bit) in bitmap \p bitmap
350
+ *
351
+ * \return -1 if no index is unset in \p bitmap, or if \p bitmap is infinitely set.
352
+ */
353
+ HWLOC_DECLSPEC int hwloc_bitmap_last_unset(hwloc_const_bitmap_t bitmap) __hwloc_attribute_pure;
354
+
355
+ /** \brief Loop macro iterating on bitmap \p bitmap
356
+ *
357
+ * The loop must start with hwloc_bitmap_foreach_begin() and end
358
+ * with hwloc_bitmap_foreach_end() followed by a terminating ';'.
359
+ *
360
+ * \p index is the loop variable; it should be an unsigned int. The
361
+ * first iteration will set \p index to the lowest index in the bitmap.
362
+ * Successive iterations will iterate through, in order, all remaining
363
+ * indexes set in the bitmap. To be specific: each iteration will return a
364
+ * value for \p index such that hwloc_bitmap_isset(bitmap, index) is true.
365
+ *
366
+ * The assert prevents the loop from being infinite if the bitmap is infinitely set.
367
+ *
368
+ * \hideinitializer
369
+ */
370
+ #define hwloc_bitmap_foreach_begin(id, bitmap) \
371
+ do { \
372
+ assert(hwloc_bitmap_weight(bitmap) != -1); \
373
+ for (id = hwloc_bitmap_first(bitmap); \
374
+ (unsigned) id != (unsigned) -1; \
375
+ id = hwloc_bitmap_next(bitmap, id)) {
376
+
377
+ /** \brief End of loop macro iterating on a bitmap.
378
+ *
379
+ * Needs a terminating ';'.
380
+ *
381
+ * \sa hwloc_bitmap_foreach_begin()
382
+ * \hideinitializer
383
+ */
384
+ #define hwloc_bitmap_foreach_end() \
385
+ } \
386
+ } while (0)
387
+
388
+
389
+ /*
390
+ * Combining bitmaps.
391
+ */
392
+
393
+ /** \brief Or bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
394
+ *
395
+ * \p res can be the same as \p bitmap1 or \p bitmap2
396
+ */
397
+ HWLOC_DECLSPEC int hwloc_bitmap_or (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
398
+
399
+ /** \brief And bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
400
+ *
401
+ * \p res can be the same as \p bitmap1 or \p bitmap2
402
+ */
403
+ HWLOC_DECLSPEC int hwloc_bitmap_and (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
404
+
405
+ /** \brief And bitmap \p bitmap1 and the negation of \p bitmap2 and store the result in bitmap \p res
406
+ *
407
+ * \p res can be the same as \p bitmap1 or \p bitmap2
408
+ */
409
+ HWLOC_DECLSPEC int hwloc_bitmap_andnot (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
410
+
411
+ /** \brief Xor bitmaps \p bitmap1 and \p bitmap2 and store the result in bitmap \p res
412
+ *
413
+ * \p res can be the same as \p bitmap1 or \p bitmap2
414
+ */
415
+ HWLOC_DECLSPEC int hwloc_bitmap_xor (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2);
416
+
417
+ /** \brief Negate bitmap \p bitmap and store the result in bitmap \p res
418
+ *
419
+ * \p res can be the same as \p bitmap
420
+ */
421
+ HWLOC_DECLSPEC int hwloc_bitmap_not (hwloc_bitmap_t res, hwloc_const_bitmap_t bitmap);
422
+
423
+
424
+ /*
425
+ * Comparing bitmaps.
426
+ */
427
+
428
+ /** \brief Test whether bitmaps \p bitmap1 and \p bitmap2 intersects.
429
+ *
430
+ * \return 1 if bitmaps intersect, 0 otherwise.
431
+ */
432
+ HWLOC_DECLSPEC int hwloc_bitmap_intersects (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
433
+
434
+ /** \brief Test whether bitmap \p sub_bitmap is part of bitmap \p super_bitmap.
435
+ *
436
+ * \return 1 if \p sub_bitmap is included in \p super_bitmap, 0 otherwise.
437
+ *
438
+ * \note The empty bitmap is considered included in any other bitmap.
439
+ */
440
+ HWLOC_DECLSPEC int hwloc_bitmap_isincluded (hwloc_const_bitmap_t sub_bitmap, hwloc_const_bitmap_t super_bitmap) __hwloc_attribute_pure;
441
+
442
+ /** \brief Test whether bitmap \p bitmap1 is equal to bitmap \p bitmap2.
443
+ *
444
+ * \return 1 if bitmaps are equal, 0 otherwise.
445
+ */
446
+ HWLOC_DECLSPEC int hwloc_bitmap_isequal (hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
447
+
448
+ /** \brief Compare bitmaps \p bitmap1 and \p bitmap2 using their lowest index.
449
+ *
450
+ * A bitmap is considered smaller if its least significant bit is smaller.
451
+ * The empty bitmap is considered higher than anything (because its least significant bit does not exist).
452
+ *
453
+ * \return -1 if \p bitmap1 is considered smaller than \p bitmap2.
454
+ * \return 1 if \p bitmap1 is considered larger than \p bitmap2.
455
+ *
456
+ * For instance comparing binary bitmaps 0011 and 0110 returns -1
457
+ * (hence 0011 is considered smaller than 0110)
458
+ * because least significant bit of 0011 (0001) is smaller than least significant bit of 0110 (0010).
459
+ * Comparing 01001 and 00110 would also return -1 for the same reason.
460
+ *
461
+ * \return 0 if bitmaps are considered equal, even if they are not strictly equal.
462
+ * They just need to have the same least significant bit.
463
+ * For instance, comparing binary bitmaps 0010 and 0110 returns 0 because they have the same least significant bit.
464
+ */
465
+ HWLOC_DECLSPEC int hwloc_bitmap_compare_first(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
466
+
467
+ /** \brief Compare bitmaps \p bitmap1 and \p bitmap2 in lexicographic order.
468
+ *
469
+ * Lexicographic comparison of bitmaps, starting for their highest indexes.
470
+ * Compare last indexes first, then second, etc.
471
+ * The empty bitmap is considered lower than anything.
472
+ *
473
+ * \return -1 if \p bitmap1 is considered smaller than \p bitmap2.
474
+ * \return 1 if \p bitmap1 is considered larger than \p bitmap2.
475
+ * \return 0 if bitmaps are equal (contrary to hwloc_bitmap_compare_first()).
476
+ *
477
+ * For instance comparing binary bitmaps 0011 and 0110 returns -1
478
+ * (hence 0011 is considered smaller than 0110).
479
+ * Comparing 00101 and 01010 returns -1 too.
480
+ *
481
+ * \note This is different from the non-existing hwloc_bitmap_compare_last()
482
+ * which would only compare the highest index of each bitmap.
483
+ */
484
+ HWLOC_DECLSPEC int hwloc_bitmap_compare(hwloc_const_bitmap_t bitmap1, hwloc_const_bitmap_t bitmap2) __hwloc_attribute_pure;
485
+
486
+ /** @} */
487
+
488
+
489
+ #ifdef __cplusplus
490
+ } /* extern "C" */
491
+ #endif
492
+
493
+
494
+ #endif /* HWLOC_BITMAP_H */
deps/exla/cache/xla_extension/include/include/hwloc/cpukinds.h ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2020-2021 Inria. All rights reserved.
3
+ * See COPYING in top-level directory.
4
+ */
5
+
6
+ /** \file
7
+ * \brief Kinds of CPU cores.
8
+ */
9
+
10
+ #ifndef HWLOC_CPUKINDS_H
11
+ #define HWLOC_CPUKINDS_H
12
+
13
+ #include "hwloc.h"
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #elif 0
18
+ }
19
+ #endif
20
+
21
+ /** \defgroup hwlocality_cpukinds Kinds of CPU cores
22
+ *
23
+ * Platforms with heterogeneous CPUs may have some cores with
24
+ * different features or frequencies.
25
+ * This API exposes identical PUs in sets called CPU kinds.
26
+ * Each PU of the topology may only be in a single kind.
27
+ *
28
+ * The number of kinds may be obtained with hwloc_cpukinds_get_nr().
29
+ * If the platform is homogeneous, there may be a single kind
30
+ * with all PUs.
31
+ * If the platform or operating system does not expose any
32
+ * information about CPU cores, there may be no kind at all.
33
+ *
34
+ * The index of the kind that describes a given CPU set
35
+ * (if any, and not partially)
36
+ * may be obtained with hwloc_cpukinds_get_by_cpuset().
37
+ *
38
+ * From the index of a kind, it is possible to retrieve information
39
+ * with hwloc_cpukinds_get_info():
40
+ * an abstracted efficiency value,
41
+ * and an array of info attributes
42
+ * (for instance the "CoreType" and "FrequencyMaxMHz",
43
+ * see \ref topoattrs_cpukinds).
44
+ *
45
+ * A higher efficiency value means greater intrinsic performance
46
+ * (and possibly less performance/power efficiency).
47
+ * Kinds with lower efficiency values are ranked first:
48
+ * Passing 0 as \p kind_index to hwloc_cpukinds_get_info() will
49
+ * return information about the CPU kind with lower performance
50
+ * but higher energy-efficiency.
51
+ * Higher \p kind_index values would rather return information
52
+ * about power-hungry high-performance cores.
53
+ *
54
+ * When available, efficiency values are gathered from the operating system.
55
+ * If so, \p cpukind_efficiency is set in the struct hwloc_topology_discovery_support array.
56
+ * This is currently available on Windows 10, Mac OS X (Darwin),
57
+ * and on some Linux platforms where core "capacity" is exposed in sysfs.
58
+ *
59
+ * If the operating system does not expose core efficiencies natively,
60
+ * hwloc tries to compute efficiencies by comparing CPU kinds using
61
+ * frequencies (on ARM), or core types and frequencies (on other architectures).
62
+ * The environment variable HWLOC_CPUKINDS_RANKING may be used
63
+ * to change this heuristics, see \ref envvar.
64
+ *
65
+ * If hwloc fails to rank any kind, for instance because the operating
66
+ * system does not expose efficiencies and core frequencies,
67
+ * all kinds will have an unknown efficiency (\c -1),
68
+ * and they are not indexed/ordered in any specific way.
69
+ *
70
+ * @{
71
+ */
72
+
73
+ /** \brief Get the number of different kinds of CPU cores in the topology.
74
+ *
75
+ * \p flags must be \c 0 for now.
76
+ *
77
+ * \return The number of CPU kinds (positive integer) on success.
78
+ * \return \c 0 if no information about kinds was found.
79
+ * \return \c -1 with \p errno set to \c EINVAL if \p flags is invalid.
80
+ */
81
+ HWLOC_DECLSPEC int
82
+ hwloc_cpukinds_get_nr(hwloc_topology_t topology,
83
+ unsigned long flags);
84
+
85
+ /** \brief Get the index of the CPU kind that contains CPUs listed in \p cpuset.
86
+ *
87
+ * \p flags must be \c 0 for now.
88
+ *
89
+ * \return The index of the CPU kind (positive integer or 0) on success.
90
+ * \return \c -1 with \p errno set to \c EXDEV if \p cpuset is
91
+ * only partially included in the some kind.
92
+ * \return \c -1 with \p errno set to \c ENOENT if \p cpuset is
93
+ * not included in any kind, even partially.
94
+ * \return \c -1 with \p errno set to \c EINVAL if parameters are invalid.
95
+ */
96
+ HWLOC_DECLSPEC int
97
+ hwloc_cpukinds_get_by_cpuset(hwloc_topology_t topology,
98
+ hwloc_const_bitmap_t cpuset,
99
+ unsigned long flags);
100
+
101
+ /** \brief Get the CPU set and infos about a CPU kind in the topology.
102
+ *
103
+ * \p kind_index identifies one kind of CPU between 0 and the number
104
+ * of kinds returned by hwloc_cpukinds_get_nr() minus 1.
105
+ *
106
+ * If not \c NULL, the bitmap \p cpuset will be filled with
107
+ * the set of PUs of this kind.
108
+ *
109
+ * The integer pointed by \p efficiency, if not \c NULL will, be filled
110
+ * with the ranking of this kind of CPU in term of efficiency (see above).
111
+ * It ranges from \c 0 to the number of kinds
112
+ * (as reported by hwloc_cpukinds_get_nr()) minus 1.
113
+ *
114
+ * Kinds with lower efficiency are reported first.
115
+ *
116
+ * If there is a single kind in the topology, its efficiency \c 0.
117
+ * If the efficiency of some kinds of cores is unknown,
118
+ * the efficiency of all kinds is set to \c -1,
119
+ * and kinds are reported in no specific order.
120
+ *
121
+ * The array of info attributes (for instance the "CoreType",
122
+ * "FrequencyMaxMHz" or "FrequencyBaseMHz", see \ref topoattrs_cpukinds)
123
+ * and its length are returned in \p infos or \p nr_infos.
124
+ * The array belongs to the topology, it should not be freed or modified.
125
+ *
126
+ * If \p nr_infos or \p infos is \c NULL, no info is returned.
127
+ *
128
+ * \p flags must be \c 0 for now.
129
+ *
130
+ * \return \c 0 on success.
131
+ * \return \c -1 with \p errno set to \c ENOENT if \p kind_index does not match any CPU kind.
132
+ * \return \c -1 with \p errno set to \c EINVAL if parameters are invalid.
133
+ */
134
+ HWLOC_DECLSPEC int
135
+ hwloc_cpukinds_get_info(hwloc_topology_t topology,
136
+ unsigned kind_index,
137
+ hwloc_bitmap_t cpuset,
138
+ int *efficiency,
139
+ unsigned *nr_infos, struct hwloc_info_s **infos,
140
+ unsigned long flags);
141
+
142
+ /** \brief Register a kind of CPU in the topology.
143
+ *
144
+ * Mark the PUs listed in \p cpuset as being of the same kind
145
+ * with respect to the given attributes.
146
+ *
147
+ * \p forced_efficiency should be \c -1 if unknown.
148
+ * Otherwise it is an abstracted efficiency value to enforce
149
+ * the ranking of all kinds if all of them have valid (and
150
+ * different) efficiencies.
151
+ *
152
+ * The array \p infos of size \p nr_infos may be used to provide
153
+ * info names and values describing this kind of PUs.
154
+ *
155
+ * \p flags must be \c 0 for now.
156
+ *
157
+ * Parameters \p cpuset and \p infos will be duplicated internally,
158
+ * the caller is responsible for freeing them.
159
+ *
160
+ * If \p cpuset overlaps with some existing kinds, those might get
161
+ * modified or split. For instance if existing kind A contains
162
+ * PUs 0 and 1, and one registers another kind for PU 1 and 2,
163
+ * there will be 3 resulting kinds:
164
+ * existing kind A is restricted to only PU 0;
165
+ * new kind B contains only PU 1 and combines information from A
166
+ * and from the newly-registered kind;
167
+ * new kind C contains only PU 2 and only gets information from
168
+ * the newly-registered kind.
169
+ *
170
+ * \note The efficiency \p forced_efficiency provided to this function
171
+ * may be different from the one reported later by hwloc_cpukinds_get_info()
172
+ * because hwloc will scale efficiency values down to
173
+ * between 0 and the number of kinds minus 1.
174
+ *
175
+ * \return \c 0 on success.
176
+ * \return \c -1 with \p errno set to \c EINVAL if some parameters are invalid,
177
+ * for instance if \p cpuset is \c NULL or empty.
178
+ */
179
+ HWLOC_DECLSPEC int
180
+ hwloc_cpukinds_register(hwloc_topology_t topology,
181
+ hwloc_bitmap_t cpuset,
182
+ int forced_efficiency,
183
+ unsigned nr_infos, struct hwloc_info_s *infos,
184
+ unsigned long flags);
185
+
186
+ /** @} */
187
+
188
+ #ifdef __cplusplus
189
+ } /* extern "C" */
190
+ #endif
191
+
192
+
193
+ #endif /* HWLOC_CPUKINDS_H */
deps/exla/cache/xla_extension/include/include/hwloc/deprecated.h ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2009 CNRS
3
+ * Copyright © 2009-2021 Inria. All rights reserved.
4
+ * Copyright © 2009-2012 Université Bordeaux
5
+ * Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
6
+ * See COPYING in top-level directory.
7
+ */
8
+
9
+ /**
10
+ * This file contains the inline code of functions declared in hwloc.h
11
+ */
12
+
13
+ #ifndef HWLOC_DEPRECATED_H
14
+ #define HWLOC_DEPRECATED_H
15
+
16
+ #ifndef HWLOC_H
17
+ #error Please include the main hwloc.h instead
18
+ #endif
19
+
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #endif
23
+
24
+ /* backward compat with v2.0 before WHOLE_SYSTEM renaming */
25
+ #define HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED
26
+ /* backward compat with v1.11 before System removal */
27
+ #define HWLOC_OBJ_SYSTEM HWLOC_OBJ_MACHINE
28
+ /* backward compat with v1.10 before Socket->Package renaming */
29
+ #define HWLOC_OBJ_SOCKET HWLOC_OBJ_PACKAGE
30
+ /* backward compat with v1.10 before Node->NUMANode clarification */
31
+ #define HWLOC_OBJ_NODE HWLOC_OBJ_NUMANODE
32
+
33
+ /** \brief Add a distances structure.
34
+ *
35
+ * Superseded by hwloc_distances_add_create()+hwloc_distances_add_values()+hwloc_distances_add_commit()
36
+ * in v2.5.
37
+ */
38
+ HWLOC_DECLSPEC int hwloc_distances_add(hwloc_topology_t topology,
39
+ unsigned nbobjs, hwloc_obj_t *objs, hwloc_uint64_t *values,
40
+ unsigned long kind, unsigned long flags) __hwloc_attribute_deprecated;
41
+
42
+ /** \brief Insert a misc object by parent.
43
+ *
44
+ * Identical to hwloc_topology_insert_misc_object().
45
+ */
46
+ static __hwloc_inline hwloc_obj_t
47
+ hwloc_topology_insert_misc_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, const char *name) __hwloc_attribute_deprecated;
48
+ static __hwloc_inline hwloc_obj_t
49
+ hwloc_topology_insert_misc_object_by_parent(hwloc_topology_t topology, hwloc_obj_t parent, const char *name)
50
+ {
51
+ return hwloc_topology_insert_misc_object(topology, parent, name);
52
+ }
53
+
54
+ /** \brief Stringify the cpuset containing a set of objects.
55
+ *
56
+ * If \p size is 0, \p string may safely be \c NULL.
57
+ *
58
+ * \return the number of character that were actually written if not truncating,
59
+ * or that would have been written (not including the ending \\0).
60
+ */
61
+ static __hwloc_inline int
62
+ hwloc_obj_cpuset_snprintf(char *str, size_t size, size_t nobj, struct hwloc_obj * const *objs) __hwloc_attribute_deprecated;
63
+ static __hwloc_inline int
64
+ hwloc_obj_cpuset_snprintf(char *str, size_t size, size_t nobj, struct hwloc_obj * const *objs)
65
+ {
66
+ hwloc_bitmap_t set = hwloc_bitmap_alloc();
67
+ int res;
68
+ unsigned i;
69
+
70
+ hwloc_bitmap_zero(set);
71
+ for(i=0; i<nobj; i++)
72
+ if (objs[i]->cpuset)
73
+ hwloc_bitmap_or(set, set, objs[i]->cpuset);
74
+
75
+ res = hwloc_bitmap_snprintf(str, size, set);
76
+ hwloc_bitmap_free(set);
77
+ return res;
78
+ }
79
+
80
+ /** \brief Convert a type string into a type and some attributes.
81
+ *
82
+ * Deprecated by hwloc_type_sscanf()
83
+ */
84
+ static __hwloc_inline int
85
+ hwloc_obj_type_sscanf(const char *string, hwloc_obj_type_t *typep, int *depthattrp, void *typeattrp, size_t typeattrsize) __hwloc_attribute_deprecated;
86
+ static __hwloc_inline int
87
+ hwloc_obj_type_sscanf(const char *string, hwloc_obj_type_t *typep, int *depthattrp, void *typeattrp, size_t typeattrsize)
88
+ {
89
+ union hwloc_obj_attr_u attr;
90
+ int err = hwloc_type_sscanf(string, typep, &attr, sizeof(attr));
91
+ if (err < 0)
92
+ return err;
93
+ if (hwloc_obj_type_is_cache(*typep)) {
94
+ if (depthattrp)
95
+ *depthattrp = (int) attr.cache.depth;
96
+ if (typeattrp && typeattrsize >= sizeof(hwloc_obj_cache_type_t))
97
+ memcpy(typeattrp, &attr.cache.type, sizeof(hwloc_obj_cache_type_t));
98
+ } else if (*typep == HWLOC_OBJ_GROUP) {
99
+ if (depthattrp)
100
+ *depthattrp = (int) attr.group.depth;
101
+ }
102
+ return 0;
103
+ }
104
+
105
+ /** \brief Set the default memory binding policy of the current
106
+ * process or thread to prefer the NUMA node(s) specified by physical \p nodeset
107
+ */
108
+ static __hwloc_inline int
109
+ hwloc_set_membind_nodeset(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_deprecated;
110
+ static __hwloc_inline int
111
+ hwloc_set_membind_nodeset(hwloc_topology_t topology, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags)
112
+ {
113
+ return hwloc_set_membind(topology, nodeset, policy, flags | HWLOC_MEMBIND_BYNODESET);
114
+ }
115
+
116
+ /** \brief Query the default memory binding policy and physical locality of the
117
+ * current process or thread.
118
+ */
119
+ static __hwloc_inline int
120
+ hwloc_get_membind_nodeset(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags) __hwloc_attribute_deprecated;
121
+ static __hwloc_inline int
122
+ hwloc_get_membind_nodeset(hwloc_topology_t topology, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags)
123
+ {
124
+ return hwloc_get_membind(topology, nodeset, policy, flags | HWLOC_MEMBIND_BYNODESET);
125
+ }
126
+
127
+ /** \brief Set the default memory binding policy of the specified
128
+ * process to prefer the NUMA node(s) specified by physical \p nodeset
129
+ */
130
+ static __hwloc_inline int
131
+ hwloc_set_proc_membind_nodeset(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_deprecated;
132
+ static __hwloc_inline int
133
+ hwloc_set_proc_membind_nodeset(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags)
134
+ {
135
+ return hwloc_set_proc_membind(topology, pid, nodeset, policy, flags | HWLOC_MEMBIND_BYNODESET);
136
+ }
137
+
138
+ /** \brief Query the default memory binding policy and physical locality of the
139
+ * specified process.
140
+ */
141
+ static __hwloc_inline int
142
+ hwloc_get_proc_membind_nodeset(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags) __hwloc_attribute_deprecated;
143
+ static __hwloc_inline int
144
+ hwloc_get_proc_membind_nodeset(hwloc_topology_t topology, hwloc_pid_t pid, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags)
145
+ {
146
+ return hwloc_get_proc_membind(topology, pid, nodeset, policy, flags | HWLOC_MEMBIND_BYNODESET);
147
+ }
148
+
149
+ /** \brief Bind the already-allocated memory identified by (addr, len)
150
+ * to the NUMA node(s) in physical \p nodeset.
151
+ */
152
+ static __hwloc_inline int
153
+ hwloc_set_area_membind_nodeset(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_deprecated;
154
+ static __hwloc_inline int
155
+ hwloc_set_area_membind_nodeset(hwloc_topology_t topology, const void *addr, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags)
156
+ {
157
+ return hwloc_set_area_membind(topology, addr, len, nodeset, policy, flags | HWLOC_MEMBIND_BYNODESET);
158
+ }
159
+
160
+ /** \brief Query the physical NUMA node(s) and binding policy of the memory
161
+ * identified by (\p addr, \p len ).
162
+ */
163
+ static __hwloc_inline int
164
+ hwloc_get_area_membind_nodeset(hwloc_topology_t topology, const void *addr, size_t len, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags) __hwloc_attribute_deprecated;
165
+ static __hwloc_inline int
166
+ hwloc_get_area_membind_nodeset(hwloc_topology_t topology, const void *addr, size_t len, hwloc_nodeset_t nodeset, hwloc_membind_policy_t * policy, int flags)
167
+ {
168
+ return hwloc_get_area_membind(topology, addr, len, nodeset, policy, flags | HWLOC_MEMBIND_BYNODESET);
169
+ }
170
+
171
+ /** \brief Allocate some memory on the given physical nodeset \p nodeset
172
+ */
173
+ static __hwloc_inline void *
174
+ hwloc_alloc_membind_nodeset(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_malloc __hwloc_attribute_deprecated;
175
+ static __hwloc_inline void *
176
+ hwloc_alloc_membind_nodeset(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags)
177
+ {
178
+ return hwloc_alloc_membind(topology, len, nodeset, policy, flags | HWLOC_MEMBIND_BYNODESET);
179
+ }
180
+
181
+ /** \brief Allocate some memory on the given nodeset \p nodeset.
182
+ */
183
+ static __hwloc_inline void *
184
+ hwloc_alloc_membind_policy_nodeset(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags) __hwloc_attribute_malloc __hwloc_attribute_deprecated;
185
+ static __hwloc_inline void *
186
+ hwloc_alloc_membind_policy_nodeset(hwloc_topology_t topology, size_t len, hwloc_const_nodeset_t nodeset, hwloc_membind_policy_t policy, int flags)
187
+ {
188
+ return hwloc_alloc_membind_policy(topology, len, nodeset, policy, flags | HWLOC_MEMBIND_BYNODESET);
189
+ }
190
+
191
+ /** \brief Convert a CPU set into a NUMA node set and handle non-NUMA cases
192
+ */
193
+ static __hwloc_inline void
194
+ hwloc_cpuset_to_nodeset_strict(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset) __hwloc_attribute_deprecated;
195
+ static __hwloc_inline void
196
+ hwloc_cpuset_to_nodeset_strict(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset)
197
+ {
198
+ hwloc_cpuset_to_nodeset(topology, _cpuset, nodeset);
199
+ }
200
+
201
+ /** \brief Convert a NUMA node set into a CPU set and handle non-NUMA cases
202
+ */
203
+ static __hwloc_inline void
204
+ hwloc_cpuset_from_nodeset_strict(hwloc_topology_t topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset) __hwloc_attribute_deprecated;
205
+ static __hwloc_inline void
206
+ hwloc_cpuset_from_nodeset_strict(hwloc_topology_t topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset)
207
+ {
208
+ hwloc_cpuset_from_nodeset(topology, _cpuset, nodeset);
209
+ }
210
+
211
+
212
+ #ifdef __cplusplus
213
+ } /* extern "C" */
214
+ #endif
215
+
216
+
217
+ #endif /* HWLOC_DEPRECATED_H */
deps/exla/cache/xla_extension/include/include/hwloc/diff.h ADDED
@@ -0,0 +1,289 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2013-2020 Inria. All rights reserved.
3
+ * See COPYING in top-level directory.
4
+ */
5
+
6
+ /** \file
7
+ * \brief Topology differences.
8
+ */
9
+
10
+ #ifndef HWLOC_DIFF_H
11
+ #define HWLOC_DIFF_H
12
+
13
+ #ifndef HWLOC_H
14
+ #error Please include the main hwloc.h instead
15
+ #endif
16
+
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #elif 0
21
+ }
22
+ #endif
23
+
24
+
25
+ /** \defgroup hwlocality_diff Topology differences
26
+ *
27
+ * Applications that manipulate many similar topologies, for instance
28
+ * one for each node of a homogeneous cluster, may want to compress
29
+ * topologies to reduce the memory footprint.
30
+ *
31
+ * This file offers a way to manipulate the difference between topologies
32
+ * and export/import it to/from XML.
33
+ * Compression may therefore be achieved by storing one topology
34
+ * entirely while the others are only described by their differences
35
+ * with the former.
36
+ * The actual topology can be reconstructed when actually needed by
37
+ * applying the precomputed difference to the reference topology.
38
+ *
39
+ * This interface targets very similar nodes.
40
+ * Only very simple differences between topologies are actually
41
+ * supported, for instance a change in the memory size, the name
42
+ * of the object, or some info attribute.
43
+ * More complex differences such as adding or removing objects cannot
44
+ * be represented in the difference structures and therefore return
45
+ * errors.
46
+ * Differences between object sets or topology-wide allowed sets,
47
+ * cannot be represented either.
48
+ *
49
+ * It means that there is no need to apply the difference when
50
+ * looking at the tree organization (how many levels, how many
51
+ * objects per level, what kind of objects, CPU and node sets, etc)
52
+ * and when binding to objects.
53
+ * However the difference must be applied when looking at object
54
+ * attributes such as the name, the memory size or info attributes.
55
+ *
56
+ * @{
57
+ */
58
+
59
+
60
+ /** \brief Type of one object attribute difference.
61
+ */
62
+ typedef enum hwloc_topology_diff_obj_attr_type_e {
63
+ /** \brief The object local memory is modified.
64
+ * The union is a hwloc_topology_diff_obj_attr_u::hwloc_topology_diff_obj_attr_uint64_s
65
+ * (and the index field is ignored).
66
+ */
67
+ HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_SIZE,
68
+
69
+ /** \brief The object name is modified.
70
+ * The union is a hwloc_topology_diff_obj_attr_u::hwloc_topology_diff_obj_attr_string_s
71
+ * (and the name field is ignored).
72
+ */
73
+
74
+ HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_NAME,
75
+ /** \brief the value of an info attribute is modified.
76
+ * The union is a hwloc_topology_diff_obj_attr_u::hwloc_topology_diff_obj_attr_string_s.
77
+ */
78
+ HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_INFO
79
+ } hwloc_topology_diff_obj_attr_type_t;
80
+
81
+ /** \brief One object attribute difference.
82
+ */
83
+ union hwloc_topology_diff_obj_attr_u {
84
+ struct hwloc_topology_diff_obj_attr_generic_s {
85
+ /* each part of the union must start with these */
86
+ hwloc_topology_diff_obj_attr_type_t type;
87
+ } generic;
88
+
89
+ /** \brief Integer attribute modification with an optional index. */
90
+ struct hwloc_topology_diff_obj_attr_uint64_s {
91
+ /* used for storing integer attributes */
92
+ hwloc_topology_diff_obj_attr_type_t type;
93
+ hwloc_uint64_t index; /* not used for SIZE */
94
+ hwloc_uint64_t oldvalue;
95
+ hwloc_uint64_t newvalue;
96
+ } uint64;
97
+
98
+ /** \brief String attribute modification with an optional name */
99
+ struct hwloc_topology_diff_obj_attr_string_s {
100
+ /* used for storing name and info pairs */
101
+ hwloc_topology_diff_obj_attr_type_t type;
102
+ char *name; /* not used for NAME */
103
+ char *oldvalue;
104
+ char *newvalue;
105
+ } string;
106
+ };
107
+
108
+
109
+ /** \brief Type of one element of a difference list.
110
+ */
111
+ typedef enum hwloc_topology_diff_type_e {
112
+ /** \brief An object attribute was changed.
113
+ * The union is a hwloc_topology_diff_u::hwloc_topology_diff_obj_attr_s.
114
+ */
115
+ HWLOC_TOPOLOGY_DIFF_OBJ_ATTR,
116
+
117
+ /** \brief The difference is too complex,
118
+ * it cannot be represented. The difference below
119
+ * this object has not been checked.
120
+ * hwloc_topology_diff_build() will return 1.
121
+ *
122
+ * The union is a hwloc_topology_diff_u::hwloc_topology_diff_too_complex_s.
123
+ */
124
+ HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX
125
+ } hwloc_topology_diff_type_t;
126
+
127
+ /** \brief One element of a difference list between two topologies.
128
+ */
129
+ typedef union hwloc_topology_diff_u {
130
+ struct hwloc_topology_diff_generic_s {
131
+ /* each part of the union must start with these */
132
+ hwloc_topology_diff_type_t type;
133
+ union hwloc_topology_diff_u * next; /* pointer to the next element of the list, or NULL */
134
+ } generic;
135
+
136
+ /* A difference in an object attribute. */
137
+ struct hwloc_topology_diff_obj_attr_s {
138
+ hwloc_topology_diff_type_t type; /* must be ::HWLOC_TOPOLOGY_DIFF_OBJ_ATTR */
139
+ union hwloc_topology_diff_u * next;
140
+ /* List of attribute differences for a single object */
141
+ int obj_depth;
142
+ unsigned obj_index;
143
+ union hwloc_topology_diff_obj_attr_u diff;
144
+ } obj_attr;
145
+
146
+ /* A difference that is too complex. */
147
+ struct hwloc_topology_diff_too_complex_s {
148
+ hwloc_topology_diff_type_t type; /* must be ::HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX */
149
+ union hwloc_topology_diff_u * next;
150
+ /* Where we had to stop computing the diff in the first topology */
151
+ int obj_depth;
152
+ unsigned obj_index;
153
+ } too_complex;
154
+ } * hwloc_topology_diff_t;
155
+
156
+
157
+ /** \brief Compute the difference between 2 topologies.
158
+ *
159
+ * The difference is stored as a list of ::hwloc_topology_diff_t entries
160
+ * starting at \p diff.
161
+ * It is computed by doing a depth-first traversal of both topology trees
162
+ * simultaneously.
163
+ *
164
+ * If the difference between 2 objects is too complex to be represented
165
+ * (for instance if some objects have different types, or different numbers
166
+ * of children), a special diff entry of type ::HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX
167
+ * is queued.
168
+ * The computation of the diff does not continue below these objects.
169
+ * So each such diff entry means that the difference between two subtrees
170
+ * could not be computed.
171
+ *
172
+ * \return 0 if the difference can be represented properly.
173
+ *
174
+ * \return 0 with \p diff pointing to NULL if there is no difference
175
+ * between the topologies.
176
+ *
177
+ * \return 1 if the difference is too complex (see above). Some entries in
178
+ * the list will be of type ::HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX.
179
+ *
180
+ * \return -1 on any other error.
181
+ *
182
+ * \note \p flags is currently not used. It should be 0.
183
+ *
184
+ * \note The output diff has to be freed with hwloc_topology_diff_destroy().
185
+ *
186
+ * \note The output diff can only be exported to XML or passed to
187
+ * hwloc_topology_diff_apply() if 0 was returned, i.e. if no entry of type
188
+ * ::HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX is listed.
189
+ *
190
+ * \note The output diff may be modified by removing some entries from
191
+ * the list. The removed entries should be freed by passing them to
192
+ * to hwloc_topology_diff_destroy() (possible as another list).
193
+ */
194
+ HWLOC_DECLSPEC int hwloc_topology_diff_build(hwloc_topology_t topology, hwloc_topology_t newtopology, unsigned long flags, hwloc_topology_diff_t *diff);
195
+
196
+ /** \brief Flags to be given to hwloc_topology_diff_apply().
197
+ */
198
+ enum hwloc_topology_diff_apply_flags_e {
199
+ /** \brief Apply topology diff in reverse direction.
200
+ * \hideinitializer
201
+ */
202
+ HWLOC_TOPOLOGY_DIFF_APPLY_REVERSE = (1UL<<0)
203
+ };
204
+
205
+ /** \brief Apply a topology diff to an existing topology.
206
+ *
207
+ * \p flags is an OR'ed set of ::hwloc_topology_diff_apply_flags_e.
208
+ *
209
+ * The new topology is modified in place. hwloc_topology_dup()
210
+ * may be used to duplicate it before patching.
211
+ *
212
+ * If the difference cannot be applied entirely, all previous applied
213
+ * elements are unapplied before returning.
214
+ *
215
+ * \return 0 on success.
216
+ *
217
+ * \return -N if applying the difference failed while trying
218
+ * to apply the N-th part of the difference. For instance -1
219
+ * is returned if the very first difference element could not
220
+ * be applied.
221
+ */
222
+ HWLOC_DECLSPEC int hwloc_topology_diff_apply(hwloc_topology_t topology, hwloc_topology_diff_t diff, unsigned long flags);
223
+
224
+ /** \brief Destroy a list of topology differences.
225
+ */
226
+ HWLOC_DECLSPEC int hwloc_topology_diff_destroy(hwloc_topology_diff_t diff);
227
+
228
+ /** \brief Load a list of topology differences from a XML file.
229
+ *
230
+ * If not \c NULL, \p refname will be filled with the identifier
231
+ * string of the reference topology for the difference file,
232
+ * if any was specified in the XML file.
233
+ * This identifier is usually the name of the other XML file
234
+ * that contains the reference topology.
235
+ *
236
+ * \note the pointer returned in refname should later be freed
237
+ * by the caller.
238
+ */
239
+ HWLOC_DECLSPEC int hwloc_topology_diff_load_xml(const char *xmlpath, hwloc_topology_diff_t *diff, char **refname);
240
+
241
+ /** \brief Export a list of topology differences to a XML file.
242
+ *
243
+ * If not \c NULL, \p refname defines an identifier string
244
+ * for the reference topology which was used as a base when
245
+ * computing this difference.
246
+ * This identifier is usually the name of the other XML file
247
+ * that contains the reference topology.
248
+ * This attribute is given back when reading the diff from XML.
249
+ */
250
+ HWLOC_DECLSPEC int hwloc_topology_diff_export_xml(hwloc_topology_diff_t diff, const char *refname, const char *xmlpath);
251
+
252
+ /** \brief Load a list of topology differences from a XML buffer.
253
+ *
254
+ * If not \c NULL, \p refname will be filled with the identifier
255
+ * string of the reference topology for the difference file,
256
+ * if any was specified in the XML file.
257
+ * This identifier is usually the name of the other XML file
258
+ * that contains the reference topology.
259
+ *
260
+ * \note the pointer returned in refname should later be freed
261
+ * by the caller.
262
+ */
263
+ HWLOC_DECLSPEC int hwloc_topology_diff_load_xmlbuffer(const char *xmlbuffer, int buflen, hwloc_topology_diff_t *diff, char **refname);
264
+
265
+ /** \brief Export a list of topology differences to a XML buffer.
266
+ *
267
+ * If not \c NULL, \p refname defines an identifier string
268
+ * for the reference topology which was used as a base when
269
+ * computing this difference.
270
+ * This identifier is usually the name of the other XML file
271
+ * that contains the reference topology.
272
+ * This attribute is given back when reading the diff from XML.
273
+ *
274
+ * The returned buffer ends with a \0 that is included in the returned
275
+ * length.
276
+ *
277
+ * \note The XML buffer should later be freed with hwloc_free_xmlbuffer().
278
+ */
279
+ HWLOC_DECLSPEC int hwloc_topology_diff_export_xmlbuffer(hwloc_topology_diff_t diff, const char *refname, char **xmlbuffer, int *buflen);
280
+
281
+ /** @} */
282
+
283
+
284
+ #ifdef __cplusplus
285
+ } /* extern "C" */
286
+ #endif
287
+
288
+
289
+ #endif /* HWLOC_DIFF_H */
deps/exla/cache/xla_extension/include/include/hwloc/distances.h ADDED
@@ -0,0 +1,471 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2010-2021 Inria. All rights reserved.
3
+ * See COPYING in top-level directory.
4
+ */
5
+
6
+ /** \file
7
+ * \brief Object distances.
8
+ */
9
+
10
+ #ifndef HWLOC_DISTANCES_H
11
+ #define HWLOC_DISTANCES_H
12
+
13
+ #ifndef HWLOC_H
14
+ #error Please include the main hwloc.h instead
15
+ #endif
16
+
17
+
18
+ #ifdef __cplusplus
19
+ extern "C" {
20
+ #elif 0
21
+ }
22
+ #endif
23
+
24
+
25
+ /** \defgroup hwlocality_distances_get Retrieve distances between objects
26
+ * @{
27
+ */
28
+
29
+ /** \brief Matrix of distances between a set of objects.
30
+ *
31
+ * This matrix often contains latencies between NUMA nodes
32
+ * (as reported in the System Locality Distance Information Table (SLIT)
33
+ * in the ACPI specification), which may or may not be physically accurate.
34
+ * It corresponds to the latency for accessing the memory of one node
35
+ * from a core in another node.
36
+ * The corresponding kind is ::HWLOC_DISTANCES_KIND_FROM_OS | ::HWLOC_DISTANCES_KIND_FROM_USER.
37
+ * The name of this distances structure is "NUMALatency".
38
+ * Others distance structures include and "XGMIBandwidth", "XGMIHops"
39
+ * and "NVLinkBandwidth".
40
+ *
41
+ * The matrix may also contain bandwidths between random sets of objects,
42
+ * possibly provided by the user, as specified in the \p kind attribute.
43
+ *
44
+ * Pointers \p objs and \p values should not be replaced, reallocated, freed, etc.
45
+ * However callers are allowed to modify \p kind as well as the contents
46
+ * of \p objs and \p values arrays.
47
+ * For instance, if there is a single NUMA node per Package,
48
+ * hwloc_get_obj_with_same_locality() may be used to convert between them
49
+ * and replace NUMA nodes in the \p objs array with the corresponding Packages.
50
+ * See also hwloc_distances_transform() for applying some transformations
51
+ * to the structure.
52
+ */
53
+ struct hwloc_distances_s {
54
+ unsigned nbobjs; /**< \brief Number of objects described by the distance matrix. */
55
+ hwloc_obj_t *objs; /**< \brief Array of objects described by the distance matrix.
56
+ * These objects are not in any particular order,
57
+ * see hwloc_distances_obj_index() and hwloc_distances_obj_pair_values()
58
+ * for easy ways to find objects in this array and their corresponding values.
59
+ */
60
+ unsigned long kind; /**< \brief OR'ed set of ::hwloc_distances_kind_e. */
61
+ hwloc_uint64_t *values; /**< \brief Matrix of distances between objects, stored as a one-dimension array.
62
+ *
63
+ * Distance from i-th to j-th object is stored in slot i*nbobjs+j.
64
+ * The meaning of the value depends on the \p kind attribute.
65
+ */
66
+ };
67
+
68
+ /** \brief Kinds of distance matrices.
69
+ *
70
+ * The \p kind attribute of struct hwloc_distances_s is a OR'ed set
71
+ * of kinds.
72
+ *
73
+ * A kind of format HWLOC_DISTANCES_KIND_FROM_* specifies where the
74
+ * distance information comes from, if known.
75
+ *
76
+ * A kind of format HWLOC_DISTANCES_KIND_MEANS_* specifies whether
77
+ * values are latencies or bandwidths, if applicable.
78
+ */
79
+ enum hwloc_distances_kind_e {
80
+ /** \brief These distances were obtained from the operating system or hardware.
81
+ * \hideinitializer
82
+ */
83
+ HWLOC_DISTANCES_KIND_FROM_OS = (1UL<<0),
84
+ /** \brief These distances were provided by the user.
85
+ * \hideinitializer
86
+ */
87
+ HWLOC_DISTANCES_KIND_FROM_USER = (1UL<<1),
88
+
89
+ /** \brief Distance values are similar to latencies between objects.
90
+ * Values are smaller for closer objects, hence minimal on the diagonal
91
+ * of the matrix (distance between an object and itself).
92
+ * It could also be the number of network hops between objects, etc.
93
+ * \hideinitializer
94
+ */
95
+ HWLOC_DISTANCES_KIND_MEANS_LATENCY = (1UL<<2),
96
+ /** \brief Distance values are similar to bandwidths between objects.
97
+ * Values are higher for closer objects, hence maximal on the diagonal
98
+ * of the matrix (distance between an object and itself).
99
+ * Such values are currently ignored for distance-based grouping.
100
+ * \hideinitializer
101
+ */
102
+ HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH = (1UL<<3),
103
+
104
+ /** \brief This distances structure covers objects of different types.
105
+ * This may apply to the "NVLinkBandwidth" structure in presence
106
+ * of a NVSwitch or POWER processor NVLink port.
107
+ * \hideinitializer
108
+ */
109
+ HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES = (1UL<<4)
110
+ };
111
+
112
+ /** \brief Retrieve distance matrices.
113
+ *
114
+ * Retrieve distance matrices from the topology into the \p distances array.
115
+ *
116
+ * \p flags is currently unused, should be \c 0.
117
+ *
118
+ * \p kind serves as a filter. If \c 0, all distance matrices are returned.
119
+ * If it contains some HWLOC_DISTANCES_KIND_FROM_*, only distance matrices
120
+ * whose kind matches one of these are returned.
121
+ * If it contains some HWLOC_DISTANCES_KIND_MEANS_*, only distance matrices
122
+ * whose kind matches one of these are returned.
123
+ *
124
+ * On input, \p nr points to the number of distance matrices that may be stored
125
+ * in \p distances.
126
+ * On output, \p nr points to the number of distance matrices that were actually
127
+ * found, even if some of them couldn't be stored in \p distances.
128
+ * Distance matrices that couldn't be stored are ignored, but the function still
129
+ * returns success (\c 0). The caller may find out by comparing the value pointed
130
+ * by \p nr before and after the function call.
131
+ *
132
+ * Each distance matrix returned in the \p distances array should be released
133
+ * by the caller using hwloc_distances_release().
134
+ */
135
+ HWLOC_DECLSPEC int
136
+ hwloc_distances_get(hwloc_topology_t topology,
137
+ unsigned *nr, struct hwloc_distances_s **distances,
138
+ unsigned long kind, unsigned long flags);
139
+
140
+ /** \brief Retrieve distance matrices for object at a specific depth in the topology.
141
+ *
142
+ * Identical to hwloc_distances_get() with the additional \p depth filter.
143
+ */
144
+ HWLOC_DECLSPEC int
145
+ hwloc_distances_get_by_depth(hwloc_topology_t topology, int depth,
146
+ unsigned *nr, struct hwloc_distances_s **distances,
147
+ unsigned long kind, unsigned long flags);
148
+
149
+ /** \brief Retrieve distance matrices for object of a specific type.
150
+ *
151
+ * Identical to hwloc_distances_get() with the additional \p type filter.
152
+ */
153
+ HWLOC_DECLSPEC int
154
+ hwloc_distances_get_by_type(hwloc_topology_t topology, hwloc_obj_type_t type,
155
+ unsigned *nr, struct hwloc_distances_s **distances,
156
+ unsigned long kind, unsigned long flags);
157
+
158
+ /** \brief Retrieve a distance matrix with the given name.
159
+ *
160
+ * Usually only one distances structure may match a given name.
161
+ *
162
+ * The name of the most common structure is "NUMALatency".
163
+ * Others include "XGMIBandwidth", "XGMIHops" and "NVLinkBandwidth".
164
+ */
165
+ HWLOC_DECLSPEC int
166
+ hwloc_distances_get_by_name(hwloc_topology_t topology, const char *name,
167
+ unsigned *nr, struct hwloc_distances_s **distances,
168
+ unsigned long flags);
169
+
170
+ /** \brief Get a description of what a distances structure contains.
171
+ *
172
+ * For instance "NUMALatency" for hardware-provided NUMA distances (ACPI SLIT),
173
+ * or NULL if unknown.
174
+ */
175
+ HWLOC_DECLSPEC const char *
176
+ hwloc_distances_get_name(hwloc_topology_t topology, struct hwloc_distances_s *distances);
177
+
178
+ /** \brief Release a distance matrix structure previously returned by hwloc_distances_get().
179
+ *
180
+ * \note This function is not required if the structure is removed with hwloc_distances_release_remove().
181
+ */
182
+ HWLOC_DECLSPEC void
183
+ hwloc_distances_release(hwloc_topology_t topology, struct hwloc_distances_s *distances);
184
+
185
+ /** \brief Transformations of distances structures. */
186
+ enum hwloc_distances_transform_e {
187
+ /** \brief Remove \c NULL objects from the distances structure.
188
+ *
189
+ * Every object that was replaced with \c NULL in the \p objs array
190
+ * is removed and the \p values array is updated accordingly.
191
+ *
192
+ * At least \c 2 objects must remain, otherwise hwloc_distances_transform()
193
+ * will return \c -1 with \p errno set to \c EINVAL.
194
+ *
195
+ * \p kind will be updated with or without ::HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES
196
+ * according to the remaining objects.
197
+ *
198
+ * \hideinitializer
199
+ */
200
+ HWLOC_DISTANCES_TRANSFORM_REMOVE_NULL = 0,
201
+
202
+ /** \brief Replace bandwidth values with a number of links.
203
+ *
204
+ * Usually all values will be either \c 0 (no link) or \c 1 (one link).
205
+ * However some matrices could get larger values if some pairs of
206
+ * peers are connected by different numbers of links.
207
+ *
208
+ * Values on the diagonal are set to \c 0.
209
+ *
210
+ * This transformation only applies to bandwidth matrices.
211
+ *
212
+ * \hideinitializer
213
+ */
214
+ HWLOC_DISTANCES_TRANSFORM_LINKS = 1,
215
+
216
+ /** \brief Merge switches with multiple ports into a single object.
217
+ * This currently only applies to NVSwitches where GPUs seem connected to different
218
+ * separate switch ports in the NVLinkBandwidth matrix. This transformation will
219
+ * replace all of them with the same port connected to all GPUs.
220
+ * Other ports are removed by applying ::HWLOC_DISTANCES_TRANSFORM_REMOVE_NULL internally.
221
+ * \hideinitializer
222
+ */
223
+ HWLOC_DISTANCES_TRANSFORM_MERGE_SWITCH_PORTS = 2,
224
+
225
+ /** \brief Apply a transitive closure to the matrix to connect objects across switches.
226
+ * This currently only applies to GPUs and NVSwitches in the NVLinkBandwidth matrix.
227
+ * All pairs of GPUs will be reported as directly connected.
228
+ * \hideinitializer
229
+ */
230
+ HWLOC_DISTANCES_TRANSFORM_TRANSITIVE_CLOSURE = 3
231
+ };
232
+
233
+ /** \brief Apply a transformation to a distances structure.
234
+ *
235
+ * Modify a distances structure that was previously obtained with
236
+ * hwloc_distances_get() or one of its variants.
237
+ *
238
+ * This modifies the local copy of the distances structures but does
239
+ * not modify the distances information stored inside the topology
240
+ * (retrieved by another call to hwloc_distances_get() or exported to XML).
241
+ * To do so, one should add a new distances structure with same
242
+ * name, kind, objects and values (see \ref hwlocality_distances_add)
243
+ * and then remove this old one with hwloc_distances_release_remove().
244
+ *
245
+ * \p transform must be one of the transformations listed
246
+ * in ::hwloc_distances_transform_e.
247
+ *
248
+ * These transformations may modify the contents of the \p objs or \p values arrays.
249
+ *
250
+ * \p transform_attr must be \c NULL for now.
251
+ *
252
+ * \p flags must be \c 0 for now.
253
+ *
254
+ * \note Objects in distances array \p objs may be directly modified
255
+ * in place without using hwloc_distances_transform().
256
+ * One may use hwloc_get_obj_with_same_locality() to easily convert
257
+ * between similar objects of different types.
258
+ */
259
+ HWLOC_DECLSPEC int hwloc_distances_transform(hwloc_topology_t topology, struct hwloc_distances_s *distances,
260
+ enum hwloc_distances_transform_e transform,
261
+ void *transform_attr,
262
+ unsigned long flags);
263
+
264
+ /** @} */
265
+
266
+
267
+
268
+ /** \defgroup hwlocality_distances_consult Helpers for consulting distance matrices
269
+ * @{
270
+ */
271
+
272
+ /** \brief Find the index of an object in a distances structure.
273
+ *
274
+ * \return -1 if object \p obj is not involved in structure \p distances.
275
+ */
276
+ static __hwloc_inline int
277
+ hwloc_distances_obj_index(struct hwloc_distances_s *distances, hwloc_obj_t obj)
278
+ {
279
+ unsigned i;
280
+ for(i=0; i<distances->nbobjs; i++)
281
+ if (distances->objs[i] == obj)
282
+ return (int)i;
283
+ return -1;
284
+ }
285
+
286
+ /** \brief Find the values between two objects in a distance matrices.
287
+ *
288
+ * The distance from \p obj1 to \p obj2 is stored in the value pointed by
289
+ * \p value1to2 and reciprocally.
290
+ *
291
+ * \return -1 if object \p obj1 or \p obj2 is not involved in structure \p distances.
292
+ */
293
+ static __hwloc_inline int
294
+ hwloc_distances_obj_pair_values(struct hwloc_distances_s *distances,
295
+ hwloc_obj_t obj1, hwloc_obj_t obj2,
296
+ hwloc_uint64_t *value1to2, hwloc_uint64_t *value2to1)
297
+ {
298
+ int i1 = hwloc_distances_obj_index(distances, obj1);
299
+ int i2 = hwloc_distances_obj_index(distances, obj2);
300
+ if (i1 < 0 || i2 < 0)
301
+ return -1;
302
+ *value1to2 = distances->values[i1 * distances->nbobjs + i2];
303
+ *value2to1 = distances->values[i2 * distances->nbobjs + i1];
304
+ return 0;
305
+ }
306
+
307
+ /** @} */
308
+
309
+
310
+
311
+ /** \defgroup hwlocality_distances_add Add distances between objects
312
+ *
313
+ * The usual way to add distances is:
314
+ * \code
315
+ * hwloc_distances_add_handle_t handle;
316
+ * int err = -1;
317
+ * handle = hwloc_distances_add_create(topology, "name", kind, 0);
318
+ * if (handle) {
319
+ * err = hwloc_distances_add_values(topology, handle, nbobjs, objs, values, 0);
320
+ * if (!err)
321
+ * err = hwloc_distances_add_commit(topology, handle, flags);
322
+ * }
323
+ * \endcode
324
+ * If \p err is \c 0 at the end, then addition was successful.
325
+ *
326
+ * @{
327
+ */
328
+
329
+ /** \brief Handle to a new distances structure during its addition to the topology. */
330
+ typedef void * hwloc_distances_add_handle_t;
331
+
332
+ /** \brief Create a new empty distances structure.
333
+ *
334
+ * Create an empty distances structure
335
+ * to be filled with hwloc_distances_add_values()
336
+ * and then committed with hwloc_distances_add_commit().
337
+ *
338
+ * Parameter \p name is optional, it may be \c NULL.
339
+ * Otherwise, it will be copied internally and may later be freed by the caller.
340
+ *
341
+ * \p kind specifies the kind of distance as a OR'ed set of ::hwloc_distances_kind_e.
342
+ * Kind ::HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES will be automatically set
343
+ * according to objects having different types in hwloc_distances_add_values().
344
+ *
345
+ * \p flags must be \c 0 for now.
346
+ *
347
+ * \return A hwloc_distances_add_handle_t that should then be passed
348
+ * to hwloc_distances_add_values() and hwloc_distances_add_commit().
349
+ *
350
+ * \return \c NULL on error.
351
+ */
352
+ HWLOC_DECLSPEC hwloc_distances_add_handle_t
353
+ hwloc_distances_add_create(hwloc_topology_t topology,
354
+ const char *name, unsigned long kind,
355
+ unsigned long flags);
356
+
357
+ /** \brief Specify the objects and values in a new empty distances structure.
358
+ *
359
+ * Specify the objects and values for a new distances structure
360
+ * that was returned as a handle by hwloc_distances_add_create().
361
+ * The structure must then be committed with hwloc_distances_add_commit().
362
+ *
363
+ * The number of objects is \p nbobjs and the array of objects is \p objs.
364
+ * Distance values are stored as a one-dimension array in \p values.
365
+ * The distance from object i to object j is in slot i*nbobjs+j.
366
+ *
367
+ * \p nbobjs must be at least 2.
368
+ *
369
+ * Arrays \p objs and \p values will be copied internally,
370
+ * they may later be freed by the caller.
371
+ *
372
+ * On error, the temporary distances structure and its content are destroyed.
373
+ *
374
+ * \p flags must be \c 0 for now.
375
+ *
376
+ * \return \c 0 on success.
377
+ * \return \c -1 on error.
378
+ */
379
+ HWLOC_DECLSPEC int hwloc_distances_add_values(hwloc_topology_t topology,
380
+ hwloc_distances_add_handle_t handle,
381
+ unsigned nbobjs, hwloc_obj_t *objs,
382
+ hwloc_uint64_t *values,
383
+ unsigned long flags);
384
+
385
+ /** \brief Flags for adding a new distances to a topology. */
386
+ enum hwloc_distances_add_flag_e {
387
+ /** \brief Try to group objects based on the newly provided distance information.
388
+ * This is ignored for distances between objects of different types.
389
+ * \hideinitializer
390
+ */
391
+ HWLOC_DISTANCES_ADD_FLAG_GROUP = (1UL<<0),
392
+ /** \brief If grouping, consider the distance values as inaccurate and relax the
393
+ * comparisons during the grouping algorithms. The actual accuracy may be modified
394
+ * through the HWLOC_GROUPING_ACCURACY environment variable (see \ref envvar).
395
+ * \hideinitializer
396
+ */
397
+ HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE = (1UL<<1)
398
+ };
399
+
400
+ /** \brief Commit a new distances structure.
401
+ *
402
+ * This function finalizes the distances structure and inserts in it the topology.
403
+ *
404
+ * Parameter \p handle was previously returned by hwloc_distances_add_create().
405
+ * Then objects and values were specified with hwloc_distances_add_values().
406
+ *
407
+ * \p flags configures the behavior of the function using an optional OR'ed set of
408
+ * ::hwloc_distances_add_flag_e.
409
+ * It may be used to request the grouping of existing objects based on distances.
410
+ *
411
+ * On error, the temporary distances structure and its content are destroyed.
412
+ *
413
+ * \return \c 0 on success.
414
+ * \return \c -1 on error.
415
+ */
416
+ HWLOC_DECLSPEC int hwloc_distances_add_commit(hwloc_topology_t topology,
417
+ hwloc_distances_add_handle_t handle,
418
+ unsigned long flags);
419
+
420
+ /** @} */
421
+
422
+
423
+
424
+ /** \defgroup hwlocality_distances_remove Remove distances between objects
425
+ * @{
426
+ */
427
+
428
+ /** \brief Remove all distance matrices from a topology.
429
+ *
430
+ * Remove all distance matrices, either provided by the user or
431
+ * gathered through the OS.
432
+ *
433
+ * If these distances were used to group objects, these additional
434
+ * Group objects are not removed from the topology.
435
+ */
436
+ HWLOC_DECLSPEC int hwloc_distances_remove(hwloc_topology_t topology);
437
+
438
+ /** \brief Remove distance matrices for objects at a specific depth in the topology.
439
+ *
440
+ * Identical to hwloc_distances_remove() but only applies to one level of the topology.
441
+ */
442
+ HWLOC_DECLSPEC int hwloc_distances_remove_by_depth(hwloc_topology_t topology, int depth);
443
+
444
+ /** \brief Remove distance matrices for objects of a specific type in the topology.
445
+ *
446
+ * Identical to hwloc_distances_remove() but only applies to one level of the topology.
447
+ */
448
+ static __hwloc_inline int
449
+ hwloc_distances_remove_by_type(hwloc_topology_t topology, hwloc_obj_type_t type)
450
+ {
451
+ int depth = hwloc_get_type_depth(topology, type);
452
+ if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
453
+ return 0;
454
+ return hwloc_distances_remove_by_depth(topology, depth);
455
+ }
456
+
457
+ /** \brief Release and remove the given distance matrice from the topology.
458
+ *
459
+ * This function includes a call to hwloc_distances_release().
460
+ */
461
+ HWLOC_DECLSPEC int hwloc_distances_release_remove(hwloc_topology_t topology, struct hwloc_distances_s *distances);
462
+
463
+ /** @} */
464
+
465
+
466
+ #ifdef __cplusplus
467
+ } /* extern "C" */
468
+ #endif
469
+
470
+
471
+ #endif /* HWLOC_DISTANCES_H */
deps/exla/cache/xla_extension/include/include/hwloc/export.h ADDED
@@ -0,0 +1,278 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2009-2018 Inria. All rights reserved.
3
+ * Copyright © 2009-2012 Université Bordeaux
4
+ * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
5
+ * See COPYING in top-level directory.
6
+ */
7
+
8
+ /** \file
9
+ * \brief Exporting Topologies to XML or to Synthetic strings.
10
+ */
11
+
12
+ #ifndef HWLOC_EXPORT_H
13
+ #define HWLOC_EXPORT_H
14
+
15
+ #ifndef HWLOC_H
16
+ #error Please include the main hwloc.h instead
17
+ #endif
18
+
19
+
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #elif 0
23
+ }
24
+ #endif
25
+
26
+
27
+ /** \defgroup hwlocality_xmlexport Exporting Topologies to XML
28
+ * @{
29
+ */
30
+
31
+ /** \brief Flags for exporting XML topologies.
32
+ *
33
+ * Flags to be given as a OR'ed set to hwloc_topology_export_xml().
34
+ */
35
+ enum hwloc_topology_export_xml_flags_e {
36
+ /** \brief Export XML that is loadable by hwloc v1.x.
37
+ * However, the export may miss some details about the topology.
38
+ * \hideinitializer
39
+ */
40
+ HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1 = (1UL<<0)
41
+ };
42
+
43
+ /** \brief Export the topology into an XML file.
44
+ *
45
+ * This file may be loaded later through hwloc_topology_set_xml().
46
+ *
47
+ * By default, the latest export format is used, which means older hwloc
48
+ * releases (e.g. v1.x) will not be able to import it.
49
+ * Exporting to v1.x specific XML format is possible using flag
50
+ * ::HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1 but it may miss some details
51
+ * about the topology.
52
+ * If there is any chance that the exported file may ever be imported
53
+ * back by a process using hwloc 1.x, one should consider detecting
54
+ * it at runtime and using the corresponding export format.
55
+ *
56
+ * \p flags is a OR'ed set of ::hwloc_topology_export_xml_flags_e.
57
+ *
58
+ * \return -1 if a failure occured.
59
+ *
60
+ * \note See also hwloc_topology_set_userdata_export_callback()
61
+ * for exporting application-specific object userdata.
62
+ *
63
+ * \note The topology-specific userdata pointer is ignored when exporting to XML.
64
+ *
65
+ * \note Only printable characters may be exported to XML string attributes.
66
+ * Any other character, especially any non-ASCII character, will be silently
67
+ * dropped.
68
+ *
69
+ * \note If \p name is "-", the XML output is sent to the standard output.
70
+ */
71
+ HWLOC_DECLSPEC int hwloc_topology_export_xml(hwloc_topology_t topology, const char *xmlpath, unsigned long flags);
72
+
73
+ /** \brief Export the topology into a newly-allocated XML memory buffer.
74
+ *
75
+ * \p xmlbuffer is allocated by the callee and should be freed with
76
+ * hwloc_free_xmlbuffer() later in the caller.
77
+ *
78
+ * This memory buffer may be loaded later through hwloc_topology_set_xmlbuffer().
79
+ *
80
+ * By default, the latest export format is used, which means older hwloc
81
+ * releases (e.g. v1.x) will not be able to import it.
82
+ * Exporting to v1.x specific XML format is possible using flag
83
+ * ::HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1 but it may miss some details
84
+ * about the topology.
85
+ * If there is any chance that the exported buffer may ever be imported
86
+ * back by a process using hwloc 1.x, one should consider detecting
87
+ * it at runtime and using the corresponding export format.
88
+ *
89
+ * The returned buffer ends with a \0 that is included in the returned
90
+ * length.
91
+ *
92
+ * \p flags is a OR'ed set of ::hwloc_topology_export_xml_flags_e.
93
+ *
94
+ * \return -1 if a failure occured.
95
+ *
96
+ * \note See also hwloc_topology_set_userdata_export_callback()
97
+ * for exporting application-specific object userdata.
98
+ *
99
+ * \note The topology-specific userdata pointer is ignored when exporting to XML.
100
+ *
101
+ * \note Only printable characters may be exported to XML string attributes.
102
+ * Any other character, especially any non-ASCII character, will be silently
103
+ * dropped.
104
+ */
105
+ HWLOC_DECLSPEC int hwloc_topology_export_xmlbuffer(hwloc_topology_t topology, char **xmlbuffer, int *buflen, unsigned long flags);
106
+
107
+ /** \brief Free a buffer allocated by hwloc_topology_export_xmlbuffer() */
108
+ HWLOC_DECLSPEC void hwloc_free_xmlbuffer(hwloc_topology_t topology, char *xmlbuffer);
109
+
110
+ /** \brief Set the application-specific callback for exporting object userdata
111
+ *
112
+ * The object userdata pointer is not exported to XML by default because hwloc
113
+ * does not know what it contains.
114
+ *
115
+ * This function lets applications set \p export_cb to a callback function
116
+ * that converts this opaque userdata into an exportable string.
117
+ *
118
+ * \p export_cb is invoked during XML export for each object whose
119
+ * \p userdata pointer is not \c NULL.
120
+ * The callback should use hwloc_export_obj_userdata() or
121
+ * hwloc_export_obj_userdata_base64() to actually export
122
+ * something to XML (possibly multiple times per object).
123
+ *
124
+ * \p export_cb may be set to \c NULL if userdata should not be exported to XML.
125
+ *
126
+ * \note The topology-specific userdata pointer is ignored when exporting to XML.
127
+ */
128
+ HWLOC_DECLSPEC void hwloc_topology_set_userdata_export_callback(hwloc_topology_t topology,
129
+ void (*export_cb)(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj));
130
+
131
+ /** \brief Export some object userdata to XML
132
+ *
133
+ * This function may only be called from within the export() callback passed
134
+ * to hwloc_topology_set_userdata_export_callback().
135
+ * It may be invoked one of multiple times to export some userdata to XML.
136
+ * The \p buffer content of length \p length is stored with optional name
137
+ * \p name.
138
+ *
139
+ * When importing this XML file, the import() callback (if set) will be
140
+ * called exactly as many times as hwloc_export_obj_userdata() was called
141
+ * during export(). It will receive the corresponding \p name, \p buffer
142
+ * and \p length arguments.
143
+ *
144
+ * \p reserved, \p topology and \p obj must be the first three parameters
145
+ * that were given to the export callback.
146
+ *
147
+ * Only printable characters may be exported to XML string attributes.
148
+ * If a non-printable character is passed in \p name or \p buffer,
149
+ * the function returns -1 with errno set to EINVAL.
150
+ *
151
+ * If exporting binary data, the application should first encode into
152
+ * printable characters only (or use hwloc_export_obj_userdata_base64()).
153
+ * It should also take care of portability issues if the export may
154
+ * be reimported on a different architecture.
155
+ */
156
+ HWLOC_DECLSPEC int hwloc_export_obj_userdata(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length);
157
+
158
+ /** \brief Encode and export some object userdata to XML
159
+ *
160
+ * This function is similar to hwloc_export_obj_userdata() but it encodes
161
+ * the input buffer into printable characters before exporting.
162
+ * On import, decoding is automatically performed before the data is given
163
+ * to the import() callback if any.
164
+ *
165
+ * This function may only be called from within the export() callback passed
166
+ * to hwloc_topology_set_userdata_export_callback().
167
+ *
168
+ * The function does not take care of portability issues if the export
169
+ * may be reimported on a different architecture.
170
+ */
171
+ HWLOC_DECLSPEC int hwloc_export_obj_userdata_base64(void *reserved, hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length);
172
+
173
+ /** \brief Set the application-specific callback for importing userdata
174
+ *
175
+ * On XML import, userdata is ignored by default because hwloc does not know
176
+ * how to store it in memory.
177
+ *
178
+ * This function lets applications set \p import_cb to a callback function
179
+ * that will get the XML-stored userdata and store it in the object as expected
180
+ * by the application.
181
+ *
182
+ * \p import_cb is called during hwloc_topology_load() as many times as
183
+ * hwloc_export_obj_userdata() was called during export. The topology
184
+ * is not entirely setup yet. Object attributes are ready to consult,
185
+ * but links between objects are not.
186
+ *
187
+ * \p import_cb may be \c NULL if userdata should be ignored during import.
188
+ *
189
+ * \note \p buffer contains \p length characters followed by a null byte ('\0').
190
+ *
191
+ * \note This function should be called before hwloc_topology_load().
192
+ *
193
+ * \note The topology-specific userdata pointer is ignored when importing from XML.
194
+ */
195
+ HWLOC_DECLSPEC void hwloc_topology_set_userdata_import_callback(hwloc_topology_t topology,
196
+ void (*import_cb)(hwloc_topology_t topology, hwloc_obj_t obj, const char *name, const void *buffer, size_t length));
197
+
198
+ /** @} */
199
+
200
+
201
+ /** \defgroup hwlocality_syntheticexport Exporting Topologies to Synthetic
202
+ * @{
203
+ */
204
+
205
+ /** \brief Flags for exporting synthetic topologies.
206
+ *
207
+ * Flags to be given as a OR'ed set to hwloc_topology_export_synthetic().
208
+ */
209
+ enum hwloc_topology_export_synthetic_flags_e {
210
+ /** \brief Export extended types such as L2dcache as basic types such as Cache.
211
+ *
212
+ * This is required if loading the synthetic description with hwloc < 1.9.
213
+ * \hideinitializer
214
+ */
215
+ HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_EXTENDED_TYPES = (1UL<<0),
216
+
217
+ /** \brief Do not export level attributes.
218
+ *
219
+ * Ignore level attributes such as memory/cache sizes or PU indexes.
220
+ * This is required if loading the synthetic description with hwloc < 1.10.
221
+ * \hideinitializer
222
+ */
223
+ HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_ATTRS = (1UL<<1),
224
+
225
+ /** \brief Export the memory hierarchy as expected in hwloc 1.x.
226
+ *
227
+ * Instead of attaching memory children to levels, export single NUMA node child
228
+ * as normal intermediate levels, when possible.
229
+ * This is required if loading the synthetic description with hwloc 1.x.
230
+ * However this may fail if some objects have multiple local NUMA nodes.
231
+ * \hideinitializer
232
+ */
233
+ HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_V1 = (1UL<<2),
234
+
235
+ /** \brief Do not export memory information.
236
+ *
237
+ * Only export the actual hierarchy of normal CPU-side objects and ignore
238
+ * where memory is attached.
239
+ * This is useful for when the hierarchy of CPUs is what really matters,
240
+ * but it behaves as if there was a single machine-wide NUMA node.
241
+ * \hideinitializer
242
+ */
243
+ HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_IGNORE_MEMORY = (1UL<<3)
244
+ };
245
+
246
+ /** \brief Export the topology as a synthetic string.
247
+ *
248
+ * At most \p buflen characters will be written in \p buffer,
249
+ * including the terminating \0.
250
+ *
251
+ * This exported string may be given back to hwloc_topology_set_synthetic().
252
+ *
253
+ * \p flags is a OR'ed set of ::hwloc_topology_export_synthetic_flags_e.
254
+ *
255
+ * \return The number of characters that were written,
256
+ * not including the terminating \0.
257
+ *
258
+ * \return -1 if the topology could not be exported,
259
+ * for instance if it is not symmetric.
260
+ *
261
+ * \note I/O and Misc children are ignored, the synthetic string only
262
+ * describes normal children.
263
+ *
264
+ * \note A 1024-byte buffer should be large enough for exporting
265
+ * topologies in the vast majority of cases.
266
+ */
267
+ HWLOC_DECLSPEC int hwloc_topology_export_synthetic(hwloc_topology_t topology, char *buffer, size_t buflen, unsigned long flags);
268
+
269
+ /** @} */
270
+
271
+
272
+
273
+ #ifdef __cplusplus
274
+ } /* extern "C" */
275
+ #endif
276
+
277
+
278
+ #endif /* HWLOC_EXPORT_H */
deps/exla/cache/xla_extension/include/include/hwloc/helper.h ADDED
@@ -0,0 +1,1231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2009 CNRS
3
+ * Copyright © 2009-2021 Inria. All rights reserved.
4
+ * Copyright © 2009-2012 Université Bordeaux
5
+ * Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
6
+ * See COPYING in top-level directory.
7
+ */
8
+
9
+ /** \file
10
+ * \brief High-level hwloc traversal helpers.
11
+ */
12
+
13
+ #ifndef HWLOC_HELPER_H
14
+ #define HWLOC_HELPER_H
15
+
16
+ #ifndef HWLOC_H
17
+ #error Please include the main hwloc.h instead
18
+ #endif
19
+
20
+ #include <stdlib.h>
21
+ #include <errno.h>
22
+
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+
29
+ /** \defgroup hwlocality_helper_find_inside Finding Objects inside a CPU set
30
+ * @{
31
+ */
32
+
33
+ /** \brief Get the first largest object included in the given cpuset \p set.
34
+ *
35
+ * \return the first object that is included in \p set and whose parent is not.
36
+ *
37
+ * This is convenient for iterating over all largest objects within a CPU set
38
+ * by doing a loop getting the first largest object and clearing its CPU set
39
+ * from the remaining CPU set.
40
+ */
41
+ static __hwloc_inline hwloc_obj_t
42
+ hwloc_get_first_largest_obj_inside_cpuset(hwloc_topology_t topology, hwloc_const_cpuset_t set)
43
+ {
44
+ hwloc_obj_t obj = hwloc_get_root_obj(topology);
45
+ if (!hwloc_bitmap_intersects(obj->cpuset, set))
46
+ return NULL;
47
+ while (!hwloc_bitmap_isincluded(obj->cpuset, set)) {
48
+ /* while the object intersects without being included, look at its children */
49
+ hwloc_obj_t child = obj->first_child;
50
+ while (child) {
51
+ if (hwloc_bitmap_intersects(child->cpuset, set))
52
+ break;
53
+ child = child->next_sibling;
54
+ }
55
+ if (!child)
56
+ /* no child intersects, return their father */
57
+ return obj;
58
+ /* found one intersecting child, look at its children */
59
+ obj = child;
60
+ }
61
+ /* obj is included, return it */
62
+ return obj;
63
+ }
64
+
65
+ /** \brief Get the set of largest objects covering exactly a given cpuset \p set
66
+ *
67
+ * \return the number of objects returned in \p objs.
68
+ */
69
+ HWLOC_DECLSPEC int hwloc_get_largest_objs_inside_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set,
70
+ hwloc_obj_t * __hwloc_restrict objs, int max);
71
+
72
+ /** \brief Return the next object at depth \p depth included in CPU set \p set.
73
+ *
74
+ * If \p prev is \c NULL, return the first object at depth \p depth
75
+ * included in \p set. The next invokation should pass the previous
76
+ * return value in \p prev so as to obtain the next object in \p set.
77
+ *
78
+ * \note Objects with empty CPU sets are ignored
79
+ * (otherwise they would be considered included in any given set).
80
+ *
81
+ * \note This function cannot work if objects at the given depth do
82
+ * not have CPU sets (I/O or Misc objects).
83
+ */
84
+ static __hwloc_inline hwloc_obj_t
85
+ hwloc_get_next_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
86
+ int depth, hwloc_obj_t prev)
87
+ {
88
+ hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
89
+ if (!next)
90
+ return NULL;
91
+ while (next && (hwloc_bitmap_iszero(next->cpuset) || !hwloc_bitmap_isincluded(next->cpuset, set)))
92
+ next = next->next_cousin;
93
+ return next;
94
+ }
95
+
96
+ /** \brief Return the next object of type \p type included in CPU set \p set.
97
+ *
98
+ * If there are multiple or no depth for given type, return \c NULL
99
+ * and let the caller fallback to
100
+ * hwloc_get_next_obj_inside_cpuset_by_depth().
101
+ *
102
+ * \note Objects with empty CPU sets are ignored
103
+ * (otherwise they would be considered included in any given set).
104
+ *
105
+ * \note This function cannot work if objects of the given type do
106
+ * not have CPU sets (I/O or Misc objects).
107
+ */
108
+ static __hwloc_inline hwloc_obj_t
109
+ hwloc_get_next_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
110
+ hwloc_obj_type_t type, hwloc_obj_t prev)
111
+ {
112
+ int depth = hwloc_get_type_depth(topology, type);
113
+ if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
114
+ return NULL;
115
+ return hwloc_get_next_obj_inside_cpuset_by_depth(topology, set, depth, prev);
116
+ }
117
+
118
+ /** \brief Return the (logically) \p idx -th object at depth \p depth included in CPU set \p set.
119
+ *
120
+ * \note Objects with empty CPU sets are ignored
121
+ * (otherwise they would be considered included in any given set).
122
+ *
123
+ * \note This function cannot work if objects at the given depth do
124
+ * not have CPU sets (I/O or Misc objects).
125
+ */
126
+ static __hwloc_inline hwloc_obj_t
127
+ hwloc_get_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
128
+ int depth, unsigned idx) __hwloc_attribute_pure;
129
+ static __hwloc_inline hwloc_obj_t
130
+ hwloc_get_obj_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
131
+ int depth, unsigned idx)
132
+ {
133
+ hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
134
+ unsigned count = 0;
135
+ if (!obj)
136
+ return NULL;
137
+ while (obj) {
138
+ if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set)) {
139
+ if (count == idx)
140
+ return obj;
141
+ count++;
142
+ }
143
+ obj = obj->next_cousin;
144
+ }
145
+ return NULL;
146
+ }
147
+
148
+ /** \brief Return the \p idx -th object of type \p type included in CPU set \p set.
149
+ *
150
+ * If there are multiple or no depth for given type, return \c NULL
151
+ * and let the caller fallback to
152
+ * hwloc_get_obj_inside_cpuset_by_depth().
153
+ *
154
+ * \note Objects with empty CPU sets are ignored
155
+ * (otherwise they would be considered included in any given set).
156
+ *
157
+ * \note This function cannot work if objects of the given type do
158
+ * not have CPU sets (I/O or Misc objects).
159
+ */
160
+ static __hwloc_inline hwloc_obj_t
161
+ hwloc_get_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
162
+ hwloc_obj_type_t type, unsigned idx) __hwloc_attribute_pure;
163
+ static __hwloc_inline hwloc_obj_t
164
+ hwloc_get_obj_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
165
+ hwloc_obj_type_t type, unsigned idx)
166
+ {
167
+ int depth = hwloc_get_type_depth(topology, type);
168
+ if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
169
+ return NULL;
170
+ return hwloc_get_obj_inside_cpuset_by_depth(topology, set, depth, idx);
171
+ }
172
+
173
+ /** \brief Return the number of objects at depth \p depth included in CPU set \p set.
174
+ *
175
+ * \note Objects with empty CPU sets are ignored
176
+ * (otherwise they would be considered included in any given set).
177
+ *
178
+ * \note This function cannot work if objects at the given depth do
179
+ * not have CPU sets (I/O or Misc objects).
180
+ */
181
+ static __hwloc_inline unsigned
182
+ hwloc_get_nbobjs_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
183
+ int depth) __hwloc_attribute_pure;
184
+ static __hwloc_inline unsigned
185
+ hwloc_get_nbobjs_inside_cpuset_by_depth (hwloc_topology_t topology, hwloc_const_cpuset_t set,
186
+ int depth)
187
+ {
188
+ hwloc_obj_t obj = hwloc_get_obj_by_depth (topology, depth, 0);
189
+ unsigned count = 0;
190
+ if (!obj)
191
+ return 0;
192
+ while (obj) {
193
+ if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
194
+ count++;
195
+ obj = obj->next_cousin;
196
+ }
197
+ return count;
198
+ }
199
+
200
+ /** \brief Return the number of objects of type \p type included in CPU set \p set.
201
+ *
202
+ * If no object for that type exists inside CPU set \p set, 0 is
203
+ * returned. If there are several levels with objects of that type
204
+ * inside CPU set \p set, -1 is returned.
205
+ *
206
+ * \note Objects with empty CPU sets are ignored
207
+ * (otherwise they would be considered included in any given set).
208
+ *
209
+ * \note This function cannot work if objects of the given type do
210
+ * not have CPU sets (I/O objects).
211
+ */
212
+ static __hwloc_inline int
213
+ hwloc_get_nbobjs_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
214
+ hwloc_obj_type_t type) __hwloc_attribute_pure;
215
+ static __hwloc_inline int
216
+ hwloc_get_nbobjs_inside_cpuset_by_type (hwloc_topology_t topology, hwloc_const_cpuset_t set,
217
+ hwloc_obj_type_t type)
218
+ {
219
+ int depth = hwloc_get_type_depth(topology, type);
220
+ if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
221
+ return 0;
222
+ if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
223
+ return -1; /* FIXME: agregate nbobjs from different levels? */
224
+ return (int) hwloc_get_nbobjs_inside_cpuset_by_depth(topology, set, depth);
225
+ }
226
+
227
+ /** \brief Return the logical index among the objects included in CPU set \p set.
228
+ *
229
+ * Consult all objects in the same level as \p obj and inside CPU set \p set
230
+ * in the logical order, and return the index of \p obj within them.
231
+ * If \p set covers the entire topology, this is the logical index of \p obj.
232
+ * Otherwise, this is similar to a logical index within the part of the topology
233
+ * defined by CPU set \p set.
234
+ *
235
+ * \note Objects with empty CPU sets are ignored
236
+ * (otherwise they would be considered included in any given set).
237
+ *
238
+ * \note This function cannot work if obj does not have CPU sets (I/O objects).
239
+ */
240
+ static __hwloc_inline int
241
+ hwloc_get_obj_index_inside_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
242
+ hwloc_obj_t obj) __hwloc_attribute_pure;
243
+ static __hwloc_inline int
244
+ hwloc_get_obj_index_inside_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
245
+ hwloc_obj_t obj)
246
+ {
247
+ int idx = 0;
248
+ if (!hwloc_bitmap_isincluded(obj->cpuset, set))
249
+ return -1;
250
+ /* count how many objects are inside the cpuset on the way from us to the beginning of the level */
251
+ while ((obj = obj->prev_cousin) != NULL)
252
+ if (!hwloc_bitmap_iszero(obj->cpuset) && hwloc_bitmap_isincluded(obj->cpuset, set))
253
+ idx++;
254
+ return idx;
255
+ }
256
+
257
+ /** @} */
258
+
259
+
260
+
261
+ /** \defgroup hwlocality_helper_find_covering Finding Objects covering at least CPU set
262
+ * @{
263
+ */
264
+
265
+ /** \brief Get the child covering at least CPU set \p set.
266
+ *
267
+ * \return \c NULL if no child matches or if \p set is empty.
268
+ *
269
+ * \note This function cannot work if parent does not have a CPU set (I/O or Misc objects).
270
+ */
271
+ static __hwloc_inline hwloc_obj_t
272
+ hwloc_get_child_covering_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
273
+ hwloc_obj_t parent) __hwloc_attribute_pure;
274
+ static __hwloc_inline hwloc_obj_t
275
+ hwloc_get_child_covering_cpuset (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_const_cpuset_t set,
276
+ hwloc_obj_t parent)
277
+ {
278
+ hwloc_obj_t child;
279
+ if (hwloc_bitmap_iszero(set))
280
+ return NULL;
281
+ child = parent->first_child;
282
+ while (child) {
283
+ if (child->cpuset && hwloc_bitmap_isincluded(set, child->cpuset))
284
+ return child;
285
+ child = child->next_sibling;
286
+ }
287
+ return NULL;
288
+ }
289
+
290
+ /** \brief Get the lowest object covering at least CPU set \p set
291
+ *
292
+ * \return \c NULL if no object matches or if \p set is empty.
293
+ */
294
+ static __hwloc_inline hwloc_obj_t
295
+ hwloc_get_obj_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
296
+ static __hwloc_inline hwloc_obj_t
297
+ hwloc_get_obj_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set)
298
+ {
299
+ struct hwloc_obj *current = hwloc_get_root_obj(topology);
300
+ if (hwloc_bitmap_iszero(set) || !hwloc_bitmap_isincluded(set, current->cpuset))
301
+ return NULL;
302
+ while (1) {
303
+ hwloc_obj_t child = hwloc_get_child_covering_cpuset(topology, set, current);
304
+ if (!child)
305
+ return current;
306
+ current = child;
307
+ }
308
+ }
309
+
310
+ /** \brief Iterate through same-depth objects covering at least CPU set \p set
311
+ *
312
+ * If object \p prev is \c NULL, return the first object at depth \p
313
+ * depth covering at least part of CPU set \p set. The next
314
+ * invokation should pass the previous return value in \p prev so as
315
+ * to obtain the next object covering at least another part of \p set.
316
+ *
317
+ * \note This function cannot work if objects at the given depth do
318
+ * not have CPU sets (I/O or Misc objects).
319
+ */
320
+ static __hwloc_inline hwloc_obj_t
321
+ hwloc_get_next_obj_covering_cpuset_by_depth(hwloc_topology_t topology, hwloc_const_cpuset_t set,
322
+ int depth, hwloc_obj_t prev)
323
+ {
324
+ hwloc_obj_t next = hwloc_get_next_obj_by_depth(topology, depth, prev);
325
+ if (!next)
326
+ return NULL;
327
+ while (next && !hwloc_bitmap_intersects(set, next->cpuset))
328
+ next = next->next_cousin;
329
+ return next;
330
+ }
331
+
332
+ /** \brief Iterate through same-type objects covering at least CPU set \p set
333
+ *
334
+ * If object \p prev is \c NULL, return the first object of type \p
335
+ * type covering at least part of CPU set \p set. The next invokation
336
+ * should pass the previous return value in \p prev so as to obtain
337
+ * the next object of type \p type covering at least another part of
338
+ * \p set.
339
+ *
340
+ * If there are no or multiple depths for type \p type, \c NULL is returned.
341
+ * The caller may fallback to hwloc_get_next_obj_covering_cpuset_by_depth()
342
+ * for each depth.
343
+ *
344
+ * \note This function cannot work if objects of the given type do
345
+ * not have CPU sets (I/O or Misc objects).
346
+ */
347
+ static __hwloc_inline hwloc_obj_t
348
+ hwloc_get_next_obj_covering_cpuset_by_type(hwloc_topology_t topology, hwloc_const_cpuset_t set,
349
+ hwloc_obj_type_t type, hwloc_obj_t prev)
350
+ {
351
+ int depth = hwloc_get_type_depth(topology, type);
352
+ if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
353
+ return NULL;
354
+ return hwloc_get_next_obj_covering_cpuset_by_depth(topology, set, depth, prev);
355
+ }
356
+
357
+ /** @} */
358
+
359
+
360
+
361
+ /** \defgroup hwlocality_helper_ancestors Looking at Ancestor and Child Objects
362
+ * @{
363
+ *
364
+ * Be sure to see the figure in \ref termsanddefs that shows a
365
+ * complete topology tree, including depths, child/sibling/cousin
366
+ * relationships, and an example of an asymmetric topology where one
367
+ * package has fewer caches than its peers.
368
+ */
369
+
370
+ /** \brief Returns the ancestor object of \p obj at depth \p depth.
371
+ *
372
+ * \note \p depth should not be the depth of PU or NUMA objects
373
+ * since they are ancestors of no objects (except Misc or I/O).
374
+ * This function rather expects an intermediate level depth,
375
+ * such as the depth of Packages, Cores, or Caches.
376
+ */
377
+ static __hwloc_inline hwloc_obj_t
378
+ hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj) __hwloc_attribute_pure;
379
+ static __hwloc_inline hwloc_obj_t
380
+ hwloc_get_ancestor_obj_by_depth (hwloc_topology_t topology __hwloc_attribute_unused, int depth, hwloc_obj_t obj)
381
+ {
382
+ hwloc_obj_t ancestor = obj;
383
+ if (obj->depth < depth)
384
+ return NULL;
385
+ while (ancestor && ancestor->depth > depth)
386
+ ancestor = ancestor->parent;
387
+ return ancestor;
388
+ }
389
+
390
+ /** \brief Returns the ancestor object of \p obj with type \p type.
391
+ *
392
+ * \note \p type should not be ::HWLOC_OBJ_PU or ::HWLOC_OBJ_NUMANODE
393
+ * since these objects are ancestors of no objects (except Misc or I/O).
394
+ * This function rather expects an intermediate object type,
395
+ * such as ::HWLOC_OBJ_PACKAGE, ::HWLOC_OBJ_CORE, etc.
396
+ */
397
+ static __hwloc_inline hwloc_obj_t
398
+ hwloc_get_ancestor_obj_by_type (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_type_t type, hwloc_obj_t obj) __hwloc_attribute_pure;
399
+ static __hwloc_inline hwloc_obj_t
400
+ hwloc_get_ancestor_obj_by_type (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_type_t type, hwloc_obj_t obj)
401
+ {
402
+ hwloc_obj_t ancestor = obj->parent;
403
+ while (ancestor && ancestor->type != type)
404
+ ancestor = ancestor->parent;
405
+ return ancestor;
406
+ }
407
+
408
+ /** \brief Returns the common parent object to objects \p obj1 and \p obj2 */
409
+ static __hwloc_inline hwloc_obj_t
410
+ hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2) __hwloc_attribute_pure;
411
+ static __hwloc_inline hwloc_obj_t
412
+ hwloc_get_common_ancestor_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj1, hwloc_obj_t obj2)
413
+ {
414
+ /* the loop isn't so easy since intermediate ancestors may have
415
+ * different depth, causing us to alternate between using obj1->parent
416
+ * and obj2->parent. Also, even if at some point we find ancestors of
417
+ * of the same depth, their ancestors may have different depth again.
418
+ */
419
+ while (obj1 != obj2) {
420
+ while (obj1->depth > obj2->depth)
421
+ obj1 = obj1->parent;
422
+ while (obj2->depth > obj1->depth)
423
+ obj2 = obj2->parent;
424
+ if (obj1 != obj2 && obj1->depth == obj2->depth) {
425
+ obj1 = obj1->parent;
426
+ obj2 = obj2->parent;
427
+ }
428
+ }
429
+ return obj1;
430
+ }
431
+
432
+ /** \brief Returns true if \p obj is inside the subtree beginning with ancestor object \p subtree_root.
433
+ *
434
+ * \note This function cannot work if \p obj and \p subtree_root objects do
435
+ * not have CPU sets (I/O or Misc objects).
436
+ */
437
+ static __hwloc_inline int
438
+ hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root) __hwloc_attribute_pure;
439
+ static __hwloc_inline int
440
+ hwloc_obj_is_in_subtree (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj, hwloc_obj_t subtree_root)
441
+ {
442
+ return obj->cpuset && subtree_root->cpuset && hwloc_bitmap_isincluded(obj->cpuset, subtree_root->cpuset);
443
+ }
444
+
445
+ /** \brief Return the next child.
446
+ *
447
+ * Return the next child among the normal children list,
448
+ * then among the memory children list, then among the I/O
449
+ * children list, then among the Misc children list.
450
+ *
451
+ * If \p prev is \c NULL, return the first child.
452
+ *
453
+ * Return \c NULL when there is no next child.
454
+ */
455
+ static __hwloc_inline hwloc_obj_t
456
+ hwloc_get_next_child (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t parent, hwloc_obj_t prev)
457
+ {
458
+ hwloc_obj_t obj;
459
+ int state = 0;
460
+ if (prev) {
461
+ if (prev->type == HWLOC_OBJ_MISC)
462
+ state = 3;
463
+ else if (prev->type == HWLOC_OBJ_BRIDGE || prev->type == HWLOC_OBJ_PCI_DEVICE || prev->type == HWLOC_OBJ_OS_DEVICE)
464
+ state = 2;
465
+ else if (prev->type == HWLOC_OBJ_NUMANODE)
466
+ state = 1;
467
+ obj = prev->next_sibling;
468
+ } else {
469
+ obj = parent->first_child;
470
+ }
471
+ if (!obj && state == 0) {
472
+ obj = parent->memory_first_child;
473
+ state = 1;
474
+ }
475
+ if (!obj && state == 1) {
476
+ obj = parent->io_first_child;
477
+ state = 2;
478
+ }
479
+ if (!obj && state == 2) {
480
+ obj = parent->misc_first_child;
481
+ state = 3;
482
+ }
483
+ return obj;
484
+ }
485
+
486
+ /** @} */
487
+
488
+
489
+
490
+ /** \defgroup hwlocality_helper_types Kinds of object Type
491
+ * @{
492
+ *
493
+ * Each object type is
494
+ * either Normal (i.e. hwloc_obj_type_is_normal() returns 1),
495
+ * or Memory (i.e. hwloc_obj_type_is_memory() returns 1)
496
+ * or I/O (i.e. hwloc_obj_type_is_io() returns 1)
497
+ * or Misc (i.e. equal to ::HWLOC_OBJ_MISC).
498
+ * It cannot be of more than one of these kinds.
499
+ */
500
+
501
+ /** \brief Check whether an object type is Normal.
502
+ *
503
+ * Normal objects are objects of the main CPU hierarchy
504
+ * (Machine, Package, Core, PU, CPU caches, etc.),
505
+ * but they are not NUMA nodes, I/O devices or Misc objects.
506
+ *
507
+ * They are attached to parent as Normal children,
508
+ * not as Memory, I/O or Misc children.
509
+ *
510
+ * \return 1 if an object of type \p type is a Normal object, 0 otherwise.
511
+ */
512
+ HWLOC_DECLSPEC int
513
+ hwloc_obj_type_is_normal(hwloc_obj_type_t type);
514
+
515
+ /** \brief Check whether an object type is I/O.
516
+ *
517
+ * I/O objects are objects attached to their parents
518
+ * in the I/O children list.
519
+ * This current includes Bridges, PCI and OS devices.
520
+ *
521
+ * \return 1 if an object of type \p type is a I/O object, 0 otherwise.
522
+ */
523
+ HWLOC_DECLSPEC int
524
+ hwloc_obj_type_is_io(hwloc_obj_type_t type);
525
+
526
+ /** \brief Check whether an object type is Memory.
527
+ *
528
+ * Memory objects are objects attached to their parents
529
+ * in the Memory children list.
530
+ * This current includes NUMA nodes and Memory-side caches.
531
+ *
532
+ * \return 1 if an object of type \p type is a Memory object, 0 otherwise.
533
+ */
534
+ HWLOC_DECLSPEC int
535
+ hwloc_obj_type_is_memory(hwloc_obj_type_t type);
536
+
537
+ /** \brief Check whether an object type is a CPU Cache (Data, Unified or Instruction).
538
+ *
539
+ * Memory-side caches are not CPU caches.
540
+ *
541
+ * \return 1 if an object of type \p type is a Cache, 0 otherwise.
542
+ */
543
+ HWLOC_DECLSPEC int
544
+ hwloc_obj_type_is_cache(hwloc_obj_type_t type);
545
+
546
+ /** \brief Check whether an object type is a CPU Data or Unified Cache.
547
+ *
548
+ * Memory-side caches are not CPU caches.
549
+ *
550
+ * \return 1 if an object of type \p type is a CPU Data or Unified Cache, 0 otherwise.
551
+ */
552
+ HWLOC_DECLSPEC int
553
+ hwloc_obj_type_is_dcache(hwloc_obj_type_t type);
554
+
555
+ /** \brief Check whether an object type is a CPU Instruction Cache,
556
+ *
557
+ * Memory-side caches are not CPU caches.
558
+ *
559
+ * \return 1 if an object of type \p type is a CPU Instruction Cache, 0 otherwise.
560
+ */
561
+ HWLOC_DECLSPEC int
562
+ hwloc_obj_type_is_icache(hwloc_obj_type_t type);
563
+
564
+ /** @} */
565
+
566
+
567
+
568
+ /** \defgroup hwlocality_helper_find_cache Looking at Cache Objects
569
+ * @{
570
+ */
571
+
572
+ /** \brief Find the depth of cache objects matching cache level and type.
573
+ *
574
+ * Return the depth of the topology level that contains cache objects
575
+ * whose attributes match \p cachelevel and \p cachetype.
576
+
577
+ * This function is identical to calling hwloc_get_type_depth() with the
578
+ * corresponding type such as ::HWLOC_OBJ_L1ICACHE, except that it may
579
+ * also return a Unified cache when looking for an instruction cache.
580
+ *
581
+ * If no cache level matches, ::HWLOC_TYPE_DEPTH_UNKNOWN is returned.
582
+ *
583
+ * If \p cachetype is ::HWLOC_OBJ_CACHE_UNIFIED, the depth of the
584
+ * unique matching unified cache level is returned.
585
+ *
586
+ * If \p cachetype is ::HWLOC_OBJ_CACHE_DATA or ::HWLOC_OBJ_CACHE_INSTRUCTION,
587
+ * either a matching cache, or a unified cache is returned.
588
+ *
589
+ * If \p cachetype is \c -1, it is ignored and multiple levels may
590
+ * match. The function returns either the depth of a uniquely matching
591
+ * level or ::HWLOC_TYPE_DEPTH_MULTIPLE.
592
+ */
593
+ static __hwloc_inline int
594
+ hwloc_get_cache_type_depth (hwloc_topology_t topology,
595
+ unsigned cachelevel, hwloc_obj_cache_type_t cachetype)
596
+ {
597
+ int depth;
598
+ int found = HWLOC_TYPE_DEPTH_UNKNOWN;
599
+ for (depth=0; ; depth++) {
600
+ hwloc_obj_t obj = hwloc_get_obj_by_depth(topology, depth, 0);
601
+ if (!obj)
602
+ break;
603
+ if (!hwloc_obj_type_is_dcache(obj->type) || obj->attr->cache.depth != cachelevel)
604
+ /* doesn't match, try next depth */
605
+ continue;
606
+ if (cachetype == (hwloc_obj_cache_type_t) -1) {
607
+ if (found != HWLOC_TYPE_DEPTH_UNKNOWN) {
608
+ /* second match, return MULTIPLE */
609
+ return HWLOC_TYPE_DEPTH_MULTIPLE;
610
+ }
611
+ /* first match, mark it as found */
612
+ found = depth;
613
+ continue;
614
+ }
615
+ if (obj->attr->cache.type == cachetype || obj->attr->cache.type == HWLOC_OBJ_CACHE_UNIFIED)
616
+ /* exact match (either unified is alone, or we match instruction or data), return immediately */
617
+ return depth;
618
+ }
619
+ /* went to the bottom, return what we found */
620
+ return found;
621
+ }
622
+
623
+ /** \brief Get the first data (or unified) cache covering a cpuset \p set
624
+ *
625
+ * \return \c NULL if no cache matches.
626
+ */
627
+ static __hwloc_inline hwloc_obj_t
628
+ hwloc_get_cache_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set) __hwloc_attribute_pure;
629
+ static __hwloc_inline hwloc_obj_t
630
+ hwloc_get_cache_covering_cpuset (hwloc_topology_t topology, hwloc_const_cpuset_t set)
631
+ {
632
+ hwloc_obj_t current = hwloc_get_obj_covering_cpuset(topology, set);
633
+ while (current) {
634
+ if (hwloc_obj_type_is_dcache(current->type))
635
+ return current;
636
+ current = current->parent;
637
+ }
638
+ return NULL;
639
+ }
640
+
641
+ /** \brief Get the first data (or unified) cache shared between an object and somebody else.
642
+ *
643
+ * \return \c NULL if no cache matches or if an invalid object is given.
644
+ */
645
+ static __hwloc_inline hwloc_obj_t
646
+ hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj) __hwloc_attribute_pure;
647
+ static __hwloc_inline hwloc_obj_t
648
+ hwloc_get_shared_cache_covering_obj (hwloc_topology_t topology __hwloc_attribute_unused, hwloc_obj_t obj)
649
+ {
650
+ hwloc_obj_t current = obj->parent;
651
+ if (!obj->cpuset)
652
+ return NULL;
653
+ while (current) {
654
+ if (!hwloc_bitmap_isequal(current->cpuset, obj->cpuset)
655
+ && hwloc_obj_type_is_dcache(current->type))
656
+ return current;
657
+ current = current->parent;
658
+ }
659
+ return NULL;
660
+ }
661
+
662
+ /** @} */
663
+
664
+
665
+
666
+ /** \defgroup hwlocality_helper_find_misc Finding objects, miscellaneous helpers
667
+ * @{
668
+ *
669
+ * Be sure to see the figure in \ref termsanddefs that shows a
670
+ * complete topology tree, including depths, child/sibling/cousin
671
+ * relationships, and an example of an asymmetric topology where one
672
+ * package has fewer caches than its peers.
673
+ */
674
+
675
+ /** \brief Remove simultaneous multithreading PUs from a CPU set.
676
+ *
677
+ * For each core in \p topology, if \p cpuset contains some PUs of that core,
678
+ * modify \p cpuset to only keep a single PU for that core.
679
+ *
680
+ * \p which specifies which PU will be kept.
681
+ * PU are considered in physical index order.
682
+ * If 0, for each core, the function keeps the first PU that was originally set in \p cpuset.
683
+ *
684
+ * If \p which is larger than the number of PUs in a core there were originally set in \p cpuset,
685
+ * no PU is kept for that core.
686
+ *
687
+ * \note PUs that are not below a Core object are ignored
688
+ * (for instance if the topology does not contain any Core object).
689
+ * None of them is removed from \p cpuset.
690
+ */
691
+ HWLOC_DECLSPEC int hwloc_bitmap_singlify_per_core(hwloc_topology_t topology, hwloc_bitmap_t cpuset, unsigned which);
692
+
693
+ /** \brief Returns the object of type ::HWLOC_OBJ_PU with \p os_index.
694
+ *
695
+ * This function is useful for converting a CPU set into the PU
696
+ * objects it contains.
697
+ * When retrieving the current binding (e.g. with hwloc_get_cpubind()),
698
+ * one may iterate over the bits of the resulting CPU set with
699
+ * hwloc_bitmap_foreach_begin(), and find the corresponding PUs
700
+ * with this function.
701
+ */
702
+ static __hwloc_inline hwloc_obj_t
703
+ hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
704
+ static __hwloc_inline hwloc_obj_t
705
+ hwloc_get_pu_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
706
+ {
707
+ hwloc_obj_t obj = NULL;
708
+ while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PU, obj)) != NULL)
709
+ if (obj->os_index == os_index)
710
+ return obj;
711
+ return NULL;
712
+ }
713
+
714
+ /** \brief Returns the object of type ::HWLOC_OBJ_NUMANODE with \p os_index.
715
+ *
716
+ * This function is useful for converting a nodeset into the NUMA node
717
+ * objects it contains.
718
+ * When retrieving the current binding (e.g. with hwloc_get_membind() with HWLOC_MEMBIND_BYNODESET),
719
+ * one may iterate over the bits of the resulting nodeset with
720
+ * hwloc_bitmap_foreach_begin(), and find the corresponding NUMA nodes
721
+ * with this function.
722
+ */
723
+ static __hwloc_inline hwloc_obj_t
724
+ hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index) __hwloc_attribute_pure;
725
+ static __hwloc_inline hwloc_obj_t
726
+ hwloc_get_numanode_obj_by_os_index(hwloc_topology_t topology, unsigned os_index)
727
+ {
728
+ hwloc_obj_t obj = NULL;
729
+ while ((obj = hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_NUMANODE, obj)) != NULL)
730
+ if (obj->os_index == os_index)
731
+ return obj;
732
+ return NULL;
733
+ }
734
+
735
+ /** \brief Do a depth-first traversal of the topology to find and sort
736
+ *
737
+ * all objects that are at the same depth than \p src.
738
+ * Report in \p objs up to \p max physically closest ones to \p src.
739
+ *
740
+ * \return the number of objects returned in \p objs.
741
+ *
742
+ * \return 0 if \p src is an I/O object.
743
+ *
744
+ * \note This function requires the \p src object to have a CPU set.
745
+ */
746
+ /* TODO: rather provide an iterator? Provide a way to know how much should be allocated? By returning the total number of objects instead? */
747
+ HWLOC_DECLSPEC unsigned hwloc_get_closest_objs (hwloc_topology_t topology, hwloc_obj_t src, hwloc_obj_t * __hwloc_restrict objs, unsigned max);
748
+
749
+ /** \brief Find an object below another object, both specified by types and indexes.
750
+ *
751
+ * Start from the top system object and find object of type \p type1
752
+ * and logical index \p idx1. Then look below this object and find another
753
+ * object of type \p type2 and logical index \p idx2. Indexes are specified
754
+ * within the parent, not withing the entire system.
755
+ *
756
+ * For instance, if type1 is PACKAGE, idx1 is 2, type2 is CORE and idx2
757
+ * is 3, return the fourth core object below the third package.
758
+ *
759
+ * \note This function requires these objects to have a CPU set.
760
+ */
761
+ static __hwloc_inline hwloc_obj_t
762
+ hwloc_get_obj_below_by_type (hwloc_topology_t topology,
763
+ hwloc_obj_type_t type1, unsigned idx1,
764
+ hwloc_obj_type_t type2, unsigned idx2) __hwloc_attribute_pure;
765
+ static __hwloc_inline hwloc_obj_t
766
+ hwloc_get_obj_below_by_type (hwloc_topology_t topology,
767
+ hwloc_obj_type_t type1, unsigned idx1,
768
+ hwloc_obj_type_t type2, unsigned idx2)
769
+ {
770
+ hwloc_obj_t obj;
771
+ obj = hwloc_get_obj_by_type (topology, type1, idx1);
772
+ if (!obj)
773
+ return NULL;
774
+ return hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, type2, idx2);
775
+ }
776
+
777
+ /** \brief Find an object below a chain of objects specified by types and indexes.
778
+ *
779
+ * This is a generalized version of hwloc_get_obj_below_by_type().
780
+ *
781
+ * Arrays \p typev and \p idxv must contain \p nr types and indexes.
782
+ *
783
+ * Start from the top system object and walk the arrays \p typev and \p idxv.
784
+ * For each type and logical index couple in the arrays, look under the previously found
785
+ * object to find the index-th object of the given type.
786
+ * Indexes are specified within the parent, not withing the entire system.
787
+ *
788
+ * For instance, if nr is 3, typev contains NODE, PACKAGE and CORE,
789
+ * and idxv contains 0, 1 and 2, return the third core object below
790
+ * the second package below the first NUMA node.
791
+ *
792
+ * \note This function requires all these objects and the root object
793
+ * to have a CPU set.
794
+ */
795
+ static __hwloc_inline hwloc_obj_t
796
+ hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv) __hwloc_attribute_pure;
797
+ static __hwloc_inline hwloc_obj_t
798
+ hwloc_get_obj_below_array_by_type (hwloc_topology_t topology, int nr, hwloc_obj_type_t *typev, unsigned *idxv)
799
+ {
800
+ hwloc_obj_t obj = hwloc_get_root_obj(topology);
801
+ int i;
802
+ for(i=0; i<nr; i++) {
803
+ if (!obj)
804
+ return NULL;
805
+ obj = hwloc_get_obj_inside_cpuset_by_type(topology, obj->cpuset, typev[i], idxv[i]);
806
+ }
807
+ return obj;
808
+ }
809
+
810
+ /** \brief Return an object of a different type with same locality.
811
+ *
812
+ * If the source object \p src is a normal or memory type,
813
+ * this function returns an object of type \p type with same
814
+ * CPU and node sets, either below or above in the hierarchy.
815
+ *
816
+ * If the source object \p src is a PCI or an OS device within a PCI
817
+ * device, the function may either return that PCI device, or another
818
+ * OS device in the same PCI parent.
819
+ * This may for instance be useful for converting between OS devices
820
+ * such as "nvml0" or "rsmi1" used in distance structures into the
821
+ * the PCI device, or the CUDA or OpenCL OS device that correspond
822
+ * to the same physical card.
823
+ *
824
+ * If not \c NULL, parameter \p subtype only select objects whose
825
+ * subtype attribute exists and is \p subtype (case-insensitively),
826
+ * for instance "OpenCL" or "CUDA".
827
+ *
828
+ * If not \c NULL, parameter \p nameprefix only selects objects whose
829
+ * name attribute exists and starts with \p nameprefix (case-insensitively),
830
+ * for instance "rsmi" for matching "rsmi0".
831
+ *
832
+ * If multiple objects match, the first one is returned.
833
+ *
834
+ * This function will not walk the hierarchy across bridges since
835
+ * the PCI locality may become different.
836
+ * This function cannot also convert between normal/memory objects
837
+ * and I/O or Misc objects.
838
+ *
839
+ * \p flags must be \c 0 for now.
840
+ *
841
+ * \return An object with identical locality,
842
+ * matching \p subtype and \p nameprefix if any.
843
+ *
844
+ * \return \c NULL if no matching object could be found,
845
+ * or if the source object and target type are incompatible,
846
+ * for instance if converting between CPU and I/O objects.
847
+ */
848
+ HWLOC_DECLSPEC hwloc_obj_t
849
+ hwloc_get_obj_with_same_locality(hwloc_topology_t topology, hwloc_obj_t src,
850
+ hwloc_obj_type_t type, const char *subtype, const char *nameprefix,
851
+ unsigned long flags);
852
+
853
+ /** @} */
854
+
855
+
856
+
857
+ /** \defgroup hwlocality_helper_distribute Distributing items over a topology
858
+ * @{
859
+ */
860
+
861
+ /** \brief Flags to be given to hwloc_distrib().
862
+ */
863
+ enum hwloc_distrib_flags_e {
864
+ /** \brief Distrib in reverse order, starting from the last objects.
865
+ * \hideinitializer
866
+ */
867
+ HWLOC_DISTRIB_FLAG_REVERSE = (1UL<<0)
868
+ };
869
+
870
+ /** \brief Distribute \p n items over the topology under \p roots
871
+ *
872
+ * Array \p set will be filled with \p n cpusets recursively distributed
873
+ * linearly over the topology under objects \p roots, down to depth \p until
874
+ * (which can be INT_MAX to distribute down to the finest level).
875
+ *
876
+ * \p n_roots is usually 1 and \p roots only contains the topology root object
877
+ * so as to distribute over the entire topology.
878
+ *
879
+ * This is typically useful when an application wants to distribute \p n
880
+ * threads over a machine, giving each of them as much private cache as
881
+ * possible and keeping them locally in number order.
882
+ *
883
+ * The caller may typically want to also call hwloc_bitmap_singlify()
884
+ * before binding a thread so that it does not move at all.
885
+ *
886
+ * \p flags should be 0 or a OR'ed set of ::hwloc_distrib_flags_e.
887
+ *
888
+ * \note This function requires the \p roots objects to have a CPU set.
889
+ *
890
+ * \note This function replaces the now deprecated hwloc_distribute()
891
+ * and hwloc_distributev() functions.
892
+ */
893
+ static __hwloc_inline int
894
+ hwloc_distrib(hwloc_topology_t topology,
895
+ hwloc_obj_t *roots, unsigned n_roots,
896
+ hwloc_cpuset_t *set,
897
+ unsigned n,
898
+ int until, unsigned long flags)
899
+ {
900
+ unsigned i;
901
+ unsigned tot_weight;
902
+ unsigned given, givenweight;
903
+ hwloc_cpuset_t *cpusetp = set;
904
+
905
+ if (flags & ~HWLOC_DISTRIB_FLAG_REVERSE) {
906
+ errno = EINVAL;
907
+ return -1;
908
+ }
909
+
910
+ tot_weight = 0;
911
+ for (i = 0; i < n_roots; i++)
912
+ tot_weight += (unsigned) hwloc_bitmap_weight(roots[i]->cpuset);
913
+
914
+ for (i = 0, given = 0, givenweight = 0; i < n_roots; i++) {
915
+ unsigned chunk, weight;
916
+ hwloc_obj_t root = roots[flags & HWLOC_DISTRIB_FLAG_REVERSE ? n_roots-1-i : i];
917
+ hwloc_cpuset_t cpuset = root->cpuset;
918
+ while (!hwloc_obj_type_is_normal(root->type))
919
+ /* If memory/io/misc, walk up to normal parent */
920
+ root = root->parent;
921
+ weight = (unsigned) hwloc_bitmap_weight(cpuset);
922
+ if (!weight)
923
+ continue;
924
+ /* Give to root a chunk proportional to its weight.
925
+ * If previous chunks got rounded-up, we may get a bit less. */
926
+ chunk = (( (givenweight+weight) * n + tot_weight-1) / tot_weight)
927
+ - (( givenweight * n + tot_weight-1) / tot_weight);
928
+ if (!root->arity || chunk <= 1 || root->depth >= until) {
929
+ /* We can't split any more, put everything there. */
930
+ if (chunk) {
931
+ /* Fill cpusets with ours */
932
+ unsigned j;
933
+ for (j=0; j < chunk; j++)
934
+ cpusetp[j] = hwloc_bitmap_dup(cpuset);
935
+ } else {
936
+ /* We got no chunk, just merge our cpuset to a previous one
937
+ * (the first chunk cannot be empty)
938
+ * so that this root doesn't get ignored.
939
+ */
940
+ assert(given);
941
+ hwloc_bitmap_or(cpusetp[-1], cpusetp[-1], cpuset);
942
+ }
943
+ } else {
944
+ /* Still more to distribute, recurse into children */
945
+ hwloc_distrib(topology, root->children, root->arity, cpusetp, chunk, until, flags);
946
+ }
947
+ cpusetp += chunk;
948
+ given += chunk;
949
+ givenweight += weight;
950
+ }
951
+
952
+ return 0;
953
+ }
954
+
955
+ /** @} */
956
+
957
+
958
+
959
+ /** \defgroup hwlocality_helper_topology_sets CPU and node sets of entire topologies
960
+ * @{
961
+ */
962
+
963
+ /** \brief Get complete CPU set
964
+ *
965
+ * \return the complete CPU set of processors of the system.
966
+ *
967
+ * \note The returned cpuset is not newly allocated and should thus not be
968
+ * changed or freed; hwloc_bitmap_dup() must be used to obtain a local copy.
969
+ *
970
+ * \note This is equivalent to retrieving the root object complete CPU-set.
971
+ */
972
+ HWLOC_DECLSPEC hwloc_const_cpuset_t
973
+ hwloc_topology_get_complete_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
974
+
975
+ /** \brief Get topology CPU set
976
+ *
977
+ * \return the CPU set of processors of the system for which hwloc
978
+ * provides topology information. This is equivalent to the cpuset of the
979
+ * system object.
980
+ *
981
+ * \note The returned cpuset is not newly allocated and should thus not be
982
+ * changed or freed; hwloc_bitmap_dup() must be used to obtain a local copy.
983
+ *
984
+ * \note This is equivalent to retrieving the root object CPU-set.
985
+ */
986
+ HWLOC_DECLSPEC hwloc_const_cpuset_t
987
+ hwloc_topology_get_topology_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
988
+
989
+ /** \brief Get allowed CPU set
990
+ *
991
+ * \return the CPU set of allowed processors of the system.
992
+ *
993
+ * \note If the topology flag ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED was not set,
994
+ * this is identical to hwloc_topology_get_topology_cpuset(), which means
995
+ * all PUs are allowed.
996
+ *
997
+ * \note If ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED was set, applying
998
+ * hwloc_bitmap_intersects() on the result of this function and on an object
999
+ * cpuset checks whether there are allowed PUs inside that object.
1000
+ * Applying hwloc_bitmap_and() returns the list of these allowed PUs.
1001
+ *
1002
+ * \note The returned cpuset is not newly allocated and should thus not be
1003
+ * changed or freed, hwloc_bitmap_dup() must be used to obtain a local copy.
1004
+ */
1005
+ HWLOC_DECLSPEC hwloc_const_cpuset_t
1006
+ hwloc_topology_get_allowed_cpuset(hwloc_topology_t topology) __hwloc_attribute_pure;
1007
+
1008
+ /** \brief Get complete node set
1009
+ *
1010
+ * \return the complete node set of memory of the system.
1011
+ *
1012
+ * \note The returned nodeset is not newly allocated and should thus not be
1013
+ * changed or freed; hwloc_bitmap_dup() must be used to obtain a local copy.
1014
+ *
1015
+ * \note This is equivalent to retrieving the root object complete nodeset.
1016
+ */
1017
+ HWLOC_DECLSPEC hwloc_const_nodeset_t
1018
+ hwloc_topology_get_complete_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1019
+
1020
+ /** \brief Get topology node set
1021
+ *
1022
+ * \return the node set of memory of the system for which hwloc
1023
+ * provides topology information. This is equivalent to the nodeset of the
1024
+ * system object.
1025
+ *
1026
+ * \note The returned nodeset is not newly allocated and should thus not be
1027
+ * changed or freed; hwloc_bitmap_dup() must be used to obtain a local copy.
1028
+ *
1029
+ * \note This is equivalent to retrieving the root object nodeset.
1030
+ */
1031
+ HWLOC_DECLSPEC hwloc_const_nodeset_t
1032
+ hwloc_topology_get_topology_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1033
+
1034
+ /** \brief Get allowed node set
1035
+ *
1036
+ * \return the node set of allowed memory of the system.
1037
+ *
1038
+ * \note If the topology flag ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED was not set,
1039
+ * this is identical to hwloc_topology_get_topology_nodeset(), which means
1040
+ * all NUMA nodes are allowed.
1041
+ *
1042
+ * \note If ::HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED was set, applying
1043
+ * hwloc_bitmap_intersects() on the result of this function and on an object
1044
+ * nodeset checks whether there are allowed NUMA nodes inside that object.
1045
+ * Applying hwloc_bitmap_and() returns the list of these allowed NUMA nodes.
1046
+ *
1047
+ * \note The returned nodeset is not newly allocated and should thus not be
1048
+ * changed or freed, hwloc_bitmap_dup() must be used to obtain a local copy.
1049
+ */
1050
+ HWLOC_DECLSPEC hwloc_const_nodeset_t
1051
+ hwloc_topology_get_allowed_nodeset(hwloc_topology_t topology) __hwloc_attribute_pure;
1052
+
1053
+ /** @} */
1054
+
1055
+
1056
+
1057
+ /** \defgroup hwlocality_helper_nodeset_convert Converting between CPU sets and node sets
1058
+ *
1059
+ * @{
1060
+ */
1061
+
1062
+ /** \brief Convert a CPU set into a NUMA node set
1063
+ *
1064
+ * For each PU included in the input \p _cpuset, set the corresponding
1065
+ * local NUMA node(s) in the output \p nodeset.
1066
+ *
1067
+ * If some NUMA nodes have no CPUs at all, this function never sets their
1068
+ * indexes in the output node set, even if a full CPU set is given in input.
1069
+ *
1070
+ * Hence the entire topology CPU set is converted into the set of all nodes
1071
+ * that have some local CPUs.
1072
+ */
1073
+ static __hwloc_inline int
1074
+ hwloc_cpuset_to_nodeset(hwloc_topology_t topology, hwloc_const_cpuset_t _cpuset, hwloc_nodeset_t nodeset)
1075
+ {
1076
+ int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
1077
+ hwloc_obj_t obj = NULL;
1078
+ assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1079
+ hwloc_bitmap_zero(nodeset);
1080
+ while ((obj = hwloc_get_next_obj_covering_cpuset_by_depth(topology, _cpuset, depth, obj)) != NULL)
1081
+ if (hwloc_bitmap_set(nodeset, obj->os_index) < 0)
1082
+ return -1;
1083
+ return 0;
1084
+ }
1085
+
1086
+ /** \brief Convert a NUMA node set into a CPU set
1087
+ *
1088
+ * For each NUMA node included in the input \p nodeset, set the corresponding
1089
+ * local PUs in the output \p _cpuset.
1090
+ *
1091
+ * If some CPUs have no local NUMA nodes, this function never sets their
1092
+ * indexes in the output CPU set, even if a full node set is given in input.
1093
+ *
1094
+ * Hence the entire topology node set is converted into the set of all CPUs
1095
+ * that have some local NUMA nodes.
1096
+ */
1097
+ static __hwloc_inline int
1098
+ hwloc_cpuset_from_nodeset(hwloc_topology_t topology, hwloc_cpuset_t _cpuset, hwloc_const_nodeset_t nodeset)
1099
+ {
1100
+ int depth = hwloc_get_type_depth(topology, HWLOC_OBJ_NUMANODE);
1101
+ hwloc_obj_t obj = NULL;
1102
+ assert(depth != HWLOC_TYPE_DEPTH_UNKNOWN);
1103
+ hwloc_bitmap_zero(_cpuset);
1104
+ while ((obj = hwloc_get_next_obj_by_depth(topology, depth, obj)) != NULL) {
1105
+ if (hwloc_bitmap_isset(nodeset, obj->os_index))
1106
+ /* no need to check obj->cpuset because objects in levels always have a cpuset */
1107
+ if (hwloc_bitmap_or(_cpuset, _cpuset, obj->cpuset) < 0)
1108
+ return -1;
1109
+ }
1110
+ return 0;
1111
+ }
1112
+
1113
+ /** @} */
1114
+
1115
+
1116
+
1117
+ /** \defgroup hwlocality_advanced_io Finding I/O objects
1118
+ * @{
1119
+ */
1120
+
1121
+ /** \brief Get the first non-I/O ancestor object.
1122
+ *
1123
+ * Given the I/O object \p ioobj, find the smallest non-I/O ancestor
1124
+ * object. This object (normal or memory) may then be used for binding
1125
+ * because it has non-NULL CPU and node sets
1126
+ * and because its locality is the same as \p ioobj.
1127
+ *
1128
+ * \note The resulting object is usually a normal object but it could also
1129
+ * be a memory object (e.g. NUMA node) in future platforms if I/O objects
1130
+ * ever get attached to memory instead of CPUs.
1131
+ */
1132
+ static __hwloc_inline hwloc_obj_t
1133
+ hwloc_get_non_io_ancestor_obj(hwloc_topology_t topology __hwloc_attribute_unused,
1134
+ hwloc_obj_t ioobj)
1135
+ {
1136
+ hwloc_obj_t obj = ioobj;
1137
+ while (obj && !obj->cpuset) {
1138
+ obj = obj->parent;
1139
+ }
1140
+ return obj;
1141
+ }
1142
+
1143
+ /** \brief Get the next PCI device in the system.
1144
+ *
1145
+ * \return the first PCI device if \p prev is \c NULL.
1146
+ */
1147
+ static __hwloc_inline hwloc_obj_t
1148
+ hwloc_get_next_pcidev(hwloc_topology_t topology, hwloc_obj_t prev)
1149
+ {
1150
+ return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_PCI_DEVICE, prev);
1151
+ }
1152
+
1153
+ /** \brief Find the PCI device object matching the PCI bus id
1154
+ * given domain, bus device and function PCI bus id.
1155
+ */
1156
+ static __hwloc_inline hwloc_obj_t
1157
+ hwloc_get_pcidev_by_busid(hwloc_topology_t topology,
1158
+ unsigned domain, unsigned bus, unsigned dev, unsigned func)
1159
+ {
1160
+ hwloc_obj_t obj = NULL;
1161
+ while ((obj = hwloc_get_next_pcidev(topology, obj)) != NULL) {
1162
+ if (obj->attr->pcidev.domain == domain
1163
+ && obj->attr->pcidev.bus == bus
1164
+ && obj->attr->pcidev.dev == dev
1165
+ && obj->attr->pcidev.func == func)
1166
+ return obj;
1167
+ }
1168
+ return NULL;
1169
+ }
1170
+
1171
+ /** \brief Find the PCI device object matching the PCI bus id
1172
+ * given as a string xxxx:yy:zz.t or yy:zz.t.
1173
+ */
1174
+ static __hwloc_inline hwloc_obj_t
1175
+ hwloc_get_pcidev_by_busidstring(hwloc_topology_t topology, const char *busid)
1176
+ {
1177
+ unsigned domain = 0; /* default */
1178
+ unsigned bus, dev, func;
1179
+
1180
+ if (sscanf(busid, "%x:%x.%x", &bus, &dev, &func) != 3
1181
+ && sscanf(busid, "%x:%x:%x.%x", &domain, &bus, &dev, &func) != 4) {
1182
+ errno = EINVAL;
1183
+ return NULL;
1184
+ }
1185
+
1186
+ return hwloc_get_pcidev_by_busid(topology, domain, bus, dev, func);
1187
+ }
1188
+
1189
+ /** \brief Get the next OS device in the system.
1190
+ *
1191
+ * \return the first OS device if \p prev is \c NULL.
1192
+ */
1193
+ static __hwloc_inline hwloc_obj_t
1194
+ hwloc_get_next_osdev(hwloc_topology_t topology, hwloc_obj_t prev)
1195
+ {
1196
+ return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_OS_DEVICE, prev);
1197
+ }
1198
+
1199
+ /** \brief Get the next bridge in the system.
1200
+ *
1201
+ * \return the first bridge if \p prev is \c NULL.
1202
+ */
1203
+ static __hwloc_inline hwloc_obj_t
1204
+ hwloc_get_next_bridge(hwloc_topology_t topology, hwloc_obj_t prev)
1205
+ {
1206
+ return hwloc_get_next_obj_by_type(topology, HWLOC_OBJ_BRIDGE, prev);
1207
+ }
1208
+
1209
+ /* \brief Checks whether a given bridge covers a given PCI bus.
1210
+ */
1211
+ static __hwloc_inline int
1212
+ hwloc_bridge_covers_pcibus(hwloc_obj_t bridge,
1213
+ unsigned domain, unsigned bus)
1214
+ {
1215
+ return bridge->type == HWLOC_OBJ_BRIDGE
1216
+ && bridge->attr->bridge.downstream_type == HWLOC_OBJ_BRIDGE_PCI
1217
+ && bridge->attr->bridge.downstream.pci.domain == domain
1218
+ && bridge->attr->bridge.downstream.pci.secondary_bus <= bus
1219
+ && bridge->attr->bridge.downstream.pci.subordinate_bus >= bus;
1220
+ }
1221
+
1222
+ /** @} */
1223
+
1224
+
1225
+
1226
+ #ifdef __cplusplus
1227
+ } /* extern "C" */
1228
+ #endif
1229
+
1230
+
1231
+ #endif /* HWLOC_HELPER_H */
deps/exla/cache/xla_extension/include/include/hwloc/inlines.h ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2009 CNRS
3
+ * Copyright © 2009-2018 Inria. All rights reserved.
4
+ * Copyright © 2009-2012 Université Bordeaux
5
+ * Copyright © 2009-2010 Cisco Systems, Inc. All rights reserved.
6
+ * See COPYING in top-level directory.
7
+ */
8
+
9
+ /**
10
+ * This file contains the inline code of functions declared in hwloc.h
11
+ */
12
+
13
+ #ifndef HWLOC_INLINES_H
14
+ #define HWLOC_INLINES_H
15
+
16
+ #ifndef HWLOC_H
17
+ #error Please include the main hwloc.h instead
18
+ #endif
19
+
20
+ #include <stdlib.h>
21
+ #include <errno.h>
22
+
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ static __hwloc_inline int
29
+ hwloc_get_type_or_below_depth (hwloc_topology_t topology, hwloc_obj_type_t type)
30
+ {
31
+ int depth = hwloc_get_type_depth(topology, type);
32
+
33
+ if (depth != HWLOC_TYPE_DEPTH_UNKNOWN)
34
+ return depth;
35
+
36
+ /* find the highest existing level with type order >= */
37
+ for(depth = hwloc_get_type_depth(topology, HWLOC_OBJ_PU); ; depth--)
38
+ if (hwloc_compare_types(hwloc_get_depth_type(topology, depth), type) < 0)
39
+ return depth+1;
40
+
41
+ /* Shouldn't ever happen, as there is always a Machine level with lower order and known depth. */
42
+ /* abort(); */
43
+ }
44
+
45
+ static __hwloc_inline int
46
+ hwloc_get_type_or_above_depth (hwloc_topology_t topology, hwloc_obj_type_t type)
47
+ {
48
+ int depth = hwloc_get_type_depth(topology, type);
49
+
50
+ if (depth != HWLOC_TYPE_DEPTH_UNKNOWN)
51
+ return depth;
52
+
53
+ /* find the lowest existing level with type order <= */
54
+ for(depth = 0; ; depth++)
55
+ if (hwloc_compare_types(hwloc_get_depth_type(topology, depth), type) > 0)
56
+ return depth-1;
57
+
58
+ /* Shouldn't ever happen, as there is always a PU level with higher order and known depth. */
59
+ /* abort(); */
60
+ }
61
+
62
+ static __hwloc_inline int
63
+ hwloc_get_nbobjs_by_type (hwloc_topology_t topology, hwloc_obj_type_t type)
64
+ {
65
+ int depth = hwloc_get_type_depth(topology, type);
66
+ if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
67
+ return 0;
68
+ if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
69
+ return -1; /* FIXME: agregate nbobjs from different levels? */
70
+ return (int) hwloc_get_nbobjs_by_depth(topology, depth);
71
+ }
72
+
73
+ static __hwloc_inline hwloc_obj_t
74
+ hwloc_get_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type, unsigned idx)
75
+ {
76
+ int depth = hwloc_get_type_depth(topology, type);
77
+ if (depth == HWLOC_TYPE_DEPTH_UNKNOWN)
78
+ return NULL;
79
+ if (depth == HWLOC_TYPE_DEPTH_MULTIPLE)
80
+ return NULL;
81
+ return hwloc_get_obj_by_depth(topology, depth, idx);
82
+ }
83
+
84
+ static __hwloc_inline hwloc_obj_t
85
+ hwloc_get_next_obj_by_depth (hwloc_topology_t topology, int depth, hwloc_obj_t prev)
86
+ {
87
+ if (!prev)
88
+ return hwloc_get_obj_by_depth (topology, depth, 0);
89
+ if (prev->depth != depth)
90
+ return NULL;
91
+ return prev->next_cousin;
92
+ }
93
+
94
+ static __hwloc_inline hwloc_obj_t
95
+ hwloc_get_next_obj_by_type (hwloc_topology_t topology, hwloc_obj_type_t type,
96
+ hwloc_obj_t prev)
97
+ {
98
+ int depth = hwloc_get_type_depth(topology, type);
99
+ if (depth == HWLOC_TYPE_DEPTH_UNKNOWN || depth == HWLOC_TYPE_DEPTH_MULTIPLE)
100
+ return NULL;
101
+ return hwloc_get_next_obj_by_depth (topology, depth, prev);
102
+ }
103
+
104
+ static __hwloc_inline hwloc_obj_t
105
+ hwloc_get_root_obj (hwloc_topology_t topology)
106
+ {
107
+ return hwloc_get_obj_by_depth (topology, 0, 0);
108
+ }
109
+
110
+ static __hwloc_inline const char *
111
+ hwloc_obj_get_info_by_name(hwloc_obj_t obj, const char *name)
112
+ {
113
+ unsigned i;
114
+ for(i=0; i<obj->infos_count; i++) {
115
+ struct hwloc_info_s *info = &obj->infos[i];
116
+ if (!strcmp(info->name, name))
117
+ return info->value;
118
+ }
119
+ return NULL;
120
+ }
121
+
122
+ static __hwloc_inline void *
123
+ hwloc_alloc_membind_policy(hwloc_topology_t topology, size_t len, hwloc_const_cpuset_t set, hwloc_membind_policy_t policy, int flags)
124
+ {
125
+ void *p = hwloc_alloc_membind(topology, len, set, policy, flags);
126
+ if (p)
127
+ return p;
128
+
129
+ if (hwloc_set_membind(topology, set, policy, flags) < 0)
130
+ /* hwloc_set_membind() takes care of ignoring errors if non-STRICT */
131
+ return NULL;
132
+
133
+ p = hwloc_alloc(topology, len);
134
+ if (p && policy != HWLOC_MEMBIND_FIRSTTOUCH)
135
+ /* Enforce the binding by touching the data */
136
+ memset(p, 0, len);
137
+ return p;
138
+ }
139
+
140
+
141
+ #ifdef __cplusplus
142
+ } /* extern "C" */
143
+ #endif
144
+
145
+
146
+ #endif /* HWLOC_INLINES_H */
deps/exla/cache/xla_extension/include/include/hwloc/linux.h ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2009 CNRS
3
+ * Copyright © 2009-2021 Inria. All rights reserved.
4
+ * Copyright © 2009-2011 Université Bordeaux
5
+ * See COPYING in top-level directory.
6
+ */
7
+
8
+ /** \file
9
+ * \brief Macros to help interaction between hwloc and Linux.
10
+ *
11
+ * Applications that use hwloc on Linux may want to include this file
12
+ * if using some low-level Linux features.
13
+ */
14
+
15
+ #ifndef HWLOC_LINUX_H
16
+ #define HWLOC_LINUX_H
17
+
18
+ #include "hwloc.h"
19
+
20
+ #include <stdio.h>
21
+
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+
28
+ /** \defgroup hwlocality_linux Linux-specific helpers
29
+ *
30
+ * This includes helpers for manipulating Linux kernel cpumap files, and hwloc
31
+ * equivalents of the Linux sched_setaffinity and sched_getaffinity system calls.
32
+ *
33
+ * @{
34
+ */
35
+
36
+ /** \brief Bind a thread \p tid on cpus given in cpuset \p set
37
+ *
38
+ * The behavior is exactly the same as the Linux sched_setaffinity system call,
39
+ * but uses a hwloc cpuset.
40
+ *
41
+ * \note This is equivalent to calling hwloc_set_proc_cpubind() with
42
+ * HWLOC_CPUBIND_THREAD as flags.
43
+ */
44
+ HWLOC_DECLSPEC int hwloc_linux_set_tid_cpubind(hwloc_topology_t topology, pid_t tid, hwloc_const_cpuset_t set);
45
+
46
+ /** \brief Get the current binding of thread \p tid
47
+ *
48
+ * The CPU-set \p set (previously allocated by the caller)
49
+ * is filled with the list of PUs which the thread
50
+ * was last bound to.
51
+ *
52
+ * The behavior is exactly the same as the Linux sched_getaffinity system call,
53
+ * but uses a hwloc cpuset.
54
+ *
55
+ * \note This is equivalent to calling hwloc_get_proc_cpubind() with
56
+ * ::HWLOC_CPUBIND_THREAD as flags.
57
+ */
58
+ HWLOC_DECLSPEC int hwloc_linux_get_tid_cpubind(hwloc_topology_t topology, pid_t tid, hwloc_cpuset_t set);
59
+
60
+ /** \brief Get the last physical CPU where thread \p tid ran.
61
+ *
62
+ * The CPU-set \p set (previously allocated by the caller)
63
+ * is filled with the PU which the thread last ran on.
64
+ *
65
+ * \note This is equivalent to calling hwloc_get_proc_last_cpu_location() with
66
+ * ::HWLOC_CPUBIND_THREAD as flags.
67
+ */
68
+ HWLOC_DECLSPEC int hwloc_linux_get_tid_last_cpu_location(hwloc_topology_t topology, pid_t tid, hwloc_bitmap_t set);
69
+
70
+ /** \brief Convert a linux kernel cpumask file \p path into a hwloc bitmap \p set.
71
+ *
72
+ * Might be used when reading CPU set from sysfs attributes such as topology
73
+ * and caches for processors, or local_cpus for devices.
74
+ *
75
+ * \note This function ignores the HWLOC_FSROOT environment variable.
76
+ */
77
+ HWLOC_DECLSPEC int hwloc_linux_read_path_as_cpumask(const char *path, hwloc_bitmap_t set);
78
+
79
+ /** @} */
80
+
81
+
82
+ #ifdef __cplusplus
83
+ } /* extern "C" */
84
+ #endif
85
+
86
+
87
+ #endif /* HWLOC_LINUX_H */
deps/exla/cache/xla_extension/include/include/hwloc/memattrs.h ADDED
@@ -0,0 +1,455 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2019-2022 Inria. All rights reserved.
3
+ * See COPYING in top-level directory.
4
+ */
5
+
6
+ /** \file
7
+ * \brief Memory node attributes.
8
+ */
9
+
10
+ #ifndef HWLOC_MEMATTR_H
11
+ #define HWLOC_MEMATTR_H
12
+
13
+ #include "hwloc.h"
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #elif 0
18
+ }
19
+ #endif
20
+
21
+ /** \defgroup hwlocality_memattrs Comparing memory node attributes for finding where to allocate on
22
+ *
23
+ * Platforms with heterogeneous memory require ways to decide whether
24
+ * a buffer should be allocated on "fast" memory (such as HBM),
25
+ * "normal" memory (DDR) or even "slow" but large-capacity memory
26
+ * (non-volatile memory).
27
+ * These memory nodes are called "Targets" while the CPU accessing them
28
+ * is called the "Initiator". Access performance depends on their
29
+ * locality (NUMA platforms) as well as the intrinsic performance
30
+ * of the targets (heterogeneous platforms).
31
+ *
32
+ * The following attributes describe the performance of memory accesses
33
+ * from an Initiator to a memory Target, for instance their latency
34
+ * or bandwidth.
35
+ * Initiators performing these memory accesses are usually some PUs or Cores
36
+ * (described as a CPU set).
37
+ * Hence a Core may choose where to allocate a memory buffer by comparing
38
+ * the attributes of different target memory nodes nearby.
39
+ *
40
+ * There are also some attributes that are system-wide.
41
+ * Their value does not depend on a specific initiator performing
42
+ * an access.
43
+ * The memory node Capacity is an example of such attribute without
44
+ * initiator.
45
+ *
46
+ * One way to use this API is to start with a cpuset describing the Cores where
47
+ * a program is bound. The best target NUMA node for allocating memory in this
48
+ * program on these Cores may be obtained by passing this cpuset as an initiator
49
+ * to hwloc_memattr_get_best_target() with the relevant memory attribute.
50
+ * For instance, if the code is latency limited, use the Latency attribute.
51
+ *
52
+ * A more flexible approach consists in getting the list of local NUMA nodes
53
+ * by passing this cpuset to hwloc_get_local_numanode_objs().
54
+ * Attribute values for these nodes, if any, may then be obtained with
55
+ * hwloc_memattr_get_value() and manually compared with the desired criteria.
56
+ *
57
+ * \note The API also supports specific objects as initiator,
58
+ * but it is currently not used internally by hwloc.
59
+ * Users may for instance use it to provide custom performance
60
+ * values for host memory accesses performed by GPUs.
61
+ *
62
+ * \note The interface actually also accepts targets that are not NUMA nodes.
63
+ * @{
64
+ */
65
+
66
+ /** \brief Memory node attributes. */
67
+ enum hwloc_memattr_id_e {
68
+ /** \brief "Capacity".
69
+ * The capacity is returned in bytes
70
+ * (local_memory attribute in objects).
71
+ *
72
+ * Best capacity nodes are nodes with <b>higher capacity</b>.
73
+ *
74
+ * No initiator is involved when looking at this attribute.
75
+ * The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST.
76
+ */
77
+ HWLOC_MEMATTR_ID_CAPACITY = 0,
78
+
79
+ /** \brief "Locality".
80
+ * The locality is returned as the number of PUs in that locality
81
+ * (e.g. the weight of its cpuset).
82
+ *
83
+ * Best locality nodes are nodes with <b>smaller locality</b>
84
+ * (nodes that are local to very few PUs).
85
+ * Poor locality nodes are nodes with larger locality
86
+ * (nodes that are local to the entire machine).
87
+ *
88
+ * No initiator is involved when looking at this attribute.
89
+ * The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST.
90
+ */
91
+ HWLOC_MEMATTR_ID_LOCALITY = 1,
92
+
93
+ /** \brief "Bandwidth".
94
+ * The bandwidth is returned in MiB/s, as seen from the given initiator location.
95
+ * Best bandwidth nodes are nodes with <b>higher bandwidth</b>.
96
+ * The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST
97
+ * and ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR.
98
+ */
99
+ HWLOC_MEMATTR_ID_BANDWIDTH = 2,
100
+
101
+ /** \brief "Latency".
102
+ * The latency is returned as nanoseconds, as seen from the given initiator location.
103
+ * Best latency nodes are nodes with <b>smaller latency</b>.
104
+ * The corresponding attribute flags are ::HWLOC_MEMATTR_FLAG_LOWER_FIRST
105
+ * and ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR.
106
+ */
107
+ HWLOC_MEMATTR_ID_LATENCY = 3
108
+
109
+ /* TODO read vs write, persistence? */
110
+ };
111
+
112
+ /** \brief A memory attribute identifier.
113
+ * May be either one of ::hwloc_memattr_id_e or a new id returned by hwloc_memattr_register().
114
+ */
115
+ typedef unsigned hwloc_memattr_id_t;
116
+
117
+ /** \brief Return the identifier of the memory attribute with the given name.
118
+ */
119
+ HWLOC_DECLSPEC int
120
+ hwloc_memattr_get_by_name(hwloc_topology_t topology,
121
+ const char *name,
122
+ hwloc_memattr_id_t *id);
123
+
124
+
125
+ /** \brief Type of location. */
126
+ enum hwloc_location_type_e {
127
+ /** \brief Location is given as a cpuset, in the location cpuset union field. \hideinitializer */
128
+ HWLOC_LOCATION_TYPE_CPUSET = 1,
129
+ /** \brief Location is given as an object, in the location object union field. \hideinitializer */
130
+ HWLOC_LOCATION_TYPE_OBJECT = 0
131
+ };
132
+
133
+ /** \brief Where to measure attributes from. */
134
+ struct hwloc_location {
135
+ /** \brief Type of location. */
136
+ enum hwloc_location_type_e type;
137
+ /** \brief Actual location. */
138
+ union hwloc_location_u {
139
+ /** \brief Location as a cpuset, when the location type is ::HWLOC_LOCATION_TYPE_CPUSET. */
140
+ hwloc_cpuset_t cpuset;
141
+ /** \brief Location as an object, when the location type is ::HWLOC_LOCATION_TYPE_OBJECT. */
142
+ hwloc_obj_t object;
143
+ } location;
144
+ };
145
+
146
+
147
+ /** \brief Flags for selecting target NUMA nodes. */
148
+ enum hwloc_local_numanode_flag_e {
149
+ /** \brief Select NUMA nodes whose locality is larger than the given cpuset.
150
+ * For instance, if a single PU (or its cpuset) is given in \p initiator,
151
+ * select all nodes close to the package that contains this PU.
152
+ * \hideinitializer
153
+ */
154
+ HWLOC_LOCAL_NUMANODE_FLAG_LARGER_LOCALITY = (1UL<<0),
155
+
156
+ /** \brief Select NUMA nodes whose locality is smaller than the given cpuset.
157
+ * For instance, if a package (or its cpuset) is given in \p initiator,
158
+ * also select nodes that are attached to only a half of that package.
159
+ * \hideinitializer
160
+ */
161
+ HWLOC_LOCAL_NUMANODE_FLAG_SMALLER_LOCALITY = (1UL<<1),
162
+
163
+ /** \brief Select all NUMA nodes in the topology.
164
+ * The initiator \p initiator is ignored.
165
+ * \hideinitializer
166
+ */
167
+ HWLOC_LOCAL_NUMANODE_FLAG_ALL = (1UL<<2)
168
+ };
169
+
170
+ /** \brief Return an array of local NUMA nodes.
171
+ *
172
+ * By default only select the NUMA nodes whose locality is exactly
173
+ * the given \p location. More nodes may be selected if additional flags
174
+ * are given as a OR'ed set of ::hwloc_local_numanode_flag_e.
175
+ *
176
+ * If \p location is given as an explicit object, its CPU set is used
177
+ * to find NUMA nodes with the corresponding locality.
178
+ * If the object does not have a CPU set (e.g. I/O object), the CPU
179
+ * parent (where the I/O object is attached) is used.
180
+ *
181
+ * On input, \p nr points to the number of nodes that may be stored
182
+ * in the \p nodes array.
183
+ * On output, \p nr will be changed to the number of stored nodes,
184
+ * or the number of nodes that would have been stored if there were
185
+ * enough room.
186
+ *
187
+ * \note Some of these NUMA nodes may not have any memory attribute
188
+ * values and hence not be reported as actual targets in other functions.
189
+ *
190
+ * \note The number of NUMA nodes in the topology (obtained by
191
+ * hwloc_bitmap_weight() on the root object nodeset) may be used
192
+ * to allocate the \p nodes array.
193
+ *
194
+ * \note When an object CPU set is given as locality, for instance a Package,
195
+ * and when flags contain both ::HWLOC_LOCAL_NUMANODE_FLAG_LARGER_LOCALITY
196
+ * and ::HWLOC_LOCAL_NUMANODE_FLAG_SMALLER_LOCALITY,
197
+ * the returned array corresponds to the nodeset of that object.
198
+ */
199
+ HWLOC_DECLSPEC int
200
+ hwloc_get_local_numanode_objs(hwloc_topology_t topology,
201
+ struct hwloc_location *location,
202
+ unsigned *nr,
203
+ hwloc_obj_t *nodes,
204
+ unsigned long flags);
205
+
206
+
207
+
208
+ /** \brief Return an attribute value for a specific target NUMA node.
209
+ *
210
+ * If the attribute does not relate to a specific initiator
211
+ * (it does not have the flag ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR),
212
+ * location \p initiator is ignored and may be \c NULL.
213
+ *
214
+ * \p flags must be \c 0 for now.
215
+ *
216
+ * \note The initiator \p initiator should be of type ::HWLOC_LOCATION_TYPE_CPUSET
217
+ * when refering to accesses performed by CPU cores.
218
+ * ::HWLOC_LOCATION_TYPE_OBJECT is currently unused internally by hwloc,
219
+ * but users may for instance use it to provide custom information about
220
+ * host memory accesses performed by GPUs.
221
+ */
222
+ HWLOC_DECLSPEC int
223
+ hwloc_memattr_get_value(hwloc_topology_t topology,
224
+ hwloc_memattr_id_t attribute,
225
+ hwloc_obj_t target_node,
226
+ struct hwloc_location *initiator,
227
+ unsigned long flags,
228
+ hwloc_uint64_t *value);
229
+
230
+ /** \brief Return the best target NUMA node for the given attribute and initiator.
231
+ *
232
+ * If the attribute does not relate to a specific initiator
233
+ * (it does not have the flag ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR),
234
+ * location \p initiator is ignored and may be \c NULL.
235
+ *
236
+ * If \p value is non \c NULL, the corresponding value is returned there.
237
+ *
238
+ * If multiple targets have the same attribute values, only one is
239
+ * returned (and there is no way to clarify how that one is chosen).
240
+ * Applications that want to detect targets with identical/similar
241
+ * values, or that want to look at values for multiple attributes,
242
+ * should rather get all values using hwloc_memattr_get_value()
243
+ * and manually select the target they consider the best.
244
+ *
245
+ * \p flags must be \c 0 for now.
246
+ *
247
+ * If there are no matching targets, \c -1 is returned with \p errno set to \c ENOENT;
248
+ *
249
+ * \note The initiator \p initiator should be of type ::HWLOC_LOCATION_TYPE_CPUSET
250
+ * when refering to accesses performed by CPU cores.
251
+ * ::HWLOC_LOCATION_TYPE_OBJECT is currently unused internally by hwloc,
252
+ * but users may for instance use it to provide custom information about
253
+ * host memory accesses performed by GPUs.
254
+ */
255
+ HWLOC_DECLSPEC int
256
+ hwloc_memattr_get_best_target(hwloc_topology_t topology,
257
+ hwloc_memattr_id_t attribute,
258
+ struct hwloc_location *initiator,
259
+ unsigned long flags,
260
+ hwloc_obj_t *best_target, hwloc_uint64_t *value);
261
+
262
+ /** \brief Return the best initiator for the given attribute and target NUMA node.
263
+ *
264
+ * If the attribute does not relate to a specific initiator
265
+ * (it does not have the flag ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR),
266
+ * \c -1 is returned and \p errno is set to \c EINVAL.
267
+ *
268
+ * If \p value is non \c NULL, the corresponding value is returned there.
269
+ *
270
+ * If multiple initiators have the same attribute values, only one is
271
+ * returned (and there is no way to clarify how that one is chosen).
272
+ * Applications that want to detect initiators with identical/similar
273
+ * values, or that want to look at values for multiple attributes,
274
+ * should rather get all values using hwloc_memattr_get_value()
275
+ * and manually select the initiator they consider the best.
276
+ *
277
+ * The returned initiator should not be modified or freed,
278
+ * it belongs to the topology.
279
+ *
280
+ * \p flags must be \c 0 for now.
281
+ *
282
+ * If there are no matching initiators, \c -1 is returned with \p errno set to \c ENOENT;
283
+ */
284
+ HWLOC_DECLSPEC int
285
+ hwloc_memattr_get_best_initiator(hwloc_topology_t topology,
286
+ hwloc_memattr_id_t attribute,
287
+ hwloc_obj_t target,
288
+ unsigned long flags,
289
+ struct hwloc_location *best_initiator, hwloc_uint64_t *value);
290
+
291
+ /** @} */
292
+
293
+
294
+ /** \defgroup hwlocality_memattrs_manage Managing memory attributes
295
+ * @{
296
+ */
297
+
298
+ /** \brief Return the name of a memory attribute.
299
+ */
300
+ HWLOC_DECLSPEC int
301
+ hwloc_memattr_get_name(hwloc_topology_t topology,
302
+ hwloc_memattr_id_t attribute,
303
+ const char **name);
304
+
305
+ /** \brief Return the flags of the given attribute.
306
+ *
307
+ * Flags are a OR'ed set of ::hwloc_memattr_flag_e.
308
+ */
309
+ HWLOC_DECLSPEC int
310
+ hwloc_memattr_get_flags(hwloc_topology_t topology,
311
+ hwloc_memattr_id_t attribute,
312
+ unsigned long *flags);
313
+
314
+ /** \brief Memory attribute flags.
315
+ * Given to hwloc_memattr_register() and returned by hwloc_memattr_get_flags().
316
+ */
317
+ enum hwloc_memattr_flag_e {
318
+ /** \brief The best nodes for this memory attribute are those with the higher values.
319
+ * For instance Bandwidth.
320
+ */
321
+ HWLOC_MEMATTR_FLAG_HIGHER_FIRST = (1UL<<0),
322
+ /** \brief The best nodes for this memory attribute are those with the lower values.
323
+ * For instance Latency.
324
+ */
325
+ HWLOC_MEMATTR_FLAG_LOWER_FIRST = (1UL<<1),
326
+ /** \brief The value returned for this memory attribute depends on the given initiator.
327
+ * For instance Bandwidth and Latency, but not Capacity.
328
+ */
329
+ HWLOC_MEMATTR_FLAG_NEED_INITIATOR = (1UL<<2)
330
+ };
331
+
332
+ /** \brief Register a new memory attribute.
333
+ *
334
+ * Add a specific memory attribute that is not defined in ::hwloc_memattr_id_e.
335
+ * Flags are a OR'ed set of ::hwloc_memattr_flag_e. It must contain at least
336
+ * one of ::HWLOC_MEMATTR_FLAG_HIGHER_FIRST or ::HWLOC_MEMATTR_FLAG_LOWER_FIRST.
337
+ */
338
+ HWLOC_DECLSPEC int
339
+ hwloc_memattr_register(hwloc_topology_t topology,
340
+ const char *name,
341
+ unsigned long flags,
342
+ hwloc_memattr_id_t *id);
343
+
344
+ /** \brief Set an attribute value for a specific target NUMA node.
345
+ *
346
+ * If the attribute does not relate to a specific initiator
347
+ * (it does not have the flag ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR),
348
+ * location \p initiator is ignored and may be \c NULL.
349
+ *
350
+ * The initiator will be copied into the topology,
351
+ * the caller should free anything allocated to store the initiator,
352
+ * for instance the cpuset.
353
+ *
354
+ * \p flags must be \c 0 for now.
355
+ *
356
+ * \note The initiator \p initiator should be of type ::HWLOC_LOCATION_TYPE_CPUSET
357
+ * when referring to accesses performed by CPU cores.
358
+ * ::HWLOC_LOCATION_TYPE_OBJECT is currently unused internally by hwloc,
359
+ * but users may for instance use it to provide custom information about
360
+ * host memory accesses performed by GPUs.
361
+ */
362
+ HWLOC_DECLSPEC int
363
+ hwloc_memattr_set_value(hwloc_topology_t topology,
364
+ hwloc_memattr_id_t attribute,
365
+ hwloc_obj_t target_node,
366
+ struct hwloc_location *initiator,
367
+ unsigned long flags,
368
+ hwloc_uint64_t value);
369
+
370
+ /** \brief Return the target NUMA nodes that have some values for a given attribute.
371
+ *
372
+ * Return targets for the given attribute in the \p targets array
373
+ * (for the given initiator if any).
374
+ * If \p values is not \c NULL, the corresponding attribute values
375
+ * are stored in the array it points to.
376
+ *
377
+ * On input, \p nr points to the number of targets that may be stored
378
+ * in the array \p targets (and \p values).
379
+ * On output, \p nr points to the number of targets (and values) that
380
+ * were actually found, even if some of them couldn't be stored in the array.
381
+ * Targets that couldn't be stored are ignored, but the function still
382
+ * returns success (\c 0). The caller may find out by comparing the value pointed
383
+ * by \p nr before and after the function call.
384
+ *
385
+ * The returned targets should not be modified or freed,
386
+ * they belong to the topology.
387
+ *
388
+ * Argument \p initiator is ignored if the attribute does not relate to a specific
389
+ * initiator (it does not have the flag ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR).
390
+ * Otherwise \p initiator may be non \c NULL to report only targets
391
+ * that have a value for that initiator.
392
+ *
393
+ * \p flags must be \c 0 for now.
394
+ *
395
+ * \note This function is meant for tools and debugging (listing internal information)
396
+ * rather than for application queries. Applications should rather select useful
397
+ * NUMA nodes with hwloc_get_local_numanode_objs() and then look at their attribute
398
+ * values.
399
+ *
400
+ * \note The initiator \p initiator should be of type ::HWLOC_LOCATION_TYPE_CPUSET
401
+ * when referring to accesses performed by CPU cores.
402
+ * ::HWLOC_LOCATION_TYPE_OBJECT is currently unused internally by hwloc,
403
+ * but users may for instance use it to provide custom information about
404
+ * host memory accesses performed by GPUs.
405
+ */
406
+ HWLOC_DECLSPEC int
407
+ hwloc_memattr_get_targets(hwloc_topology_t topology,
408
+ hwloc_memattr_id_t attribute,
409
+ struct hwloc_location *initiator,
410
+ unsigned long flags,
411
+ unsigned *nr, hwloc_obj_t *targets, hwloc_uint64_t *values);
412
+
413
+ /** \brief Return the initiators that have values for a given attribute for a specific target NUMA node.
414
+ *
415
+ * Return initiators for the given attribute and target node in the
416
+ * \p initiators array.
417
+ * If \p values is not \c NULL, the corresponding attribute values
418
+ * are stored in the array it points to.
419
+ *
420
+ * On input, \p nr points to the number of initiators that may be stored
421
+ * in the array \p initiators (and \p values).
422
+ * On output, \p nr points to the number of initiators (and values) that
423
+ * were actually found, even if some of them couldn't be stored in the array.
424
+ * Initiators that couldn't be stored are ignored, but the function still
425
+ * returns success (\c 0). The caller may find out by comparing the value pointed
426
+ * by \p nr before and after the function call.
427
+ *
428
+ * The returned initiators should not be modified or freed,
429
+ * they belong to the topology.
430
+ *
431
+ * \p flags must be \c 0 for now.
432
+ *
433
+ * If the attribute does not relate to a specific initiator
434
+ * (it does not have the flag ::HWLOC_MEMATTR_FLAG_NEED_INITIATOR),
435
+ * no initiator is returned.
436
+ *
437
+ * \note This function is meant for tools and debugging (listing internal information)
438
+ * rather than for application queries. Applications should rather select useful
439
+ * NUMA nodes with hwloc_get_local_numanode_objs() and then look at their attribute
440
+ * values for some relevant initiators.
441
+ */
442
+ HWLOC_DECLSPEC int
443
+ hwloc_memattr_get_initiators(hwloc_topology_t topology,
444
+ hwloc_memattr_id_t attribute,
445
+ hwloc_obj_t target_node,
446
+ unsigned long flags,
447
+ unsigned *nr, struct hwloc_location *initiators, hwloc_uint64_t *values);
448
+ /** @} */
449
+
450
+ #ifdef __cplusplus
451
+ } /* extern "C" */
452
+ #endif
453
+
454
+
455
+ #endif /* HWLOC_MEMATTR_H */
deps/exla/cache/xla_extension/include/include/hwloc/plugins.h ADDED
@@ -0,0 +1,689 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2013-2021 Inria. All rights reserved.
3
+ * Copyright © 2016 Cisco Systems, Inc. All rights reserved.
4
+ * See COPYING in top-level directory.
5
+ */
6
+
7
+ #ifndef HWLOC_PLUGINS_H
8
+ #define HWLOC_PLUGINS_H
9
+
10
+ /** \file
11
+ * \brief Public interface for building hwloc plugins.
12
+ */
13
+
14
+ struct hwloc_backend;
15
+
16
+ #include "hwloc.h"
17
+
18
+ #ifdef HWLOC_INSIDE_PLUGIN
19
+ /* needed for hwloc_plugin_check_namespace() */
20
+ #ifdef HWLOC_HAVE_LTDL
21
+ #include <ltdl.h>
22
+ #else
23
+ #include <dlfcn.h>
24
+ #endif
25
+ #endif
26
+
27
+
28
+
29
+ /** \defgroup hwlocality_disc_components Components and Plugins: Discovery components
30
+ *
31
+ * \note These structures and functions may change when ::HWLOC_COMPONENT_ABI is modified.
32
+ *
33
+ * @{
34
+ */
35
+
36
+ /** \brief Discovery component structure
37
+ *
38
+ * This is the major kind of components, taking care of the discovery.
39
+ * They are registered by generic components, either statically-built or as plugins.
40
+ */
41
+ struct hwloc_disc_component {
42
+ /** \brief Name.
43
+ * If this component is built as a plugin, this name does not have to match the plugin filename.
44
+ */
45
+ const char *name;
46
+
47
+ /** \brief Discovery phases performed by this component.
48
+ * OR'ed set of ::hwloc_disc_phase_t
49
+ */
50
+ unsigned phases;
51
+
52
+ /** \brief Component phases to exclude, as an OR'ed set of ::hwloc_disc_phase_t.
53
+ *
54
+ * For a GLOBAL component, this usually includes all other phases (\c ~UL).
55
+ *
56
+ * Other components only exclude types that may bring conflicting
57
+ * topology information. MISC components should likely not be excluded
58
+ * since they usually bring non-primary additional information.
59
+ */
60
+ unsigned excluded_phases;
61
+
62
+ /** \brief Instantiate callback to create a backend from the component.
63
+ * Parameters data1, data2, data3 are NULL except for components
64
+ * that have special enabling routines such as hwloc_topology_set_xml(). */
65
+ struct hwloc_backend * (*instantiate)(struct hwloc_topology *topology, struct hwloc_disc_component *component, unsigned excluded_phases, const void *data1, const void *data2, const void *data3);
66
+
67
+ /** \brief Component priority.
68
+ * Used to sort topology->components, higher priority first.
69
+ * Also used to decide between two components with the same name.
70
+ *
71
+ * Usual values are
72
+ * 50 for native OS (or platform) components,
73
+ * 45 for x86,
74
+ * 40 for no-OS fallback,
75
+ * 30 for global components (xml, synthetic),
76
+ * 20 for pci,
77
+ * 10 for other misc components (opencl etc.).
78
+ */
79
+ unsigned priority;
80
+
81
+ /** \brief Enabled by default.
82
+ * If unset, if will be disabled unless explicitly requested.
83
+ */
84
+ unsigned enabled_by_default;
85
+
86
+ /** \private Used internally to list components by priority on topology->components
87
+ * (the component structure is usually read-only,
88
+ * the core copies it before using this field for queueing)
89
+ */
90
+ struct hwloc_disc_component * next;
91
+ };
92
+
93
+ /** @} */
94
+
95
+
96
+
97
+
98
+ /** \defgroup hwlocality_disc_backends Components and Plugins: Discovery backends
99
+ *
100
+ * \note These structures and functions may change when ::HWLOC_COMPONENT_ABI is modified.
101
+ *
102
+ * @{
103
+ */
104
+
105
+ /** \brief Discovery phase */
106
+ typedef enum hwloc_disc_phase_e {
107
+ /** \brief xml or synthetic, platform-specific components such as bgq.
108
+ * Discovers everything including CPU, memory, I/O and everything else.
109
+ * A component with a Global phase usually excludes all other phases.
110
+ * \hideinitializer */
111
+ HWLOC_DISC_PHASE_GLOBAL = (1U<<0),
112
+
113
+ /** \brief CPU discovery.
114
+ * \hideinitializer */
115
+ HWLOC_DISC_PHASE_CPU = (1U<<1),
116
+
117
+ /** \brief Attach memory to existing CPU objects.
118
+ * \hideinitializer */
119
+ HWLOC_DISC_PHASE_MEMORY = (1U<<2),
120
+
121
+ /** \brief Attach PCI devices and bridges to existing CPU objects.
122
+ * \hideinitializer */
123
+ HWLOC_DISC_PHASE_PCI = (1U<<3),
124
+
125
+ /** \brief I/O discovery that requires PCI devices (OS devices such as OpenCL, CUDA, etc.).
126
+ * \hideinitializer */
127
+ HWLOC_DISC_PHASE_IO = (1U<<4),
128
+
129
+ /** \brief Misc objects that gets added below anything else.
130
+ * \hideinitializer */
131
+ HWLOC_DISC_PHASE_MISC = (1U<<5),
132
+
133
+ /** \brief Annotating existing objects, adding distances, etc.
134
+ * \hideinitializer */
135
+ HWLOC_DISC_PHASE_ANNOTATE = (1U<<6),
136
+
137
+ /** \brief Final tweaks to a ready-to-use topology.
138
+ * This phase runs once the topology is loaded, before it is returned to the topology.
139
+ * Hence it may only use the main hwloc API for modifying the topology,
140
+ * for instance by restricting it, adding info attributes, etc.
141
+ * \hideinitializer */
142
+ HWLOC_DISC_PHASE_TWEAK = (1U<<7)
143
+ } hwloc_disc_phase_t;
144
+
145
+ /** \brief Discovery status flags */
146
+ enum hwloc_disc_status_flag_e {
147
+ /** \brief The sets of allowed resources were already retrieved \hideinitializer */
148
+ HWLOC_DISC_STATUS_FLAG_GOT_ALLOWED_RESOURCES = (1UL<<1)
149
+ };
150
+
151
+ /** \brief Discovery status structure
152
+ *
153
+ * Used by the core and backends to inform about what has been/is being done
154
+ * during the discovery process.
155
+ */
156
+ struct hwloc_disc_status {
157
+ /** \brief The current discovery phase that is performed.
158
+ * Must match one of the phases in the component phases field.
159
+ */
160
+ hwloc_disc_phase_t phase;
161
+
162
+ /** \brief Dynamically excluded phases.
163
+ * If a component decides during discovery that some phases are no longer needed.
164
+ */
165
+ unsigned excluded_phases;
166
+
167
+ /** \brief OR'ed set of hwloc_disc_status_flag_e */
168
+ unsigned long flags;
169
+ };
170
+
171
+ /** \brief Discovery backend structure
172
+ *
173
+ * A backend is the instantiation of a discovery component.
174
+ * When a component gets enabled for a topology,
175
+ * its instantiate() callback creates a backend.
176
+ *
177
+ * hwloc_backend_alloc() initializes all fields to default values
178
+ * that the component may change (except "component" and "next")
179
+ * before enabling the backend with hwloc_backend_enable().
180
+ *
181
+ * Most backends assume that the topology is_thissystem flag is
182
+ * set because they talk to the underlying operating system.
183
+ * However they may still be used in topologies without the
184
+ * is_thissystem flag for debugging reasons.
185
+ * In practice, they are usually auto-disabled in such cases
186
+ * (excluded by xml or synthetic backends, or by environment
187
+ * variables when changing the Linux fsroot or the x86 cpuid path).
188
+ */
189
+ struct hwloc_backend {
190
+ /** \private Reserved for the core, set by hwloc_backend_alloc() */
191
+ struct hwloc_disc_component * component;
192
+ /** \private Reserved for the core, set by hwloc_backend_enable() */
193
+ struct hwloc_topology * topology;
194
+ /** \private Reserved for the core. Set to 1 if forced through envvar, 0 otherwise. */
195
+ int envvar_forced;
196
+ /** \private Reserved for the core. Used internally to list backends topology->backends. */
197
+ struct hwloc_backend * next;
198
+
199
+ /** \brief Discovery phases performed by this component, possibly without some of them if excluded by other components.
200
+ * OR'ed set of ::hwloc_disc_phase_t
201
+ */
202
+ unsigned phases;
203
+
204
+ /** \brief Backend flags, currently always 0. */
205
+ unsigned long flags;
206
+
207
+ /** \brief Backend-specific 'is_thissystem' property.
208
+ * Set to 0 if the backend disables the thissystem flag for this topology
209
+ * (e.g. loading from xml or synthetic string,
210
+ * or using a different fsroot on Linux, or a x86 CPUID dump).
211
+ * Set to -1 if the backend doesn't care (default).
212
+ */
213
+ int is_thissystem;
214
+
215
+ /** \brief Backend private data, or NULL if none. */
216
+ void * private_data;
217
+ /** \brief Callback for freeing the private_data.
218
+ * May be NULL.
219
+ */
220
+ void (*disable)(struct hwloc_backend *backend);
221
+
222
+ /** \brief Main discovery callback.
223
+ * returns -1 on error, either because it couldn't add its objects ot the existing topology,
224
+ * or because of an actual discovery/gathering failure.
225
+ * May be NULL.
226
+ */
227
+ int (*discover)(struct hwloc_backend *backend, struct hwloc_disc_status *status);
228
+
229
+ /** \brief Callback to retrieve the locality of a PCI object.
230
+ * Called by the PCI core when attaching PCI hierarchy to CPU objects.
231
+ * May be NULL.
232
+ */
233
+ int (*get_pci_busid_cpuset)(struct hwloc_backend *backend, struct hwloc_pcidev_attr_s *busid, hwloc_bitmap_t cpuset);
234
+ };
235
+
236
+ /** \brief Allocate a backend structure, set good default values, initialize backend->component and topology, etc.
237
+ * The caller will then modify whatever needed, and call hwloc_backend_enable().
238
+ */
239
+ HWLOC_DECLSPEC struct hwloc_backend * hwloc_backend_alloc(struct hwloc_topology *topology, struct hwloc_disc_component *component);
240
+
241
+ /** \brief Enable a previously allocated and setup backend. */
242
+ HWLOC_DECLSPEC int hwloc_backend_enable(struct hwloc_backend *backend);
243
+
244
+ /** @} */
245
+
246
+
247
+
248
+
249
+ /** \defgroup hwlocality_generic_components Components and Plugins: Generic components
250
+ *
251
+ * \note These structures and functions may change when ::HWLOC_COMPONENT_ABI is modified.
252
+ *
253
+ * @{
254
+ */
255
+
256
+ /** \brief Generic component type */
257
+ typedef enum hwloc_component_type_e {
258
+ /** \brief The data field must point to a struct hwloc_disc_component. */
259
+ HWLOC_COMPONENT_TYPE_DISC,
260
+
261
+ /** \brief The data field must point to a struct hwloc_xml_component. */
262
+ HWLOC_COMPONENT_TYPE_XML
263
+ } hwloc_component_type_t;
264
+
265
+ /** \brief Generic component structure
266
+ *
267
+ * Generic components structure, either statically listed by configure in static-components.h
268
+ * or dynamically loaded as a plugin.
269
+ */
270
+ struct hwloc_component {
271
+ /** \brief Component ABI version, set to ::HWLOC_COMPONENT_ABI */
272
+ unsigned abi;
273
+
274
+ /** \brief Process-wide component initialization callback.
275
+ *
276
+ * This optional callback is called when the component is registered
277
+ * to the hwloc core (after loading the plugin).
278
+ *
279
+ * When the component is built as a plugin, this callback
280
+ * should call hwloc_check_plugin_namespace()
281
+ * and return an negative error code on error.
282
+ *
283
+ * \p flags is always 0 for now.
284
+ *
285
+ * \return 0 on success, or a negative code on error.
286
+ *
287
+ * \note If the component uses ltdl for loading its own plugins,
288
+ * it should load/unload them only in init() and finalize(),
289
+ * to avoid race conditions with hwloc's use of ltdl.
290
+ */
291
+ int (*init)(unsigned long flags);
292
+
293
+ /** \brief Process-wide component termination callback.
294
+ *
295
+ * This optional callback is called after unregistering the component
296
+ * from the hwloc core (before unloading the plugin).
297
+ *
298
+ * \p flags is always 0 for now.
299
+ *
300
+ * \note If the component uses ltdl for loading its own plugins,
301
+ * it should load/unload them only in init() and finalize(),
302
+ * to avoid race conditions with hwloc's use of ltdl.
303
+ */
304
+ void (*finalize)(unsigned long flags);
305
+
306
+ /** \brief Component type */
307
+ hwloc_component_type_t type;
308
+
309
+ /** \brief Component flags, unused for now */
310
+ unsigned long flags;
311
+
312
+ /** \brief Component data, pointing to a struct hwloc_disc_component or struct hwloc_xml_component. */
313
+ void * data;
314
+ };
315
+
316
+ /** @} */
317
+
318
+
319
+
320
+
321
+ /** \defgroup hwlocality_components_core_funcs Components and Plugins: Core functions to be used by components
322
+ *
323
+ * \note These structures and functions may change when ::HWLOC_COMPONENT_ABI is modified.
324
+ *
325
+ * @{
326
+ */
327
+
328
+ /** \brief Check whether error messages are hidden.
329
+ *
330
+ * Callers should print critical error messages
331
+ * (e.g. invalid hw topo info, invalid config)
332
+ * only if this function returns strictly less than 2.
333
+ *
334
+ * Callers should print non-critical error messages
335
+ * (e.g. failure to initialize CUDA)
336
+ * if this function returns 0.
337
+ *
338
+ * This function return 1 by default (show critical only),
339
+ * 0 in lstopo (show all),
340
+ * or anything set in HWLOC_HIDE_ERRORS in the environment.
341
+ */
342
+ HWLOC_DECLSPEC int hwloc_hide_errors(void);
343
+
344
+ /** \brief Add an object to the topology.
345
+ *
346
+ * Insert new object \p obj in the topology starting under existing object \p root
347
+ * (if \c NULL, the topology root object is used).
348
+ *
349
+ * It is sorted along the tree of other objects according to the inclusion of
350
+ * cpusets, to eventually be added as a child of the smallest object including
351
+ * this object.
352
+ *
353
+ * If the cpuset is empty, the type of the object (and maybe some attributes)
354
+ * must be enough to find where to insert the object. This is especially true
355
+ * for NUMA nodes with memory and no CPUs.
356
+ *
357
+ * The given object should not have children.
358
+ *
359
+ * This shall only be called before levels are built.
360
+ *
361
+ * The caller should check whether the object type is filtered-out before calling this function.
362
+ *
363
+ * The topology cpuset/nodesets will be enlarged to include the object sets.
364
+ *
365
+ * \p reason is a unique string identifying where and why this insertion call was performed
366
+ * (it will be displayed in case of internal insertion error).
367
+ *
368
+ * Returns the object on success.
369
+ * Returns NULL and frees obj on error.
370
+ * Returns another object and frees obj if it was merged with an identical pre-existing object.
371
+ */
372
+ HWLOC_DECLSPEC hwloc_obj_t
373
+ hwloc__insert_object_by_cpuset(struct hwloc_topology *topology, hwloc_obj_t root,
374
+ hwloc_obj_t obj, const char *reason);
375
+
376
+ /** \brief Insert an object somewhere in the topology.
377
+ *
378
+ * It is added as the last child of the given parent.
379
+ * The cpuset is completely ignored, so strange objects such as I/O devices should
380
+ * preferably be inserted with this.
381
+ *
382
+ * When used for "normal" children with cpusets (when importing from XML
383
+ * when duplicating a topology), the caller should make sure that:
384
+ * - children are inserted in order,
385
+ * - children cpusets do not intersect.
386
+ *
387
+ * The given object may have normal, I/O or Misc children, as long as they are in order as well.
388
+ * These children must have valid parent and next_sibling pointers.
389
+ *
390
+ * The caller should check whether the object type is filtered-out before calling this function.
391
+ */
392
+ HWLOC_DECLSPEC void hwloc_insert_object_by_parent(struct hwloc_topology *topology, hwloc_obj_t parent, hwloc_obj_t obj);
393
+
394
+ /** \brief Allocate and initialize an object of the given type and physical index.
395
+ *
396
+ * If \p os_index is unknown or irrelevant, use \c HWLOC_UNKNOWN_INDEX.
397
+ */
398
+ HWLOC_DECLSPEC hwloc_obj_t hwloc_alloc_setup_object(hwloc_topology_t topology, hwloc_obj_type_t type, unsigned os_index);
399
+
400
+ /** \brief Setup object cpusets/nodesets by OR'ing its children.
401
+ *
402
+ * Used when adding an object late in the topology.
403
+ * Will update the new object by OR'ing all its new children sets.
404
+ *
405
+ * Used when PCI backend adds a hostbridge parent, when distances
406
+ * add a new Group, etc.
407
+ */
408
+ HWLOC_DECLSPEC int hwloc_obj_add_children_sets(hwloc_obj_t obj);
409
+
410
+ /** \brief Request a reconnection of children and levels in the topology.
411
+ *
412
+ * May be used by backends during discovery if they need arrays or lists
413
+ * of object within levels or children to be fully connected.
414
+ *
415
+ * \p flags is currently unused, must 0.
416
+ */
417
+ HWLOC_DECLSPEC int hwloc_topology_reconnect(hwloc_topology_t topology, unsigned long flags __hwloc_attribute_unused);
418
+
419
+ /** \brief Make sure that plugins can lookup core symbols.
420
+ *
421
+ * This is a sanity check to avoid lazy-lookup failures when libhwloc
422
+ * is loaded within a plugin, and later tries to load its own plugins.
423
+ * This may fail (and abort the program) if libhwloc symbols are in a
424
+ * private namespace.
425
+ *
426
+ * \return 0 on success.
427
+ * \return -1 if the plugin cannot be successfully loaded. The caller
428
+ * plugin init() callback should return a negative error code as well.
429
+ *
430
+ * Plugins should call this function in their init() callback to avoid
431
+ * later crashes if lazy symbol resolution is used by the upper layer that
432
+ * loaded hwloc (e.g. OpenCL implementations using dlopen with RTLD_LAZY).
433
+ *
434
+ * \note The build system must define HWLOC_INSIDE_PLUGIN if and only if
435
+ * building the caller as a plugin.
436
+ *
437
+ * \note This function should remain inline so plugins can call it even
438
+ * when they cannot find libhwloc symbols.
439
+ */
440
+ static __hwloc_inline int
441
+ hwloc_plugin_check_namespace(const char *pluginname __hwloc_attribute_unused, const char *symbol __hwloc_attribute_unused)
442
+ {
443
+ #ifdef HWLOC_INSIDE_PLUGIN
444
+ void *sym;
445
+ #ifdef HWLOC_HAVE_LTDL
446
+ lt_dlhandle handle = lt_dlopen(NULL);
447
+ #else
448
+ void *handle = dlopen(NULL, RTLD_NOW|RTLD_LOCAL);
449
+ #endif
450
+ if (!handle)
451
+ /* cannot check, assume things will work */
452
+ return 0;
453
+ #ifdef HWLOC_HAVE_LTDL
454
+ sym = lt_dlsym(handle, symbol);
455
+ lt_dlclose(handle);
456
+ #else
457
+ sym = dlsym(handle, symbol);
458
+ dlclose(handle);
459
+ #endif
460
+ if (!sym) {
461
+ static int verboseenv_checked = 0;
462
+ static int verboseenv_value = 0;
463
+ if (!verboseenv_checked) {
464
+ const char *verboseenv = getenv("HWLOC_PLUGINS_VERBOSE");
465
+ verboseenv_value = verboseenv ? atoi(verboseenv) : 0;
466
+ verboseenv_checked = 1;
467
+ }
468
+ if (verboseenv_value)
469
+ fprintf(stderr, "Plugin `%s' disabling itself because it cannot find the `%s' core symbol.\n",
470
+ pluginname, symbol);
471
+ return -1;
472
+ }
473
+ #endif /* HWLOC_INSIDE_PLUGIN */
474
+ return 0;
475
+ }
476
+
477
+ /** @} */
478
+
479
+
480
+
481
+
482
+ /** \defgroup hwlocality_components_filtering Components and Plugins: Filtering objects
483
+ *
484
+ * \note These structures and functions may change when ::HWLOC_COMPONENT_ABI is modified.
485
+ *
486
+ * @{
487
+ */
488
+
489
+ /** \brief Check whether the given PCI device classid is important.
490
+ *
491
+ * \return 1 if important, 0 otherwise.
492
+ */
493
+ static __hwloc_inline int
494
+ hwloc_filter_check_pcidev_subtype_important(unsigned classid)
495
+ {
496
+ unsigned baseclass = classid >> 8;
497
+ return (baseclass == 0x03 /* PCI_BASE_CLASS_DISPLAY */
498
+ || baseclass == 0x02 /* PCI_BASE_CLASS_NETWORK */
499
+ || baseclass == 0x01 /* PCI_BASE_CLASS_STORAGE */
500
+ || baseclass == 0x00 /* Unclassified, for Atos/Bull BXI */
501
+ || baseclass == 0x0b /* PCI_BASE_CLASS_PROCESSOR */
502
+ || classid == 0x0c04 /* PCI_CLASS_SERIAL_FIBER */
503
+ || classid == 0x0c06 /* PCI_CLASS_SERIAL_INFINIBAND */
504
+ || baseclass == 0x06 /* PCI_BASE_CLASS_BRIDGE with non-PCI downstream. the core will drop the useless ones later */
505
+ || baseclass == 0x12 /* Processing Accelerators */);
506
+ }
507
+
508
+ /** \brief Check whether the given OS device subtype is important.
509
+ *
510
+ * \return 1 if important, 0 otherwise.
511
+ */
512
+ static __hwloc_inline int
513
+ hwloc_filter_check_osdev_subtype_important(hwloc_obj_osdev_type_t subtype)
514
+ {
515
+ return (subtype != HWLOC_OBJ_OSDEV_DMA);
516
+ }
517
+
518
+ /** \brief Check whether a non-I/O object type should be filtered-out.
519
+ *
520
+ * Cannot be used for I/O objects.
521
+ *
522
+ * \return 1 if the object type should be kept, 0 otherwise.
523
+ */
524
+ static __hwloc_inline int
525
+ hwloc_filter_check_keep_object_type(hwloc_topology_t topology, hwloc_obj_type_t type)
526
+ {
527
+ enum hwloc_type_filter_e filter = HWLOC_TYPE_FILTER_KEEP_NONE;
528
+ hwloc_topology_get_type_filter(topology, type, &filter);
529
+ assert(filter != HWLOC_TYPE_FILTER_KEEP_IMPORTANT); /* IMPORTANT only used for I/O */
530
+ return filter == HWLOC_TYPE_FILTER_KEEP_NONE ? 0 : 1;
531
+ }
532
+
533
+ /** \brief Check whether the given object should be filtered-out.
534
+ *
535
+ * \return 1 if the object type should be kept, 0 otherwise.
536
+ */
537
+ static __hwloc_inline int
538
+ hwloc_filter_check_keep_object(hwloc_topology_t topology, hwloc_obj_t obj)
539
+ {
540
+ hwloc_obj_type_t type = obj->type;
541
+ enum hwloc_type_filter_e filter = HWLOC_TYPE_FILTER_KEEP_NONE;
542
+ hwloc_topology_get_type_filter(topology, type, &filter);
543
+ if (filter == HWLOC_TYPE_FILTER_KEEP_NONE)
544
+ return 0;
545
+ if (filter == HWLOC_TYPE_FILTER_KEEP_IMPORTANT) {
546
+ if (type == HWLOC_OBJ_PCI_DEVICE)
547
+ return hwloc_filter_check_pcidev_subtype_important(obj->attr->pcidev.class_id);
548
+ if (type == HWLOC_OBJ_OS_DEVICE)
549
+ return hwloc_filter_check_osdev_subtype_important(obj->attr->osdev.type);
550
+ }
551
+ return 1;
552
+ }
553
+
554
+ /** @} */
555
+
556
+
557
+
558
+
559
+ /** \defgroup hwlocality_components_pcidisc Components and Plugins: helpers for PCI discovery
560
+ *
561
+ * \note These structures and functions may change when ::HWLOC_COMPONENT_ABI is modified.
562
+ *
563
+ * @{
564
+ */
565
+
566
+ /** \brief Return the offset of the given capability in the PCI config space buffer
567
+ *
568
+ * This function requires a 256-bytes config space. Unknown/unavailable bytes should be set to 0xff.
569
+ */
570
+ HWLOC_DECLSPEC unsigned hwloc_pcidisc_find_cap(const unsigned char *config, unsigned cap);
571
+
572
+ /** \brief Fill linkspeed by reading the PCI config space where PCI_CAP_ID_EXP is at position offset.
573
+ *
574
+ * Needs 20 bytes of EXP capability block starting at offset in the config space
575
+ * for registers up to link status.
576
+ */
577
+ HWLOC_DECLSPEC int hwloc_pcidisc_find_linkspeed(const unsigned char *config, unsigned offset, float *linkspeed);
578
+
579
+ /** \brief Return the hwloc object type (PCI device or Bridge) for the given class and configuration space.
580
+ *
581
+ * This function requires 16 bytes of common configuration header at the beginning of config.
582
+ */
583
+ HWLOC_DECLSPEC hwloc_obj_type_t hwloc_pcidisc_check_bridge_type(unsigned device_class, const unsigned char *config);
584
+
585
+ /** \brief Fills the attributes of the given PCI bridge using the given PCI config space.
586
+ *
587
+ * This function requires 32 bytes of common configuration header at the beginning of config.
588
+ *
589
+ * Returns -1 and destroys /p obj if bridge fields are invalid.
590
+ */
591
+ HWLOC_DECLSPEC int hwloc_pcidisc_find_bridge_buses(unsigned domain, unsigned bus, unsigned dev, unsigned func,
592
+ unsigned *secondary_busp, unsigned *subordinate_busp,
593
+ const unsigned char *config);
594
+
595
+ /** \brief Insert a PCI object in the given PCI tree by looking at PCI bus IDs.
596
+ *
597
+ * If \p treep points to \c NULL, the new object is inserted there.
598
+ */
599
+ HWLOC_DECLSPEC void hwloc_pcidisc_tree_insert_by_busid(struct hwloc_obj **treep, struct hwloc_obj *obj);
600
+
601
+ /** \brief Add some hostbridges on top of the given tree of PCI objects and attach them to the topology.
602
+ *
603
+ * Other backends may lookup PCI objects or localities (for instance to attach OS devices)
604
+ * by using hwloc_pcidisc_find_by_busid() or hwloc_pcidisc_find_busid_parent().
605
+ */
606
+ HWLOC_DECLSPEC int hwloc_pcidisc_tree_attach(struct hwloc_topology *topology, struct hwloc_obj *tree);
607
+
608
+ /** @} */
609
+
610
+
611
+
612
+
613
+ /** \defgroup hwlocality_components_pcifind Components and Plugins: finding PCI objects during other discoveries
614
+ *
615
+ * \note These structures and functions may change when ::HWLOC_COMPONENT_ABI is modified.
616
+ *
617
+ * @{
618
+ */
619
+
620
+ /** \brief Find the object or a parent of a PCI bus ID.
621
+ *
622
+ * When attaching a new object (typically an OS device) whose locality
623
+ * is specified by PCI bus ID, this function returns the PCI object
624
+ * to use as a parent for attaching.
625
+ *
626
+ * If the exact PCI device with this bus ID exists, it is returned.
627
+ * Otherwise (for instance if it was filtered out), the function returns
628
+ * another object with similar locality (for instance a parent bridge,
629
+ * or the local CPU Package).
630
+ */
631
+ HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_find_parent_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
632
+
633
+ /** \brief Find the PCI device or bridge matching a PCI bus ID exactly.
634
+ *
635
+ * This is useful for adding specific information about some objects
636
+ * based on their PCI id. When it comes to attaching objects based on
637
+ * PCI locality, hwloc_pci_find_parent_by_busid() should be preferred.
638
+ */
639
+ HWLOC_DECLSPEC struct hwloc_obj * hwloc_pci_find_by_busid(struct hwloc_topology *topology, unsigned domain, unsigned bus, unsigned dev, unsigned func);
640
+
641
+ /** \brief Handle to a new distances structure during its addition to the topology. */
642
+ typedef void * hwloc_backend_distances_add_handle_t;
643
+
644
+ /** \brief Create a new empty distances structure.
645
+ *
646
+ * This is identical to hwloc_distances_add_create()
647
+ * but this variant is designed for backend inserting
648
+ * distances during topology discovery.
649
+ */
650
+ HWLOC_DECLSPEC hwloc_backend_distances_add_handle_t
651
+ hwloc_backend_distances_add_create(hwloc_topology_t topology,
652
+ const char *name, unsigned long kind,
653
+ unsigned long flags);
654
+
655
+ /** \brief Specify the objects and values in a new empty distances structure.
656
+ *
657
+ * This is similar to hwloc_distances_add_values()
658
+ * but this variant is designed for backend inserting
659
+ * distances during topology discovery.
660
+ *
661
+ * The only semantical difference is that \p objs and \p values
662
+ * are not duplicated, but directly attached to the topology.
663
+ * On success, these arrays are given to the core and should not
664
+ * ever be freed by the caller anymore.
665
+ */
666
+ HWLOC_DECLSPEC int
667
+ hwloc_backend_distances_add_values(hwloc_topology_t topology,
668
+ hwloc_backend_distances_add_handle_t handle,
669
+ unsigned nbobjs, hwloc_obj_t *objs,
670
+ hwloc_uint64_t *values,
671
+ unsigned long flags);
672
+
673
+ /** \brief Commit a new distances structure.
674
+ *
675
+ * This is similar to hwloc_distances_add_commit()
676
+ * but this variant is designed for backend inserting
677
+ * distances during topology discovery.
678
+ */
679
+ HWLOC_DECLSPEC int
680
+ hwloc_backend_distances_add_commit(hwloc_topology_t topology,
681
+ hwloc_backend_distances_add_handle_t handle,
682
+ unsigned long flags);
683
+
684
+ /** @} */
685
+
686
+
687
+
688
+
689
+ #endif /* HWLOC_PLUGINS_H */
deps/exla/cache/xla_extension/include/include/hwloc/rename.h ADDED
@@ -0,0 +1,901 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved.
3
+ * Copyright © 2010-2021 Inria. All rights reserved.
4
+ * See COPYING in top-level directory.
5
+ */
6
+
7
+ #ifndef HWLOC_RENAME_H
8
+ #define HWLOC_RENAME_H
9
+
10
+ #include "hwloc/autogen/config.h"
11
+
12
+
13
+ #ifdef __cplusplus
14
+ extern "C" {
15
+ #endif
16
+
17
+
18
+ /* Only enact these defines if we're actually renaming the symbols
19
+ (i.e., avoid trying to have no-op defines if we're *not*
20
+ renaming). */
21
+
22
+ #if HWLOC_SYM_TRANSFORM
23
+
24
+ /* Use a preprocessor two-step in order to get the prefixing right.
25
+ Make 2 macros: HWLOC_NAME and HWLOC_NAME_CAPS for renaming
26
+ things. */
27
+
28
+ #define HWLOC_MUNGE_NAME(a, b) HWLOC_MUNGE_NAME2(a, b)
29
+ #define HWLOC_MUNGE_NAME2(a, b) a ## b
30
+ #define HWLOC_NAME(name) HWLOC_MUNGE_NAME(HWLOC_SYM_PREFIX, hwloc_ ## name)
31
+ /* FIXME: should be "HWLOC_ ## name" below, unchanged because it doesn't matter much and could break some embedders hacks */
32
+ #define HWLOC_NAME_CAPS(name) HWLOC_MUNGE_NAME(HWLOC_SYM_PREFIX_CAPS, hwloc_ ## name)
33
+
34
+ /* Now define all the "real" names to be the prefixed names. This
35
+ allows us to use the real names throughout the code base (i.e.,
36
+ "hwloc_<foo>"); the preprocessor will adjust to have the prefixed
37
+ name under the covers. */
38
+
39
+ /* Names from hwloc.h */
40
+
41
+ #define hwloc_get_api_version HWLOC_NAME(get_api_version)
42
+
43
+ #define hwloc_topology HWLOC_NAME(topology)
44
+ #define hwloc_topology_t HWLOC_NAME(topology_t)
45
+
46
+ #define hwloc_cpuset_t HWLOC_NAME(cpuset_t)
47
+ #define hwloc_const_cpuset_t HWLOC_NAME(const_cpuset_t)
48
+ #define hwloc_nodeset_t HWLOC_NAME(nodeset_t)
49
+ #define hwloc_const_nodeset_t HWLOC_NAME(const_nodeset_t)
50
+
51
+ #define HWLOC_OBJ_MACHINE HWLOC_NAME_CAPS(OBJ_MACHINE)
52
+ #define HWLOC_OBJ_NUMANODE HWLOC_NAME_CAPS(OBJ_NUMANODE)
53
+ #define HWLOC_OBJ_MEMCACHE HWLOC_NAME_CAPS(OBJ_MEMCACHE)
54
+ #define HWLOC_OBJ_PACKAGE HWLOC_NAME_CAPS(OBJ_PACKAGE)
55
+ #define HWLOC_OBJ_DIE HWLOC_NAME_CAPS(OBJ_DIE)
56
+ #define HWLOC_OBJ_CORE HWLOC_NAME_CAPS(OBJ_CORE)
57
+ #define HWLOC_OBJ_PU HWLOC_NAME_CAPS(OBJ_PU)
58
+ #define HWLOC_OBJ_L1CACHE HWLOC_NAME_CAPS(OBJ_L1CACHE)
59
+ #define HWLOC_OBJ_L2CACHE HWLOC_NAME_CAPS(OBJ_L2CACHE)
60
+ #define HWLOC_OBJ_L3CACHE HWLOC_NAME_CAPS(OBJ_L3CACHE)
61
+ #define HWLOC_OBJ_L4CACHE HWLOC_NAME_CAPS(OBJ_L4CACHE)
62
+ #define HWLOC_OBJ_L5CACHE HWLOC_NAME_CAPS(OBJ_L5CACHE)
63
+ #define HWLOC_OBJ_L1ICACHE HWLOC_NAME_CAPS(OBJ_L1ICACHE)
64
+ #define HWLOC_OBJ_L2ICACHE HWLOC_NAME_CAPS(OBJ_L2ICACHE)
65
+ #define HWLOC_OBJ_L3ICACHE HWLOC_NAME_CAPS(OBJ_L3ICACHE)
66
+ #define HWLOC_OBJ_MISC HWLOC_NAME_CAPS(OBJ_MISC)
67
+ #define HWLOC_OBJ_GROUP HWLOC_NAME_CAPS(OBJ_GROUP)
68
+ #define HWLOC_OBJ_BRIDGE HWLOC_NAME_CAPS(OBJ_BRIDGE)
69
+ #define HWLOC_OBJ_PCI_DEVICE HWLOC_NAME_CAPS(OBJ_PCI_DEVICE)
70
+ #define HWLOC_OBJ_OS_DEVICE HWLOC_NAME_CAPS(OBJ_OS_DEVICE)
71
+ #define HWLOC_OBJ_TYPE_MAX HWLOC_NAME_CAPS(OBJ_TYPE_MAX)
72
+ #define hwloc_obj_type_t HWLOC_NAME(obj_type_t)
73
+
74
+ #define hwloc_obj_cache_type_e HWLOC_NAME(obj_cache_type_e)
75
+ #define hwloc_obj_cache_type_t HWLOC_NAME(obj_cache_type_t)
76
+ #define HWLOC_OBJ_CACHE_UNIFIED HWLOC_NAME_CAPS(OBJ_CACHE_UNIFIED)
77
+ #define HWLOC_OBJ_CACHE_DATA HWLOC_NAME_CAPS(OBJ_CACHE_DATA)
78
+ #define HWLOC_OBJ_CACHE_INSTRUCTION HWLOC_NAME_CAPS(OBJ_CACHE_INSTRUCTION)
79
+
80
+ #define hwloc_obj_bridge_type_e HWLOC_NAME(obj_bridge_type_e)
81
+ #define hwloc_obj_bridge_type_t HWLOC_NAME(obj_bridge_type_t)
82
+ #define HWLOC_OBJ_BRIDGE_HOST HWLOC_NAME_CAPS(OBJ_BRIDGE_HOST)
83
+ #define HWLOC_OBJ_BRIDGE_PCI HWLOC_NAME_CAPS(OBJ_BRIDGE_PCI)
84
+
85
+ #define hwloc_obj_osdev_type_e HWLOC_NAME(obj_osdev_type_e)
86
+ #define hwloc_obj_osdev_type_t HWLOC_NAME(obj_osdev_type_t)
87
+ #define HWLOC_OBJ_OSDEV_BLOCK HWLOC_NAME_CAPS(OBJ_OSDEV_BLOCK)
88
+ #define HWLOC_OBJ_OSDEV_GPU HWLOC_NAME_CAPS(OBJ_OSDEV_GPU)
89
+ #define HWLOC_OBJ_OSDEV_NETWORK HWLOC_NAME_CAPS(OBJ_OSDEV_NETWORK)
90
+ #define HWLOC_OBJ_OSDEV_OPENFABRICS HWLOC_NAME_CAPS(OBJ_OSDEV_OPENFABRICS)
91
+ #define HWLOC_OBJ_OSDEV_DMA HWLOC_NAME_CAPS(OBJ_OSDEV_DMA)
92
+ #define HWLOC_OBJ_OSDEV_COPROC HWLOC_NAME_CAPS(OBJ_OSDEV_COPROC)
93
+
94
+ #define hwloc_compare_types HWLOC_NAME(compare_types)
95
+
96
+ #define hwloc_obj HWLOC_NAME(obj)
97
+ #define hwloc_obj_t HWLOC_NAME(obj_t)
98
+
99
+ #define hwloc_info_s HWLOC_NAME(info_s)
100
+
101
+ #define hwloc_obj_attr_u HWLOC_NAME(obj_attr_u)
102
+ #define hwloc_numanode_attr_s HWLOC_NAME(numanode_attr_s)
103
+ #define hwloc_memory_page_type_s HWLOC_NAME(memory_page_type_s)
104
+ #define hwloc_cache_attr_s HWLOC_NAME(cache_attr_s)
105
+ #define hwloc_group_attr_s HWLOC_NAME(group_attr_s)
106
+ #define hwloc_pcidev_attr_s HWLOC_NAME(pcidev_attr_s)
107
+ #define hwloc_bridge_attr_s HWLOC_NAME(bridge_attr_s)
108
+ #define hwloc_osdev_attr_s HWLOC_NAME(osdev_attr_s)
109
+
110
+ #define hwloc_topology_init HWLOC_NAME(topology_init)
111
+ #define hwloc_topology_load HWLOC_NAME(topology_load)
112
+ #define hwloc_topology_destroy HWLOC_NAME(topology_destroy)
113
+ #define hwloc_topology_dup HWLOC_NAME(topology_dup)
114
+ #define hwloc_topology_abi_check HWLOC_NAME(topology_abi_check)
115
+ #define hwloc_topology_check HWLOC_NAME(topology_check)
116
+
117
+ #define hwloc_topology_flags_e HWLOC_NAME(topology_flags_e)
118
+
119
+ #define HWLOC_TOPOLOGY_FLAG_INCLUDE_DISALLOWED HWLOC_NAME_CAPS(TOPOLOGY_FLAG_WITH_DISALLOWED)
120
+ #define HWLOC_TOPOLOGY_FLAG_IS_THISSYSTEM HWLOC_NAME_CAPS(TOPOLOGY_FLAG_IS_THISSYSTEM)
121
+ #define HWLOC_TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES HWLOC_NAME_CAPS(TOPOLOGY_FLAG_THISSYSTEM_ALLOWED_RESOURCES)
122
+ #define HWLOC_TOPOLOGY_FLAG_IMPORT_SUPPORT HWLOC_NAME_CAPS(TOPOLOGY_FLAG_IMPORT_SUPPORT)
123
+ #define HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING HWLOC_NAME_CAPS(TOPOLOGY_FLAG_RESTRICT_TO_CPUBINDING)
124
+ #define HWLOC_TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING HWLOC_NAME_CAPS(TOPOLOGY_FLAG_RESTRICT_TO_MEMBINDING)
125
+ #define HWLOC_TOPOLOGY_FLAG_DONT_CHANGE_BINDING HWLOC_NAME_CAPS(TOPOLOGY_FLAG_DONT_CHANGE_BINDING)
126
+
127
+ #define hwloc_topology_set_pid HWLOC_NAME(topology_set_pid)
128
+ #define hwloc_topology_set_synthetic HWLOC_NAME(topology_set_synthetic)
129
+ #define hwloc_topology_set_xml HWLOC_NAME(topology_set_xml)
130
+ #define hwloc_topology_set_xmlbuffer HWLOC_NAME(topology_set_xmlbuffer)
131
+ #define hwloc_topology_components_flag_e HWLOC_NAME(hwloc_topology_components_flag_e)
132
+ #define HWLOC_TOPOLOGY_COMPONENTS_FLAG_BLACKLIST HWLOC_NAME_CAPS(TOPOLOGY_COMPONENTS_FLAG_BLACKLIST)
133
+ #define hwloc_topology_set_components HWLOC_NAME(topology_set_components)
134
+
135
+ #define hwloc_topology_set_flags HWLOC_NAME(topology_set_flags)
136
+ #define hwloc_topology_is_thissystem HWLOC_NAME(topology_is_thissystem)
137
+ #define hwloc_topology_get_flags HWLOC_NAME(topology_get_flags)
138
+ #define hwloc_topology_discovery_support HWLOC_NAME(topology_discovery_support)
139
+ #define hwloc_topology_cpubind_support HWLOC_NAME(topology_cpubind_support)
140
+ #define hwloc_topology_membind_support HWLOC_NAME(topology_membind_support)
141
+ #define hwloc_topology_misc_support HWLOC_NAME(topology_misc_support)
142
+ #define hwloc_topology_support HWLOC_NAME(topology_support)
143
+ #define hwloc_topology_get_support HWLOC_NAME(topology_get_support)
144
+
145
+ #define hwloc_type_filter_e HWLOC_NAME(type_filter_e)
146
+ #define HWLOC_TYPE_FILTER_KEEP_ALL HWLOC_NAME_CAPS(TYPE_FILTER_KEEP_ALL)
147
+ #define HWLOC_TYPE_FILTER_KEEP_NONE HWLOC_NAME_CAPS(TYPE_FILTER_KEEP_NONE)
148
+ #define HWLOC_TYPE_FILTER_KEEP_STRUCTURE HWLOC_NAME_CAPS(TYPE_FILTER_KEEP_STRUCTURE)
149
+ #define HWLOC_TYPE_FILTER_KEEP_IMPORTANT HWLOC_NAME_CAPS(TYPE_FILTER_KEEP_IMPORTANT)
150
+ #define hwloc_topology_set_type_filter HWLOC_NAME(topology_set_type_filter)
151
+ #define hwloc_topology_get_type_filter HWLOC_NAME(topology_get_type_filter)
152
+ #define hwloc_topology_set_all_types_filter HWLOC_NAME(topology_set_all_types_filter)
153
+ #define hwloc_topology_set_cache_types_filter HWLOC_NAME(topology_set_cache_types_filter)
154
+ #define hwloc_topology_set_icache_types_filter HWLOC_NAME(topology_set_icache_types_filter)
155
+ #define hwloc_topology_set_io_types_filter HWLOC_NAME(topology_set_io_types_filter)
156
+
157
+ #define hwloc_topology_set_userdata HWLOC_NAME(topology_set_userdata)
158
+ #define hwloc_topology_get_userdata HWLOC_NAME(topology_get_userdata)
159
+
160
+ #define hwloc_restrict_flags_e HWLOC_NAME(restrict_flags_e)
161
+ #define HWLOC_RESTRICT_FLAG_REMOVE_CPULESS HWLOC_NAME_CAPS(RESTRICT_FLAG_REMOVE_CPULESS)
162
+ #define HWLOC_RESTRICT_FLAG_BYNODESET HWLOC_NAME_CAPS(RESTRICT_FLAG_BYNODESET)
163
+ #define HWLOC_RESTRICT_FLAG_REMOVE_MEMLESS HWLOC_NAME_CAPS(RESTRICT_FLAG_REMOVE_MEMLESS)
164
+ #define HWLOC_RESTRICT_FLAG_ADAPT_MISC HWLOC_NAME_CAPS(RESTRICT_FLAG_ADAPT_MISC)
165
+ #define HWLOC_RESTRICT_FLAG_ADAPT_IO HWLOC_NAME_CAPS(RESTRICT_FLAG_ADAPT_IO)
166
+ #define hwloc_topology_restrict HWLOC_NAME(topology_restrict)
167
+
168
+ #define hwloc_allow_flags_e HWLOC_NAME(allow_flags_e)
169
+ #define HWLOC_ALLOW_FLAG_ALL HWLOC_NAME_CAPS(ALLOW_FLAG_ALL)
170
+ #define HWLOC_ALLOW_FLAG_LOCAL_RESTRICTIONS HWLOC_NAME_CAPS(ALLOW_FLAG_LOCAL_RESTRICTIONS)
171
+ #define HWLOC_ALLOW_FLAG_CUSTOM HWLOC_NAME_CAPS(ALLOW_FLAG_CUSTOM)
172
+ #define hwloc_topology_allow HWLOC_NAME(topology_allow)
173
+
174
+ #define hwloc_topology_insert_misc_object HWLOC_NAME(topology_insert_misc_object)
175
+ #define hwloc_topology_alloc_group_object HWLOC_NAME(topology_alloc_group_object)
176
+ #define hwloc_topology_insert_group_object HWLOC_NAME(topology_insert_group_object)
177
+ #define hwloc_obj_add_other_obj_sets HWLOC_NAME(obj_add_other_obj_sets)
178
+ #define hwloc_topology_refresh HWLOC_NAME(topology_refresh)
179
+
180
+ #define hwloc_topology_get_depth HWLOC_NAME(topology_get_depth)
181
+ #define hwloc_get_type_depth HWLOC_NAME(get_type_depth)
182
+ #define hwloc_get_memory_parents_depth HWLOC_NAME(get_memory_parents_depth)
183
+
184
+ #define hwloc_get_type_depth_e HWLOC_NAME(get_type_depth_e)
185
+ #define HWLOC_TYPE_DEPTH_UNKNOWN HWLOC_NAME_CAPS(TYPE_DEPTH_UNKNOWN)
186
+ #define HWLOC_TYPE_DEPTH_MULTIPLE HWLOC_NAME_CAPS(TYPE_DEPTH_MULTIPLE)
187
+ #define HWLOC_TYPE_DEPTH_BRIDGE HWLOC_NAME_CAPS(TYPE_DEPTH_BRIDGE)
188
+ #define HWLOC_TYPE_DEPTH_PCI_DEVICE HWLOC_NAME_CAPS(TYPE_DEPTH_PCI_DEVICE)
189
+ #define HWLOC_TYPE_DEPTH_OS_DEVICE HWLOC_NAME_CAPS(TYPE_DEPTH_OS_DEVICE)
190
+ #define HWLOC_TYPE_DEPTH_MISC HWLOC_NAME_CAPS(TYPE_DEPTH_MISC)
191
+ #define HWLOC_TYPE_DEPTH_NUMANODE HWLOC_NAME_CAPS(TYPE_DEPTH_NUMANODE)
192
+ #define HWLOC_TYPE_DEPTH_MEMCACHE HWLOC_NAME_CAPS(TYPE_DEPTH_MEMCACHE)
193
+
194
+ #define hwloc_get_depth_type HWLOC_NAME(get_depth_type)
195
+ #define hwloc_get_nbobjs_by_depth HWLOC_NAME(get_nbobjs_by_depth)
196
+ #define hwloc_get_nbobjs_by_type HWLOC_NAME(get_nbobjs_by_type)
197
+
198
+ #define hwloc_get_obj_by_depth HWLOC_NAME(get_obj_by_depth )
199
+ #define hwloc_get_obj_by_type HWLOC_NAME(get_obj_by_type )
200
+
201
+ #define hwloc_obj_type_string HWLOC_NAME(obj_type_string )
202
+ #define hwloc_obj_type_snprintf HWLOC_NAME(obj_type_snprintf )
203
+ #define hwloc_obj_attr_snprintf HWLOC_NAME(obj_attr_snprintf )
204
+ #define hwloc_type_sscanf HWLOC_NAME(type_sscanf)
205
+ #define hwloc_type_sscanf_as_depth HWLOC_NAME(type_sscanf_as_depth)
206
+
207
+ #define hwloc_obj_get_info_by_name HWLOC_NAME(obj_get_info_by_name)
208
+ #define hwloc_obj_add_info HWLOC_NAME(obj_add_info)
209
+
210
+ #define HWLOC_CPUBIND_PROCESS HWLOC_NAME_CAPS(CPUBIND_PROCESS)
211
+ #define HWLOC_CPUBIND_THREAD HWLOC_NAME_CAPS(CPUBIND_THREAD)
212
+ #define HWLOC_CPUBIND_STRICT HWLOC_NAME_CAPS(CPUBIND_STRICT)
213
+ #define HWLOC_CPUBIND_NOMEMBIND HWLOC_NAME_CAPS(CPUBIND_NOMEMBIND)
214
+
215
+ #define hwloc_cpubind_flags_t HWLOC_NAME(cpubind_flags_t)
216
+
217
+ #define hwloc_set_cpubind HWLOC_NAME(set_cpubind)
218
+ #define hwloc_get_cpubind HWLOC_NAME(get_cpubind)
219
+ #define hwloc_set_proc_cpubind HWLOC_NAME(set_proc_cpubind)
220
+ #define hwloc_get_proc_cpubind HWLOC_NAME(get_proc_cpubind)
221
+ #define hwloc_set_thread_cpubind HWLOC_NAME(set_thread_cpubind)
222
+ #define hwloc_get_thread_cpubind HWLOC_NAME(get_thread_cpubind)
223
+
224
+ #define hwloc_get_last_cpu_location HWLOC_NAME(get_last_cpu_location)
225
+ #define hwloc_get_proc_last_cpu_location HWLOC_NAME(get_proc_last_cpu_location)
226
+
227
+ #define HWLOC_MEMBIND_DEFAULT HWLOC_NAME_CAPS(MEMBIND_DEFAULT)
228
+ #define HWLOC_MEMBIND_FIRSTTOUCH HWLOC_NAME_CAPS(MEMBIND_FIRSTTOUCH)
229
+ #define HWLOC_MEMBIND_BIND HWLOC_NAME_CAPS(MEMBIND_BIND)
230
+ #define HWLOC_MEMBIND_INTERLEAVE HWLOC_NAME_CAPS(MEMBIND_INTERLEAVE)
231
+ #define HWLOC_MEMBIND_NEXTTOUCH HWLOC_NAME_CAPS(MEMBIND_NEXTTOUCH)
232
+ #define HWLOC_MEMBIND_MIXED HWLOC_NAME_CAPS(MEMBIND_MIXED)
233
+
234
+ #define hwloc_membind_policy_t HWLOC_NAME(membind_policy_t)
235
+
236
+ #define HWLOC_MEMBIND_PROCESS HWLOC_NAME_CAPS(MEMBIND_PROCESS)
237
+ #define HWLOC_MEMBIND_THREAD HWLOC_NAME_CAPS(MEMBIND_THREAD)
238
+ #define HWLOC_MEMBIND_STRICT HWLOC_NAME_CAPS(MEMBIND_STRICT)
239
+ #define HWLOC_MEMBIND_MIGRATE HWLOC_NAME_CAPS(MEMBIND_MIGRATE)
240
+ #define HWLOC_MEMBIND_NOCPUBIND HWLOC_NAME_CAPS(MEMBIND_NOCPUBIND)
241
+ #define HWLOC_MEMBIND_BYNODESET HWLOC_NAME_CAPS(MEMBIND_BYNODESET)
242
+
243
+ #define hwloc_membind_flags_t HWLOC_NAME(membind_flags_t)
244
+
245
+ #define hwloc_set_membind HWLOC_NAME(set_membind)
246
+ #define hwloc_get_membind HWLOC_NAME(get_membind)
247
+ #define hwloc_set_proc_membind HWLOC_NAME(set_proc_membind)
248
+ #define hwloc_get_proc_membind HWLOC_NAME(get_proc_membind)
249
+ #define hwloc_set_area_membind HWLOC_NAME(set_area_membind)
250
+ #define hwloc_get_area_membind HWLOC_NAME(get_area_membind)
251
+ #define hwloc_get_area_memlocation HWLOC_NAME(get_area_memlocation)
252
+ #define hwloc_alloc_membind HWLOC_NAME(alloc_membind)
253
+ #define hwloc_alloc HWLOC_NAME(alloc)
254
+ #define hwloc_free HWLOC_NAME(free)
255
+
256
+ #define hwloc_get_non_io_ancestor_obj HWLOC_NAME(get_non_io_ancestor_obj)
257
+ #define hwloc_get_next_pcidev HWLOC_NAME(get_next_pcidev)
258
+ #define hwloc_get_pcidev_by_busid HWLOC_NAME(get_pcidev_by_busid)
259
+ #define hwloc_get_pcidev_by_busidstring HWLOC_NAME(get_pcidev_by_busidstring)
260
+ #define hwloc_get_next_osdev HWLOC_NAME(get_next_osdev)
261
+ #define hwloc_get_next_bridge HWLOC_NAME(get_next_bridge)
262
+ #define hwloc_bridge_covers_pcibus HWLOC_NAME(bridge_covers_pcibus)
263
+
264
+ /* hwloc/bitmap.h */
265
+
266
+ #define hwloc_bitmap_s HWLOC_NAME(bitmap_s)
267
+ #define hwloc_bitmap_t HWLOC_NAME(bitmap_t)
268
+ #define hwloc_const_bitmap_t HWLOC_NAME(const_bitmap_t)
269
+
270
+ #define hwloc_bitmap_alloc HWLOC_NAME(bitmap_alloc)
271
+ #define hwloc_bitmap_alloc_full HWLOC_NAME(bitmap_alloc_full)
272
+ #define hwloc_bitmap_free HWLOC_NAME(bitmap_free)
273
+ #define hwloc_bitmap_dup HWLOC_NAME(bitmap_dup)
274
+ #define hwloc_bitmap_copy HWLOC_NAME(bitmap_copy)
275
+ #define hwloc_bitmap_snprintf HWLOC_NAME(bitmap_snprintf)
276
+ #define hwloc_bitmap_asprintf HWLOC_NAME(bitmap_asprintf)
277
+ #define hwloc_bitmap_sscanf HWLOC_NAME(bitmap_sscanf)
278
+ #define hwloc_bitmap_list_snprintf HWLOC_NAME(bitmap_list_snprintf)
279
+ #define hwloc_bitmap_list_asprintf HWLOC_NAME(bitmap_list_asprintf)
280
+ #define hwloc_bitmap_list_sscanf HWLOC_NAME(bitmap_list_sscanf)
281
+ #define hwloc_bitmap_taskset_snprintf HWLOC_NAME(bitmap_taskset_snprintf)
282
+ #define hwloc_bitmap_taskset_asprintf HWLOC_NAME(bitmap_taskset_asprintf)
283
+ #define hwloc_bitmap_taskset_sscanf HWLOC_NAME(bitmap_taskset_sscanf)
284
+ #define hwloc_bitmap_zero HWLOC_NAME(bitmap_zero)
285
+ #define hwloc_bitmap_fill HWLOC_NAME(bitmap_fill)
286
+ #define hwloc_bitmap_from_ulong HWLOC_NAME(bitmap_from_ulong)
287
+ #define hwloc_bitmap_from_ulongs HWLOC_NAME(bitmap_from_ulongs)
288
+ #define hwloc_bitmap_from_ith_ulong HWLOC_NAME(bitmap_from_ith_ulong)
289
+ #define hwloc_bitmap_to_ulong HWLOC_NAME(bitmap_to_ulong)
290
+ #define hwloc_bitmap_to_ith_ulong HWLOC_NAME(bitmap_to_ith_ulong)
291
+ #define hwloc_bitmap_to_ulongs HWLOC_NAME(bitmap_to_ulongs)
292
+ #define hwloc_bitmap_nr_ulongs HWLOC_NAME(bitmap_nr_ulongs)
293
+ #define hwloc_bitmap_only HWLOC_NAME(bitmap_only)
294
+ #define hwloc_bitmap_allbut HWLOC_NAME(bitmap_allbut)
295
+ #define hwloc_bitmap_set HWLOC_NAME(bitmap_set)
296
+ #define hwloc_bitmap_set_range HWLOC_NAME(bitmap_set_range)
297
+ #define hwloc_bitmap_set_ith_ulong HWLOC_NAME(bitmap_set_ith_ulong)
298
+ #define hwloc_bitmap_clr HWLOC_NAME(bitmap_clr)
299
+ #define hwloc_bitmap_clr_range HWLOC_NAME(bitmap_clr_range)
300
+ #define hwloc_bitmap_isset HWLOC_NAME(bitmap_isset)
301
+ #define hwloc_bitmap_iszero HWLOC_NAME(bitmap_iszero)
302
+ #define hwloc_bitmap_isfull HWLOC_NAME(bitmap_isfull)
303
+ #define hwloc_bitmap_isequal HWLOC_NAME(bitmap_isequal)
304
+ #define hwloc_bitmap_intersects HWLOC_NAME(bitmap_intersects)
305
+ #define hwloc_bitmap_isincluded HWLOC_NAME(bitmap_isincluded)
306
+ #define hwloc_bitmap_or HWLOC_NAME(bitmap_or)
307
+ #define hwloc_bitmap_and HWLOC_NAME(bitmap_and)
308
+ #define hwloc_bitmap_andnot HWLOC_NAME(bitmap_andnot)
309
+ #define hwloc_bitmap_xor HWLOC_NAME(bitmap_xor)
310
+ #define hwloc_bitmap_not HWLOC_NAME(bitmap_not)
311
+ #define hwloc_bitmap_first HWLOC_NAME(bitmap_first)
312
+ #define hwloc_bitmap_last HWLOC_NAME(bitmap_last)
313
+ #define hwloc_bitmap_next HWLOC_NAME(bitmap_next)
314
+ #define hwloc_bitmap_first_unset HWLOC_NAME(bitmap_first_unset)
315
+ #define hwloc_bitmap_last_unset HWLOC_NAME(bitmap_last_unset)
316
+ #define hwloc_bitmap_next_unset HWLOC_NAME(bitmap_next_unset)
317
+ #define hwloc_bitmap_singlify HWLOC_NAME(bitmap_singlify)
318
+ #define hwloc_bitmap_compare_first HWLOC_NAME(bitmap_compare_first)
319
+ #define hwloc_bitmap_compare HWLOC_NAME(bitmap_compare)
320
+ #define hwloc_bitmap_weight HWLOC_NAME(bitmap_weight)
321
+
322
+ /* hwloc/helper.h */
323
+
324
+ #define hwloc_get_type_or_below_depth HWLOC_NAME(get_type_or_below_depth)
325
+ #define hwloc_get_type_or_above_depth HWLOC_NAME(get_type_or_above_depth)
326
+ #define hwloc_get_root_obj HWLOC_NAME(get_root_obj)
327
+ #define hwloc_get_ancestor_obj_by_depth HWLOC_NAME(get_ancestor_obj_by_depth)
328
+ #define hwloc_get_ancestor_obj_by_type HWLOC_NAME(get_ancestor_obj_by_type)
329
+ #define hwloc_get_next_obj_by_depth HWLOC_NAME(get_next_obj_by_depth)
330
+ #define hwloc_get_next_obj_by_type HWLOC_NAME(get_next_obj_by_type)
331
+ #define hwloc_bitmap_singlify_per_core HWLOC_NAME(bitmap_singlify_by_core)
332
+ #define hwloc_get_pu_obj_by_os_index HWLOC_NAME(get_pu_obj_by_os_index)
333
+ #define hwloc_get_numanode_obj_by_os_index HWLOC_NAME(get_numanode_obj_by_os_index)
334
+ #define hwloc_get_next_child HWLOC_NAME(get_next_child)
335
+ #define hwloc_get_common_ancestor_obj HWLOC_NAME(get_common_ancestor_obj)
336
+ #define hwloc_obj_is_in_subtree HWLOC_NAME(obj_is_in_subtree)
337
+ #define hwloc_get_first_largest_obj_inside_cpuset HWLOC_NAME(get_first_largest_obj_inside_cpuset)
338
+ #define hwloc_get_largest_objs_inside_cpuset HWLOC_NAME(get_largest_objs_inside_cpuset)
339
+ #define hwloc_get_next_obj_inside_cpuset_by_depth HWLOC_NAME(get_next_obj_inside_cpuset_by_depth)
340
+ #define hwloc_get_next_obj_inside_cpuset_by_type HWLOC_NAME(get_next_obj_inside_cpuset_by_type)
341
+ #define hwloc_get_obj_inside_cpuset_by_depth HWLOC_NAME(get_obj_inside_cpuset_by_depth)
342
+ #define hwloc_get_obj_inside_cpuset_by_type HWLOC_NAME(get_obj_inside_cpuset_by_type)
343
+ #define hwloc_get_nbobjs_inside_cpuset_by_depth HWLOC_NAME(get_nbobjs_inside_cpuset_by_depth)
344
+ #define hwloc_get_nbobjs_inside_cpuset_by_type HWLOC_NAME(get_nbobjs_inside_cpuset_by_type)
345
+ #define hwloc_get_obj_index_inside_cpuset HWLOC_NAME(get_obj_index_inside_cpuset)
346
+ #define hwloc_get_child_covering_cpuset HWLOC_NAME(get_child_covering_cpuset)
347
+ #define hwloc_get_obj_covering_cpuset HWLOC_NAME(get_obj_covering_cpuset)
348
+ #define hwloc_get_next_obj_covering_cpuset_by_depth HWLOC_NAME(get_next_obj_covering_cpuset_by_depth)
349
+ #define hwloc_get_next_obj_covering_cpuset_by_type HWLOC_NAME(get_next_obj_covering_cpuset_by_type)
350
+ #define hwloc_obj_type_is_normal HWLOC_NAME(obj_type_is_normal)
351
+ #define hwloc_obj_type_is_memory HWLOC_NAME(obj_type_is_memory)
352
+ #define hwloc_obj_type_is_io HWLOC_NAME(obj_type_is_io)
353
+ #define hwloc_obj_type_is_cache HWLOC_NAME(obj_type_is_cache)
354
+ #define hwloc_obj_type_is_dcache HWLOC_NAME(obj_type_is_dcache)
355
+ #define hwloc_obj_type_is_icache HWLOC_NAME(obj_type_is_icache)
356
+ #define hwloc_get_cache_type_depth HWLOC_NAME(get_cache_type_depth)
357
+ #define hwloc_get_cache_covering_cpuset HWLOC_NAME(get_cache_covering_cpuset)
358
+ #define hwloc_get_shared_cache_covering_obj HWLOC_NAME(get_shared_cache_covering_obj)
359
+ #define hwloc_get_closest_objs HWLOC_NAME(get_closest_objs)
360
+ #define hwloc_get_obj_below_by_type HWLOC_NAME(get_obj_below_by_type)
361
+ #define hwloc_get_obj_below_array_by_type HWLOC_NAME(get_obj_below_array_by_type)
362
+ #define hwloc_get_obj_with_same_locality HWLOC_NAME(get_obj_with_same_locality)
363
+ #define hwloc_distrib_flags_e HWLOC_NAME(distrib_flags_e)
364
+ #define HWLOC_DISTRIB_FLAG_REVERSE HWLOC_NAME_CAPS(DISTRIB_FLAG_REVERSE)
365
+ #define hwloc_distrib HWLOC_NAME(distrib)
366
+ #define hwloc_alloc_membind_policy HWLOC_NAME(alloc_membind_policy)
367
+ #define hwloc_alloc_membind_policy_nodeset HWLOC_NAME(alloc_membind_policy_nodeset)
368
+ #define hwloc_topology_get_complete_cpuset HWLOC_NAME(topology_get_complete_cpuset)
369
+ #define hwloc_topology_get_topology_cpuset HWLOC_NAME(topology_get_topology_cpuset)
370
+ #define hwloc_topology_get_allowed_cpuset HWLOC_NAME(topology_get_allowed_cpuset)
371
+ #define hwloc_topology_get_complete_nodeset HWLOC_NAME(topology_get_complete_nodeset)
372
+ #define hwloc_topology_get_topology_nodeset HWLOC_NAME(topology_get_topology_nodeset)
373
+ #define hwloc_topology_get_allowed_nodeset HWLOC_NAME(topology_get_allowed_nodeset)
374
+ #define hwloc_cpuset_to_nodeset HWLOC_NAME(cpuset_to_nodeset)
375
+ #define hwloc_cpuset_from_nodeset HWLOC_NAME(cpuset_from_nodeset)
376
+
377
+ /* memattrs.h */
378
+
379
+ #define hwloc_memattr_id_e HWLOC_NAME(memattr_id_e)
380
+ #define HWLOC_MEMATTR_ID_CAPACITY HWLOC_NAME_CAPS(MEMATTR_ID_CAPACITY)
381
+ #define HWLOC_MEMATTR_ID_LOCALITY HWLOC_NAME_CAPS(MEMATTR_ID_LOCALITY)
382
+ #define HWLOC_MEMATTR_ID_BANDWIDTH HWLOC_NAME_CAPS(MEMATTR_ID_BANDWIDTH)
383
+ #define HWLOC_MEMATTR_ID_LATENCY HWLOC_NAME_CAPS(MEMATTR_ID_LATENCY)
384
+
385
+ #define hwloc_memattr_id_t HWLOC_NAME(memattr_id_t)
386
+ #define hwloc_memattr_get_by_name HWLOC_NAME(memattr_get_by_name)
387
+
388
+ #define hwloc_location HWLOC_NAME(location)
389
+ #define hwloc_location_type_e HWLOC_NAME(location_type_e)
390
+ #define HWLOC_LOCATION_TYPE_OBJECT HWLOC_NAME_CAPS(LOCATION_TYPE_OBJECT)
391
+ #define HWLOC_LOCATION_TYPE_CPUSET HWLOC_NAME_CAPS(LOCATION_TYPE_CPUSET)
392
+ #define hwloc_location_u HWLOC_NAME(location_u)
393
+
394
+ #define hwloc_memattr_get_value HWLOC_NAME(memattr_get_value)
395
+ #define hwloc_memattr_get_best_target HWLOC_NAME(memattr_get_best_target)
396
+ #define hwloc_memattr_get_best_initiator HWLOC_NAME(memattr_get_best_initiator)
397
+
398
+ #define hwloc_local_numanode_flag_e HWLOC_NAME(local_numanode_flag_e)
399
+ #define HWLOC_LOCAL_NUMANODE_FLAG_LARGER_LOCALITY HWLOC_NAME_CAPS(LOCAL_NUMANODE_FLAG_LARGER_LOCALITY)
400
+ #define HWLOC_LOCAL_NUMANODE_FLAG_SMALLER_LOCALITY HWLOC_NAME_CAPS(LOCAL_NUMANODE_FLAG_SMALLER_LOCALITY)
401
+ #define HWLOC_LOCAL_NUMANODE_FLAG_ALL HWLOC_NAME_CAPS(LOCAL_NUMANODE_FLAG_ALL)
402
+ #define hwloc_get_local_numanode_objs HWLOC_NAME(get_local_numanode_objs)
403
+
404
+ #define hwloc_memattr_get_name HWLOC_NAME(memattr_get_name)
405
+ #define hwloc_memattr_get_flags HWLOC_NAME(memattr_get_flags)
406
+ #define hwloc_memattr_flag_e HWLOC_NAME(memattr_flag_e)
407
+ #define HWLOC_MEMATTR_FLAG_HIGHER_FIRST HWLOC_NAME_CAPS(MEMATTR_FLAG_HIGHER_FIRST)
408
+ #define HWLOC_MEMATTR_FLAG_LOWER_FIRST HWLOC_NAME_CAPS(MEMATTR_FLAG_LOWER_FIRST)
409
+ #define HWLOC_MEMATTR_FLAG_NEED_INITIATOR HWLOC_NAME_CAPS(MEMATTR_FLAG_NEED_INITIATOR)
410
+ #define hwloc_memattr_register HWLOC_NAME(memattr_register)
411
+ #define hwloc_memattr_set_value HWLOC_NAME(memattr_set_value)
412
+ #define hwloc_memattr_get_targets HWLOC_NAME(memattr_get_targets)
413
+ #define hwloc_memattr_get_initiators HWLOC_NAME(memattr_get_initiators)
414
+
415
+ /* cpukinds.h */
416
+
417
+ #define hwloc_cpukinds_get_nr HWLOC_NAME(cpukinds_get_nr)
418
+ #define hwloc_cpukinds_get_by_cpuset HWLOC_NAME(cpukinds_get_by_cpuset)
419
+ #define hwloc_cpukinds_get_info HWLOC_NAME(cpukinds_get_info)
420
+ #define hwloc_cpukinds_register HWLOC_NAME(cpukinds_register)
421
+
422
+ /* export.h */
423
+
424
+ #define hwloc_topology_export_xml_flags_e HWLOC_NAME(topology_export_xml_flags_e)
425
+ #define HWLOC_TOPOLOGY_EXPORT_XML_FLAG_V1 HWLOC_NAME_CAPS(TOPOLOGY_EXPORT_XML_FLAG_V1)
426
+ #define hwloc_topology_export_xml HWLOC_NAME(topology_export_xml)
427
+ #define hwloc_topology_export_xmlbuffer HWLOC_NAME(topology_export_xmlbuffer)
428
+ #define hwloc_free_xmlbuffer HWLOC_NAME(free_xmlbuffer)
429
+ #define hwloc_topology_set_userdata_export_callback HWLOC_NAME(topology_set_userdata_export_callback)
430
+ #define hwloc_export_obj_userdata HWLOC_NAME(export_obj_userdata)
431
+ #define hwloc_export_obj_userdata_base64 HWLOC_NAME(export_obj_userdata_base64)
432
+ #define hwloc_topology_set_userdata_import_callback HWLOC_NAME(topology_set_userdata_import_callback)
433
+
434
+ #define hwloc_topology_export_synthetic_flags_e HWLOC_NAME(topology_export_synthetic_flags_e)
435
+ #define HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_EXTENDED_TYPES HWLOC_NAME_CAPS(TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_EXTENDED_TYPES)
436
+ #define HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_ATTRS HWLOC_NAME_CAPS(TOPOLOGY_EXPORT_SYNTHETIC_FLAG_NO_ATTRS)
437
+ #define HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_V1 HWLOC_NAME_CAPS(TOPOLOGY_EXPORT_SYNTHETIC_FLAG_V1)
438
+ #define HWLOC_TOPOLOGY_EXPORT_SYNTHETIC_FLAG_IGNORE_MEMORY HWLOC_NAME_CAPS(TOPOLOGY_EXPORT_SYNTHETIC_FLAG_IGNORE_MEMORY)
439
+ #define hwloc_topology_export_synthetic HWLOC_NAME(topology_export_synthetic)
440
+
441
+ /* distances.h */
442
+
443
+ #define hwloc_distances_s HWLOC_NAME(distances_s)
444
+
445
+ #define hwloc_distances_kind_e HWLOC_NAME(distances_kind_e)
446
+ #define HWLOC_DISTANCES_KIND_FROM_OS HWLOC_NAME_CAPS(DISTANCES_KIND_FROM_OS)
447
+ #define HWLOC_DISTANCES_KIND_FROM_USER HWLOC_NAME_CAPS(DISTANCES_KIND_FROM_USER)
448
+ #define HWLOC_DISTANCES_KIND_MEANS_LATENCY HWLOC_NAME_CAPS(DISTANCES_KIND_MEANS_LATENCY)
449
+ #define HWLOC_DISTANCES_KIND_MEANS_BANDWIDTH HWLOC_NAME_CAPS(DISTANCES_KIND_MEANS_BANDWIDTH)
450
+ #define HWLOC_DISTANCES_KIND_HETEROGENEOUS_TYPES HWLOC_NAME_CAPS(DISTANCES_KIND_HETEROGENEOUS_TYPES)
451
+
452
+ #define hwloc_distances_get HWLOC_NAME(distances_get)
453
+ #define hwloc_distances_get_by_depth HWLOC_NAME(distances_get_by_depth)
454
+ #define hwloc_distances_get_by_type HWLOC_NAME(distances_get_by_type)
455
+ #define hwloc_distances_get_by_name HWLOC_NAME(distances_get_by_name)
456
+ #define hwloc_distances_get_name HWLOC_NAME(distances_get_name)
457
+ #define hwloc_distances_release HWLOC_NAME(distances_release)
458
+ #define hwloc_distances_obj_index HWLOC_NAME(distances_obj_index)
459
+ #define hwloc_distances_obj_pair_values HWLOC_NAME(distances_pair_values)
460
+
461
+ #define hwloc_distances_transform_e HWLOC_NAME(distances_transform_e)
462
+ #define HWLOC_DISTANCES_TRANSFORM_REMOVE_NULL HWLOC_NAME_CAPS(DISTANCES_TRANSFORM_REMOVE_NULL)
463
+ #define HWLOC_DISTANCES_TRANSFORM_LINKS HWLOC_NAME_CAPS(DISTANCES_TRANSFORM_LINKS)
464
+ #define HWLOC_DISTANCES_TRANSFORM_MERGE_SWITCH_PORTS HWLOC_NAME_CAPS(DISTANCES_TRANSFORM_MERGE_SWITCH_PORTS)
465
+ #define HWLOC_DISTANCES_TRANSFORM_TRANSITIVE_CLOSURE HWLOC_NAME_CAPS(DISTANCES_TRANSFORM_TRANSITIVE_CLOSURE)
466
+ #define hwloc_distances_transform HWLOC_NAME(distances_transform)
467
+
468
+ #define hwloc_distances_add_flag_e HWLOC_NAME(distances_add_flag_e)
469
+ #define HWLOC_DISTANCES_ADD_FLAG_GROUP HWLOC_NAME_CAPS(DISTANCES_ADD_FLAG_GROUP)
470
+ #define HWLOC_DISTANCES_ADD_FLAG_GROUP_INACCURATE HWLOC_NAME_CAPS(DISTANCES_ADD_FLAG_GROUP_INACCURATE)
471
+
472
+ #define hwloc_distances_add_handle_t HWLOC_NAME(distances_add_handle_t)
473
+ #define hwloc_distances_add_create HWLOC_NAME(distances_add_create)
474
+ #define hwloc_distances_add_values HWLOC_NAME(distances_add_values)
475
+ #define hwloc_distances_add_commit HWLOC_NAME(distances_add_commit)
476
+
477
+ #define hwloc_distances_remove HWLOC_NAME(distances_remove)
478
+ #define hwloc_distances_remove_by_depth HWLOC_NAME(distances_remove_by_depth)
479
+ #define hwloc_distances_remove_by_type HWLOC_NAME(distances_remove_by_type)
480
+ #define hwloc_distances_release_remove HWLOC_NAME(distances_release_remove)
481
+
482
+ /* diff.h */
483
+
484
+ #define hwloc_topology_diff_obj_attr_type_e HWLOC_NAME(topology_diff_obj_attr_type_e)
485
+ #define hwloc_topology_diff_obj_attr_type_t HWLOC_NAME(topology_diff_obj_attr_type_t)
486
+ #define HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_SIZE HWLOC_NAME_CAPS(TOPOLOGY_DIFF_OBJ_ATTR_SIZE)
487
+ #define HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_NAME HWLOC_NAME_CAPS(TOPOLOGY_DIFF_OBJ_ATTR_NAME)
488
+ #define HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_INFO HWLOC_NAME_CAPS(TOPOLOGY_DIFF_OBJ_ATTR_INFO)
489
+ #define hwloc_topology_diff_obj_attr_u HWLOC_NAME(topology_diff_obj_attr_u)
490
+ #define hwloc_topology_diff_obj_attr_generic_s HWLOC_NAME(topology_diff_obj_attr_generic_s)
491
+ #define hwloc_topology_diff_obj_attr_uint64_s HWLOC_NAME(topology_diff_obj_attr_uint64_s)
492
+ #define hwloc_topology_diff_obj_attr_string_s HWLOC_NAME(topology_diff_obj_attr_string_s)
493
+ #define hwloc_topology_diff_type_e HWLOC_NAME(topology_diff_type_e)
494
+ #define hwloc_topology_diff_type_t HWLOC_NAME(topology_diff_type_t)
495
+ #define HWLOC_TOPOLOGY_DIFF_OBJ_ATTR HWLOC_NAME_CAPS(TOPOLOGY_DIFF_OBJ_ATTR)
496
+ #define HWLOC_TOPOLOGY_DIFF_TOO_COMPLEX HWLOC_NAME_CAPS(TOPOLOGY_DIFF_TOO_COMPLEX)
497
+ #define hwloc_topology_diff_u HWLOC_NAME(topology_diff_u)
498
+ #define hwloc_topology_diff_t HWLOC_NAME(topology_diff_t)
499
+ #define hwloc_topology_diff_generic_s HWLOC_NAME(topology_diff_generic_s)
500
+ #define hwloc_topology_diff_obj_attr_s HWLOC_NAME(topology_diff_obj_attr_s)
501
+ #define hwloc_topology_diff_too_complex_s HWLOC_NAME(topology_diff_too_complex_s)
502
+ #define hwloc_topology_diff_build HWLOC_NAME(topology_diff_build)
503
+ #define hwloc_topology_diff_apply_flags_e HWLOC_NAME(topology_diff_apply_flags_e)
504
+ #define HWLOC_TOPOLOGY_DIFF_APPLY_REVERSE HWLOC_NAME_CAPS(TOPOLOGY_DIFF_APPLY_REVERSE)
505
+ #define hwloc_topology_diff_apply HWLOC_NAME(topology_diff_apply)
506
+ #define hwloc_topology_diff_destroy HWLOC_NAME(topology_diff_destroy)
507
+ #define hwloc_topology_diff_load_xml HWLOC_NAME(topology_diff_load_xml)
508
+ #define hwloc_topology_diff_export_xml HWLOC_NAME(topology_diff_export_xml)
509
+ #define hwloc_topology_diff_load_xmlbuffer HWLOC_NAME(topology_diff_load_xmlbuffer)
510
+ #define hwloc_topology_diff_export_xmlbuffer HWLOC_NAME(topology_diff_export_xmlbuffer)
511
+
512
+ /* shmem.h */
513
+
514
+ #define hwloc_shmem_topology_get_length HWLOC_NAME(shmem_topology_get_length)
515
+ #define hwloc_shmem_topology_write HWLOC_NAME(shmem_topology_write)
516
+ #define hwloc_shmem_topology_adopt HWLOC_NAME(shmem_topology_adopt)
517
+
518
+ /* glibc-sched.h */
519
+
520
+ #define hwloc_cpuset_to_glibc_sched_affinity HWLOC_NAME(cpuset_to_glibc_sched_affinity)
521
+ #define hwloc_cpuset_from_glibc_sched_affinity HWLOC_NAME(cpuset_from_glibc_sched_affinity)
522
+
523
+ /* linux-libnuma.h */
524
+
525
+ #define hwloc_cpuset_to_linux_libnuma_ulongs HWLOC_NAME(cpuset_to_linux_libnuma_ulongs)
526
+ #define hwloc_nodeset_to_linux_libnuma_ulongs HWLOC_NAME(nodeset_to_linux_libnuma_ulongs)
527
+ #define hwloc_cpuset_from_linux_libnuma_ulongs HWLOC_NAME(cpuset_from_linux_libnuma_ulongs)
528
+ #define hwloc_nodeset_from_linux_libnuma_ulongs HWLOC_NAME(nodeset_from_linux_libnuma_ulongs)
529
+ #define hwloc_cpuset_to_linux_libnuma_bitmask HWLOC_NAME(cpuset_to_linux_libnuma_bitmask)
530
+ #define hwloc_nodeset_to_linux_libnuma_bitmask HWLOC_NAME(nodeset_to_linux_libnuma_bitmask)
531
+ #define hwloc_cpuset_from_linux_libnuma_bitmask HWLOC_NAME(cpuset_from_linux_libnuma_bitmask)
532
+ #define hwloc_nodeset_from_linux_libnuma_bitmask HWLOC_NAME(nodeset_from_linux_libnuma_bitmask)
533
+
534
+ /* linux.h */
535
+
536
+ #define hwloc_linux_set_tid_cpubind HWLOC_NAME(linux_set_tid_cpubind)
537
+ #define hwloc_linux_get_tid_cpubind HWLOC_NAME(linux_get_tid_cpubind)
538
+ #define hwloc_linux_get_tid_last_cpu_location HWLOC_NAME(linux_get_tid_last_cpu_location)
539
+ #define hwloc_linux_read_path_as_cpumask HWLOC_NAME(linux_read_file_cpumask)
540
+
541
+ /* windows.h */
542
+
543
+ #define hwloc_windows_get_nr_processor_groups HWLOC_NAME(windows_get_nr_processor_groups)
544
+ #define hwloc_windows_get_processor_group_cpuset HWLOC_NAME(windows_get_processor_group_cpuset)
545
+
546
+ /* openfabrics-verbs.h */
547
+
548
+ #define hwloc_ibv_get_device_cpuset HWLOC_NAME(ibv_get_device_cpuset)
549
+ #define hwloc_ibv_get_device_osdev HWLOC_NAME(ibv_get_device_osdev)
550
+ #define hwloc_ibv_get_device_osdev_by_name HWLOC_NAME(ibv_get_device_osdev_by_name)
551
+
552
+ /* opencl.h */
553
+
554
+ #define hwloc_cl_device_topology_amd HWLOC_NAME(cl_device_topology_amd)
555
+ #define hwloc_opencl_get_device_pci_busid HWLOC_NAME(opencl_get_device_pci_ids)
556
+ #define hwloc_opencl_get_device_cpuset HWLOC_NAME(opencl_get_device_cpuset)
557
+ #define hwloc_opencl_get_device_osdev HWLOC_NAME(opencl_get_device_osdev)
558
+ #define hwloc_opencl_get_device_osdev_by_index HWLOC_NAME(opencl_get_device_osdev_by_index)
559
+
560
+ /* cuda.h */
561
+
562
+ #define hwloc_cuda_get_device_pci_ids HWLOC_NAME(cuda_get_device_pci_ids)
563
+ #define hwloc_cuda_get_device_cpuset HWLOC_NAME(cuda_get_device_cpuset)
564
+ #define hwloc_cuda_get_device_pcidev HWLOC_NAME(cuda_get_device_pcidev)
565
+ #define hwloc_cuda_get_device_osdev HWLOC_NAME(cuda_get_device_osdev)
566
+ #define hwloc_cuda_get_device_osdev_by_index HWLOC_NAME(cuda_get_device_osdev_by_index)
567
+
568
+ /* cudart.h */
569
+
570
+ #define hwloc_cudart_get_device_pci_ids HWLOC_NAME(cudart_get_device_pci_ids)
571
+ #define hwloc_cudart_get_device_cpuset HWLOC_NAME(cudart_get_device_cpuset)
572
+ #define hwloc_cudart_get_device_pcidev HWLOC_NAME(cudart_get_device_pcidev)
573
+ #define hwloc_cudart_get_device_osdev_by_index HWLOC_NAME(cudart_get_device_osdev_by_index)
574
+
575
+ /* nvml.h */
576
+
577
+ #define hwloc_nvml_get_device_cpuset HWLOC_NAME(nvml_get_device_cpuset)
578
+ #define hwloc_nvml_get_device_osdev HWLOC_NAME(nvml_get_device_osdev)
579
+ #define hwloc_nvml_get_device_osdev_by_index HWLOC_NAME(nvml_get_device_osdev_by_index)
580
+
581
+ /* rsmi.h */
582
+
583
+ #define hwloc_rsmi_get_device_cpuset HWLOC_NAME(rsmi_get_device_cpuset)
584
+ #define hwloc_rsmi_get_device_osdev HWLOC_NAME(rsmi_get_device_osdev)
585
+ #define hwloc_rsmi_get_device_osdev_by_index HWLOC_NAME(rsmi_get_device_osdev_by_index)
586
+
587
+ /* levelzero.h */
588
+
589
+ #define hwloc_levelzero_get_device_cpuset HWLOC_NAME(levelzero_get_device_cpuset)
590
+ #define hwloc_levelzero_get_device_osdev HWLOC_NAME(levelzero_get_device_osdev)
591
+
592
+ /* gl.h */
593
+
594
+ #define hwloc_gl_get_display_osdev_by_port_device HWLOC_NAME(gl_get_display_osdev_by_port_device)
595
+ #define hwloc_gl_get_display_osdev_by_name HWLOC_NAME(gl_get_display_osdev_by_name)
596
+ #define hwloc_gl_get_display_by_osdev HWLOC_NAME(gl_get_display_by_osdev)
597
+
598
+ /* hwloc/plugins.h */
599
+
600
+ #define hwloc_disc_phase_e HWLOC_NAME(disc_phase_e)
601
+ #define HWLOC_DISC_PHASE_GLOBAL HWLOC_NAME_CAPS(DISC_PHASE_GLOBAL)
602
+ #define HWLOC_DISC_PHASE_CPU HWLOC_NAME_CAPS(DISC_PHASE_CPU)
603
+ #define HWLOC_DISC_PHASE_MEMORY HWLOC_NAME_CAPS(DISC_PHASE_MEMORY)
604
+ #define HWLOC_DISC_PHASE_PCI HWLOC_NAME_CAPS(DISC_PHASE_PCI)
605
+ #define HWLOC_DISC_PHASE_IO HWLOC_NAME_CAPS(DISC_PHASE_IO)
606
+ #define HWLOC_DISC_PHASE_MISC HWLOC_NAME_CAPS(DISC_PHASE_MISC)
607
+ #define HWLOC_DISC_PHASE_ANNOTATE HWLOC_NAME_CAPS(DISC_PHASE_ANNOTATE)
608
+ #define HWLOC_DISC_PHASE_TWEAK HWLOC_NAME_CAPS(DISC_PHASE_TWEAK)
609
+ #define hwloc_disc_phase_t HWLOC_NAME(disc_phase_t)
610
+ #define hwloc_disc_component HWLOC_NAME(disc_component)
611
+
612
+ #define hwloc_disc_status_flag_e HWLOC_NAME(disc_status_flag_e)
613
+ #define HWLOC_DISC_STATUS_FLAG_GOT_ALLOWED_RESOURCES HWLOC_NAME_CAPS(DISC_STATUS_FLAG_GOT_ALLOWED_RESOURCES)
614
+ #define hwloc_disc_status HWLOC_NAME(disc_status)
615
+
616
+ #define hwloc_backend HWLOC_NAME(backend)
617
+
618
+ #define hwloc_backend_alloc HWLOC_NAME(backend_alloc)
619
+ #define hwloc_backend_enable HWLOC_NAME(backend_enable)
620
+
621
+ #define hwloc_component_type_e HWLOC_NAME(component_type_e)
622
+ #define HWLOC_COMPONENT_TYPE_DISC HWLOC_NAME_CAPS(COMPONENT_TYPE_DISC)
623
+ #define HWLOC_COMPONENT_TYPE_XML HWLOC_NAME_CAPS(COMPONENT_TYPE_XML)
624
+ #define hwloc_component_type_t HWLOC_NAME(component_type_t)
625
+ #define hwloc_component HWLOC_NAME(component)
626
+
627
+ #define hwloc_plugin_check_namespace HWLOC_NAME(plugin_check_namespace)
628
+
629
+ #define hwloc_hide_errors HWLOC_NAME(hide_errors)
630
+ #define hwloc__insert_object_by_cpuset HWLOC_NAME(_insert_object_by_cpuset)
631
+ #define hwloc_insert_object_by_parent HWLOC_NAME(insert_object_by_parent)
632
+ #define hwloc_alloc_setup_object HWLOC_NAME(alloc_setup_object)
633
+ #define hwloc_obj_add_children_sets HWLOC_NAME(add_children_sets)
634
+ #define hwloc_topology_reconnect HWLOC_NAME(topology_reconnect)
635
+
636
+ #define hwloc_filter_check_pcidev_subtype_important HWLOC_NAME(filter_check_pcidev_subtype_important)
637
+ #define hwloc_filter_check_osdev_subtype_important HWLOC_NAME(filter_check_osdev_subtype_important)
638
+ #define hwloc_filter_check_keep_object_type HWLOC_NAME(filter_check_keep_object_type)
639
+ #define hwloc_filter_check_keep_object HWLOC_NAME(filter_check_keep_object)
640
+
641
+ #define hwloc_pcidisc_find_cap HWLOC_NAME(pcidisc_find_cap)
642
+ #define hwloc_pcidisc_find_linkspeed HWLOC_NAME(pcidisc_find_linkspeed)
643
+ #define hwloc_pcidisc_check_bridge_type HWLOC_NAME(pcidisc_check_bridge_type)
644
+ #define hwloc_pcidisc_find_bridge_buses HWLOC_NAME(pcidisc_find_bridge_buses)
645
+ #define hwloc_pcidisc_tree_insert_by_busid HWLOC_NAME(pcidisc_tree_insert_by_busid)
646
+ #define hwloc_pcidisc_tree_attach HWLOC_NAME(pcidisc_tree_attach)
647
+
648
+ #define hwloc_pci_find_by_busid HWLOC_NAME(pcidisc_find_by_busid)
649
+ #define hwloc_pci_find_parent_by_busid HWLOC_NAME(pcidisc_find_busid_parent)
650
+
651
+ #define hwloc_backend_distances_add_handle_t HWLOC_NAME(backend_distances_add_handle_t)
652
+ #define hwloc_backend_distances_add_create HWLOC_NAME(backend_distances_add_create)
653
+ #define hwloc_backend_distances_add_values HWLOC_NAME(backend_distances_add_values)
654
+ #define hwloc_backend_distances_add_commit HWLOC_NAME(backend_distances_add_commit)
655
+
656
+ /* hwloc/deprecated.h */
657
+
658
+ #define hwloc_distances_add HWLOC_NAME(distances_add)
659
+
660
+ #define hwloc_topology_insert_misc_object_by_parent HWLOC_NAME(topology_insert_misc_object_by_parent)
661
+ #define hwloc_obj_cpuset_snprintf HWLOC_NAME(obj_cpuset_snprintf)
662
+ #define hwloc_obj_type_sscanf HWLOC_NAME(obj_type_sscanf)
663
+
664
+ #define hwloc_set_membind_nodeset HWLOC_NAME(set_membind_nodeset)
665
+ #define hwloc_get_membind_nodeset HWLOC_NAME(get_membind_nodeset)
666
+ #define hwloc_set_proc_membind_nodeset HWLOC_NAME(set_proc_membind_nodeset)
667
+ #define hwloc_get_proc_membind_nodeset HWLOC_NAME(get_proc_membind_nodeset)
668
+ #define hwloc_set_area_membind_nodeset HWLOC_NAME(set_area_membind_nodeset)
669
+ #define hwloc_get_area_membind_nodeset HWLOC_NAME(get_area_membind_nodeset)
670
+ #define hwloc_alloc_membind_nodeset HWLOC_NAME(alloc_membind_nodeset)
671
+
672
+ #define hwloc_cpuset_to_nodeset_strict HWLOC_NAME(cpuset_to_nodeset_strict)
673
+ #define hwloc_cpuset_from_nodeset_strict HWLOC_NAME(cpuset_from_nodeset_strict)
674
+
675
+ /* private/debug.h */
676
+
677
+ #define hwloc_debug_enabled HWLOC_NAME(debug_enabled)
678
+ #define hwloc_debug HWLOC_NAME(debug)
679
+
680
+ /* private/misc.h */
681
+
682
+ #ifndef HWLOC_HAVE_CORRECT_SNPRINTF
683
+ #define hwloc_snprintf HWLOC_NAME(snprintf)
684
+ #endif
685
+ #define hwloc_ffsl_manual HWLOC_NAME(ffsl_manual)
686
+ #define hwloc_ffs32 HWLOC_NAME(ffs32)
687
+ #define hwloc_ffsl_from_ffs32 HWLOC_NAME(ffsl_from_ffs32)
688
+ #define hwloc_flsl_manual HWLOC_NAME(flsl_manual)
689
+ #define hwloc_fls32 HWLOC_NAME(fls32)
690
+ #define hwloc_flsl_from_fls32 HWLOC_NAME(flsl_from_fls32)
691
+ #define hwloc_weight_long HWLOC_NAME(weight_long)
692
+ #define hwloc_strncasecmp HWLOC_NAME(strncasecmp)
693
+
694
+ #define hwloc_bitmap_compare_inclusion HWLOC_NAME(bitmap_compare_inclusion)
695
+
696
+ #define hwloc_pci_class_string HWLOC_NAME(pci_class_string)
697
+ #define hwloc_linux_pci_link_speed_from_string HWLOC_NAME(linux_pci_link_speed_from_string)
698
+
699
+ #define hwloc_cache_type_by_depth_type HWLOC_NAME(cache_type_by_depth_type)
700
+ #define hwloc__obj_type_is_normal HWLOC_NAME(_obj_type_is_normal)
701
+ #define hwloc__obj_type_is_memory HWLOC_NAME(_obj_type_is_memory)
702
+ #define hwloc__obj_type_is_io HWLOC_NAME(_obj_type_is_io)
703
+ #define hwloc__obj_type_is_special HWLOC_NAME(_obj_type_is_special)
704
+
705
+ #define hwloc__obj_type_is_cache HWLOC_NAME(_obj_type_is_cache)
706
+ #define hwloc__obj_type_is_dcache HWLOC_NAME(_obj_type_is_dcache)
707
+ #define hwloc__obj_type_is_icache HWLOC_NAME(_obj_type_is_icache)
708
+
709
+ /* private/cpuid-x86.h */
710
+
711
+ #define hwloc_have_x86_cpuid HWLOC_NAME(have_x86_cpuid)
712
+ #define hwloc_x86_cpuid HWLOC_NAME(x86_cpuid)
713
+
714
+ /* private/xml.h */
715
+
716
+ #define hwloc__xml_verbose HWLOC_NAME(_xml_verbose)
717
+
718
+ #define hwloc__xml_import_state_s HWLOC_NAME(_xml_import_state_s)
719
+ #define hwloc__xml_import_state_t HWLOC_NAME(_xml_import_state_t)
720
+ #define hwloc__xml_import_diff HWLOC_NAME(_xml_import_diff)
721
+ #define hwloc_xml_backend_data_s HWLOC_NAME(xml_backend_data_s)
722
+ #define hwloc__xml_export_state_s HWLOC_NAME(_xml_export_state_s)
723
+ #define hwloc__xml_export_state_t HWLOC_NAME(_xml_export_state_t)
724
+ #define hwloc__xml_export_data_s HWLOC_NAME(_xml_export_data_s)
725
+ #define hwloc__xml_export_topology HWLOC_NAME(_xml_export_topology)
726
+ #define hwloc__xml_export_diff HWLOC_NAME(_xml_export_diff)
727
+
728
+ #define hwloc_xml_callbacks HWLOC_NAME(xml_callbacks)
729
+ #define hwloc_xml_component HWLOC_NAME(xml_component)
730
+ #define hwloc_xml_callbacks_register HWLOC_NAME(xml_callbacks_register)
731
+ #define hwloc_xml_callbacks_reset HWLOC_NAME(xml_callbacks_reset)
732
+
733
+ #define hwloc__xml_imported_v1distances_s HWLOC_NAME(_xml_imported_v1distances_s)
734
+
735
+ /* private/components.h */
736
+
737
+ #define hwloc_disc_component_force_enable HWLOC_NAME(disc_component_force_enable)
738
+ #define hwloc_disc_components_enable_others HWLOC_NAME(disc_components_instantiate_others)
739
+
740
+ #define hwloc_backends_is_thissystem HWLOC_NAME(backends_is_thissystem)
741
+ #define hwloc_backends_find_callbacks HWLOC_NAME(backends_find_callbacks)
742
+
743
+ #define hwloc_topology_components_init HWLOC_NAME(topology_components_init)
744
+ #define hwloc_backends_disable_all HWLOC_NAME(backends_disable_all)
745
+ #define hwloc_topology_components_fini HWLOC_NAME(topology_components_fini)
746
+
747
+ #define hwloc_components_init HWLOC_NAME(components_init)
748
+ #define hwloc_components_fini HWLOC_NAME(components_fini)
749
+
750
+ /* private/internal-private.h */
751
+
752
+ #define hwloc_xml_component HWLOC_NAME(xml_component)
753
+ #define hwloc_synthetic_component HWLOC_NAME(synthetic_component)
754
+
755
+ #define hwloc_aix_component HWLOC_NAME(aix_component)
756
+ #define hwloc_bgq_component HWLOC_NAME(bgq_component)
757
+ #define hwloc_darwin_component HWLOC_NAME(darwin_component)
758
+ #define hwloc_freebsd_component HWLOC_NAME(freebsd_component)
759
+ #define hwloc_hpux_component HWLOC_NAME(hpux_component)
760
+ #define hwloc_linux_component HWLOC_NAME(linux_component)
761
+ #define hwloc_netbsd_component HWLOC_NAME(netbsd_component)
762
+ #define hwloc_noos_component HWLOC_NAME(noos_component)
763
+ #define hwloc_solaris_component HWLOC_NAME(solaris_component)
764
+ #define hwloc_windows_component HWLOC_NAME(windows_component)
765
+ #define hwloc_x86_component HWLOC_NAME(x86_component)
766
+
767
+ #define hwloc_cuda_component HWLOC_NAME(cuda_component)
768
+ #define hwloc_gl_component HWLOC_NAME(gl_component)
769
+ #define hwloc_levelzero_component HWLOC_NAME(levelzero_component)
770
+ #define hwloc_nvml_component HWLOC_NAME(nvml_component)
771
+ #define hwloc_rsmi_component HWLOC_NAME(rsmi_component)
772
+ #define hwloc_opencl_component HWLOC_NAME(opencl_component)
773
+ #define hwloc_pci_component HWLOC_NAME(pci_component)
774
+
775
+ #define hwloc_xml_libxml_component HWLOC_NAME(xml_libxml_component)
776
+ #define hwloc_xml_nolibxml_component HWLOC_NAME(xml_nolibxml_component)
777
+
778
+ /* private/private.h */
779
+
780
+ #define hwloc_internal_location_s HWLOC_NAME(internal_location_s)
781
+
782
+ #define hwloc_special_level_s HWLOC_NAME(special_level_s)
783
+
784
+ #define hwloc_pci_forced_locality_s HWLOC_NAME(pci_forced_locality_s)
785
+ #define hwloc_pci_locality_s HWLOC_NAME(pci_locality_s)
786
+
787
+ #define hwloc_topology_forced_component_s HWLOC_NAME(topology_forced_component)
788
+
789
+ #define hwloc_alloc_root_sets HWLOC_NAME(alloc_root_sets)
790
+ #define hwloc_setup_pu_level HWLOC_NAME(setup_pu_level)
791
+ #define hwloc_get_sysctlbyname HWLOC_NAME(get_sysctlbyname)
792
+ #define hwloc_get_sysctl HWLOC_NAME(get_sysctl)
793
+ #define hwloc_fallback_nbprocessors HWLOC_NAME(fallback_nbprocessors)
794
+ #define hwloc_fallback_memsize HWLOC_NAME(fallback_memsize)
795
+
796
+ #define hwloc__object_cpusets_compare_first HWLOC_NAME(_object_cpusets_compare_first)
797
+ #define hwloc__reorder_children HWLOC_NAME(_reorder_children)
798
+
799
+ #define hwloc_topology_setup_defaults HWLOC_NAME(topology_setup_defaults)
800
+ #define hwloc_topology_clear HWLOC_NAME(topology_clear)
801
+
802
+ #define hwloc__attach_memory_object HWLOC_NAME(insert_memory_object)
803
+
804
+ #define hwloc_get_obj_by_type_and_gp_index HWLOC_NAME(get_obj_by_type_and_gp_index)
805
+
806
+ #define hwloc_pci_discovery_init HWLOC_NAME(pci_discovery_init)
807
+ #define hwloc_pci_discovery_prepare HWLOC_NAME(pci_discovery_prepare)
808
+ #define hwloc_pci_discovery_exit HWLOC_NAME(pci_discovery_exit)
809
+ #define hwloc_find_insert_io_parent_by_complete_cpuset HWLOC_NAME(hwloc_find_insert_io_parent_by_complete_cpuset)
810
+
811
+ #define hwloc__add_info HWLOC_NAME(_add_info)
812
+ #define hwloc__add_info_nodup HWLOC_NAME(_add_info_nodup)
813
+ #define hwloc__move_infos HWLOC_NAME(_move_infos)
814
+ #define hwloc__free_infos HWLOC_NAME(_free_infos)
815
+ #define hwloc__tma_dup_infos HWLOC_NAME(_tma_dup_infos)
816
+
817
+ #define hwloc_binding_hooks HWLOC_NAME(binding_hooks)
818
+ #define hwloc_set_native_binding_hooks HWLOC_NAME(set_native_binding_hooks)
819
+ #define hwloc_set_binding_hooks HWLOC_NAME(set_binding_hooks)
820
+
821
+ #define hwloc_set_linuxfs_hooks HWLOC_NAME(set_linuxfs_hooks)
822
+ #define hwloc_set_bgq_hooks HWLOC_NAME(set_bgq_hooks)
823
+ #define hwloc_set_solaris_hooks HWLOC_NAME(set_solaris_hooks)
824
+ #define hwloc_set_aix_hooks HWLOC_NAME(set_aix_hooks)
825
+ #define hwloc_set_windows_hooks HWLOC_NAME(set_windows_hooks)
826
+ #define hwloc_set_darwin_hooks HWLOC_NAME(set_darwin_hooks)
827
+ #define hwloc_set_freebsd_hooks HWLOC_NAME(set_freebsd_hooks)
828
+ #define hwloc_set_netbsd_hooks HWLOC_NAME(set_netbsd_hooks)
829
+ #define hwloc_set_hpux_hooks HWLOC_NAME(set_hpux_hooks)
830
+
831
+ #define hwloc_look_hardwired_fujitsu_k HWLOC_NAME(look_hardwired_fujitsu_k)
832
+ #define hwloc_look_hardwired_fujitsu_fx10 HWLOC_NAME(look_hardwired_fujitsu_fx10)
833
+ #define hwloc_look_hardwired_fujitsu_fx100 HWLOC_NAME(look_hardwired_fujitsu_fx100)
834
+
835
+ #define hwloc_add_uname_info HWLOC_NAME(add_uname_info)
836
+ #define hwloc_free_unlinked_object HWLOC_NAME(free_unlinked_object)
837
+ #define hwloc_free_object_and_children HWLOC_NAME(free_object_and_children)
838
+ #define hwloc_free_object_siblings_and_children HWLOC_NAME(free_object_siblings_and_children)
839
+
840
+ #define hwloc_alloc_heap HWLOC_NAME(alloc_heap)
841
+ #define hwloc_alloc_mmap HWLOC_NAME(alloc_mmap)
842
+ #define hwloc_free_heap HWLOC_NAME(free_heap)
843
+ #define hwloc_free_mmap HWLOC_NAME(free_mmap)
844
+ #define hwloc_alloc_or_fail HWLOC_NAME(alloc_or_fail)
845
+
846
+ #define hwloc_internal_distances_s HWLOC_NAME(internal_distances_s)
847
+ #define hwloc_internal_distances_init HWLOC_NAME(internal_distances_init)
848
+ #define hwloc_internal_distances_prepare HWLOC_NAME(internal_distances_prepare)
849
+ #define hwloc_internal_distances_dup HWLOC_NAME(internal_distances_dup)
850
+ #define hwloc_internal_distances_refresh HWLOC_NAME(internal_distances_refresh)
851
+ #define hwloc_internal_distances_destroy HWLOC_NAME(internal_distances_destroy)
852
+ #define hwloc_internal_distances_add HWLOC_NAME(internal_distances_add)
853
+ #define hwloc_internal_distances_add_by_index HWLOC_NAME(internal_distances_add_by_index)
854
+ #define hwloc_internal_distances_invalidate_cached_objs HWLOC_NAME(hwloc_internal_distances_invalidate_cached_objs)
855
+
856
+ #define hwloc_internal_memattr_s HWLOC_NAME(internal_memattr_s)
857
+ #define hwloc_internal_memattr_target_s HWLOC_NAME(internal_memattr_target_s)
858
+ #define hwloc_internal_memattr_initiator_s HWLOC_NAME(internal_memattr_initiator_s)
859
+ #define hwloc_internal_memattrs_init HWLOC_NAME(internal_memattrs_init)
860
+ #define hwloc_internal_memattrs_prepare HWLOC_NAME(internal_memattrs_prepare)
861
+ #define hwloc_internal_memattrs_dup HWLOC_NAME(internal_memattrs_dup)
862
+ #define hwloc_internal_memattrs_destroy HWLOC_NAME(internal_memattrs_destroy)
863
+ #define hwloc_internal_memattrs_need_refresh HWLOC_NAME(internal_memattrs_need_refresh)
864
+ #define hwloc_internal_memattrs_refresh HWLOC_NAME(internal_memattrs_refresh)
865
+
866
+ #define hwloc_internal_cpukind_s HWLOC_NAME(internal_cpukind_s)
867
+ #define hwloc_internal_cpukinds_init HWLOC_NAME(internal_cpukinds_init)
868
+ #define hwloc_internal_cpukinds_destroy HWLOC_NAME(internal_cpukinds_destroy)
869
+ #define hwloc_internal_cpukinds_dup HWLOC_NAME(internal_cpukinds_dup)
870
+ #define hwloc_internal_cpukinds_register HWLOC_NAME(internal_cpukinds_register)
871
+ #define hwloc_internal_cpukinds_rank HWLOC_NAME(internal_cpukinds_rank)
872
+ #define hwloc_internal_cpukinds_restrict HWLOC_NAME(internal_cpukinds_restrict)
873
+
874
+ #define hwloc_encode_to_base64 HWLOC_NAME(encode_to_base64)
875
+ #define hwloc_decode_from_base64 HWLOC_NAME(decode_from_base64)
876
+
877
+ #define hwloc_progname HWLOC_NAME(progname)
878
+
879
+ #define hwloc__topology_disadopt HWLOC_NAME(_topology_disadopt)
880
+ #define hwloc__topology_dup HWLOC_NAME(_topology_dup)
881
+
882
+ #define hwloc_tma HWLOC_NAME(tma)
883
+ #define hwloc_tma_malloc HWLOC_NAME(tma_malloc)
884
+ #define hwloc_tma_calloc HWLOC_NAME(tma_calloc)
885
+ #define hwloc_tma_strdup HWLOC_NAME(tma_strdup)
886
+ #define hwloc_bitmap_tma_dup HWLOC_NAME(bitmap_tma_dup)
887
+
888
+ /* private/solaris-chiptype.h */
889
+
890
+ #define hwloc_solaris_chip_info_s HWLOC_NAME(solaris_chip_info_s)
891
+ #define hwloc_solaris_get_chip_info HWLOC_NAME(solaris_get_chip_info)
892
+
893
+ #endif /* HWLOC_SYM_TRANSFORM */
894
+
895
+
896
+ #ifdef __cplusplus
897
+ } /* extern "C" */
898
+ #endif
899
+
900
+
901
+ #endif /* HWLOC_RENAME_H */
deps/exla/cache/xla_extension/include/include/hwloc/shmem.h ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Copyright © 2013-2018 Inria. All rights reserved.
3
+ * See COPYING in top-level directory.
4
+ */
5
+
6
+ /** \file
7
+ * \brief Sharing topologies between processes
8
+ */
9
+
10
+ #ifndef HWLOC_SHMEM_H
11
+ #define HWLOC_SHMEM_H
12
+
13
+ #include "hwloc.h"
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #elif 0
18
+ }
19
+ #endif
20
+
21
+
22
+ /** \defgroup hwlocality_shmem Sharing topologies between processes
23
+ *
24
+ * These functions are used to share a topology between processes by
25
+ * duplicating it into a file-backed shared-memory buffer.
26
+ *
27
+ * The master process must first get the required shared-memory size
28
+ * for storing this topology with hwloc_shmem_topology_get_length().
29
+ *
30
+ * Then it must find a virtual memory area of that size that is available
31
+ * in all processes (identical virtual addresses in all processes).
32
+ * On Linux, this can be done by comparing holes found in /proc/\<pid\>/maps
33
+ * for each process.
34
+ *
35
+ * Once found, it must open a destination file for storing the buffer,
36
+ * and pass it to hwloc_shmem_topology_write() together with
37
+ * virtual memory address and length obtained above.
38
+ *
39
+ * Other processes may then adopt this shared topology by opening the
40
+ * same file and passing it to hwloc_shmem_topology_adopt() with the
41
+ * exact same virtual memory address and length.
42
+ *
43
+ * @{
44
+ */
45
+
46
+ /** \brief Get the required shared memory length for storing a topology.
47
+ *
48
+ * This length (in bytes) must be used in hwloc_shmem_topology_write()
49
+ * and hwloc_shmem_topology_adopt() later.
50
+ *
51
+ * \note Flags \p flags are currently unused, must be 0.
52
+ */
53
+ HWLOC_DECLSPEC int hwloc_shmem_topology_get_length(hwloc_topology_t topology,
54
+ size_t *lengthp,
55
+ unsigned long flags);
56
+
57
+ /** \brief Duplicate a topology to a shared memory file.
58
+ *
59
+ * Temporarily map a file in virtual memory and duplicate the
60
+ * topology \p topology by allocating duplicates in there.
61
+ *
62
+ * The segment of the file pointed by descriptor \p fd,
63
+ * starting at offset \p fileoffset, and of length \p length (in bytes),
64
+ * will be temporarily mapped at virtual address \p mmap_address
65
+ * during the duplication.
66
+ *
67
+ * The mapping length \p length must have been previously obtained with
68
+ * hwloc_shmem_topology_get_length()
69
+ * and the topology must not have been modified in the meantime.
70
+ *
71
+ * \note Flags \p flags are currently unused, must be 0.
72
+ *
73
+ * \note The object userdata pointer is duplicated but the pointed buffer
74
+ * is not. However the caller may also allocate it manually in shared memory
75
+ * to share it as well.
76
+ *
77
+ * \return -1 with errno set to EBUSY if the virtual memory mapping defined
78
+ * by \p mmap_address and \p length isn't available in the process.
79
+ * \return -1 with errno set to EINVAL if \p fileoffset, \p mmap_address
80
+ * or \p length aren't page-aligned.
81
+ */
82
+ HWLOC_DECLSPEC int hwloc_shmem_topology_write(hwloc_topology_t topology,
83
+ int fd, hwloc_uint64_t fileoffset,
84
+ void *mmap_address, size_t length,
85
+ unsigned long flags);
86
+
87
+ /** \brief Adopt a shared memory topology stored in a file.
88
+ *
89
+ * Map a file in virtual memory and adopt the topology that was previously
90
+ * stored there with hwloc_shmem_topology_write().
91
+ *
92
+ * The returned adopted topology in \p topologyp can be used just like any
93
+ * topology. And it must be destroyed with hwloc_topology_destroy() as usual.
94
+ *
95
+ * However the topology is read-only.
96
+ * For instance, it cannot be modified with hwloc_topology_restrict()
97
+ * and object userdata pointers cannot be changed.
98
+ *
99
+ * The segment of the file pointed by descriptor \p fd,
100
+ * starting at offset \p fileoffset, and of length \p length (in bytes),
101
+ * will be mapped at virtual address \p mmap_address.
102
+ *
103
+ * The file pointed by descriptor \p fd, the offset \p fileoffset,
104
+ * the requested mapping virtual address \p mmap_address and the length \p length
105
+ * must be identical to what was given to hwloc_shmem_topology_write() earlier.
106
+ *
107
+ * \note Flags \p flags are currently unused, must be 0.
108
+ *
109
+ * \note The object userdata pointer should not be used unless the process
110
+ * that created the shared topology also placed userdata-pointed buffers
111
+ * in shared memory.
112
+ *
113
+ * \note This function takes care of calling hwloc_topology_abi_check().
114
+ *
115
+ * \return -1 with errno set to EBUSY if the virtual memory mapping defined
116
+ * by \p mmap_address and \p length isn't available in the process.
117
+ *
118
+ * \return -1 with errno set to EINVAL if \p fileoffset, \p mmap_address
119
+ * or \p length aren't page-aligned, or do not match what was given to
120
+ * hwloc_shmem_topology_write() earlier.
121
+ *
122
+ * \return -1 with errno set to EINVAL if the layout of the topology structure
123
+ * is different between the writer process and the adopter process.
124
+ */
125
+ HWLOC_DECLSPEC int hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
126
+ int fd, hwloc_uint64_t fileoffset,
127
+ void *mmap_address, size_t length,
128
+ unsigned long flags);
129
+ /** @} */
130
+
131
+
132
+ #ifdef __cplusplus
133
+ } /* extern "C" */
134
+ #endif
135
+
136
+
137
+ #endif /* HWLOC_SHMEM_H */
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl.h ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl.hpp ADDED
The diff for this file is too large to render. See raw diff
 
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_common.h ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022-2023 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ /// @file
18
+ /// C common API
19
+
20
+ #ifndef ONEAPI_DNNL_DNNL_COMMON_H
21
+ #define ONEAPI_DNNL_DNNL_COMMON_H
22
+
23
+ #include "oneapi/dnnl/dnnl_common_types.h"
24
+ #include "oneapi/dnnl/dnnl_config.h"
25
+ #include "oneapi/dnnl/dnnl_version.h"
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ /// @addtogroup dnnl_api oneDNN API
32
+ /// @{
33
+
34
+ /// @addtogroup dnnl_api_common Common API
35
+ /// @{
36
+
37
+ /// @addtogroup dnnl_api_engine Engine
38
+ /// @{
39
+
40
+ /// Returns the number of engines of a particular kind.
41
+ ///
42
+ /// @param kind Kind of engines to count.
43
+ /// @returns Count of the engines.
44
+ size_t DNNL_API dnnl_engine_get_count(dnnl_engine_kind_t kind);
45
+
46
+ /// Creates an engine.
47
+ ///
48
+ /// @param engine Output engine.
49
+ /// @param kind Engine kind.
50
+ /// @param index Engine index that should be between 0 and the count of
51
+ /// engines of the requested kind.
52
+ /// @returns #dnnl_success on success and a status describing the error
53
+ /// otherwise.
54
+ dnnl_status_t DNNL_API dnnl_engine_create(
55
+ dnnl_engine_t *engine, dnnl_engine_kind_t kind, size_t index);
56
+
57
+ /// Returns the kind of an engine.
58
+ ///
59
+ /// @param engine Engine to query.
60
+ /// @param kind Output engine kind.
61
+ /// @returns #dnnl_success on success and a status describing the error
62
+ /// otherwise.
63
+ dnnl_status_t DNNL_API dnnl_engine_get_kind(
64
+ dnnl_engine_t engine, dnnl_engine_kind_t *kind);
65
+
66
+ /// Destroys an engine.
67
+ ///
68
+ /// @param engine Engine to destroy.
69
+ /// @returns #dnnl_success on success and a status describing the error
70
+ /// otherwise.
71
+ dnnl_status_t DNNL_API dnnl_engine_destroy(dnnl_engine_t engine);
72
+
73
+ /// @} dnnl_api_engine
74
+
75
+ /// @addtogroup dnnl_api_stream Stream
76
+ /// @{
77
+
78
+ /// Creates an execution stream.
79
+ ///
80
+ /// @param stream Output execution stream.
81
+ /// @param engine Engine to create the execution stream on.
82
+ /// @param flags Stream behavior flags (@sa dnnl_stream_flags_t).
83
+ /// @returns #dnnl_success on success and a status describing the error
84
+ /// otherwise.
85
+ dnnl_status_t DNNL_API dnnl_stream_create(
86
+ dnnl_stream_t *stream, dnnl_engine_t engine, unsigned flags);
87
+
88
+ /// Returns the engine of a stream object.
89
+ ///
90
+ /// @param stream Stream object.
91
+ /// @param engine Output engine on which the stream is created.
92
+ /// @returns #dnnl_success on success and a status describing the error
93
+ /// otherwise.
94
+ dnnl_status_t DNNL_API dnnl_stream_get_engine(
95
+ const_dnnl_stream_t stream, dnnl_engine_t *engine);
96
+
97
+ /// Waits for all primitives in the execution stream to finish computations.
98
+ ///
99
+ /// @param stream Execution stream.
100
+ /// @returns #dnnl_success on success and a status describing the error
101
+ /// otherwise.
102
+ dnnl_status_t DNNL_API dnnl_stream_wait(dnnl_stream_t stream);
103
+
104
+ /// Destroys an execution stream.
105
+ ///
106
+ /// @param stream Execution stream to destroy.
107
+ /// @returns #dnnl_success on success and a status describing the error
108
+ /// otherwise.
109
+ dnnl_status_t DNNL_API dnnl_stream_destroy(dnnl_stream_t stream);
110
+
111
+ /// @} dnnl_api_stream
112
+
113
+ /// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
114
+ /// @{
115
+
116
+ /// Returns the floating-point math mode that will be used by default
117
+ /// for all subsequently created primitives.
118
+ ///
119
+ /// @param mode Output FP math mode.
120
+ /// @returns #dnnl_success on success and a status describing the error
121
+ /// otherwise.
122
+ dnnl_status_t DNNL_API dnnl_get_default_fpmath_mode(dnnl_fpmath_mode_t *mode);
123
+
124
+ /// Sets the floating-point math mode that will be used by default
125
+ /// for all subsequently created primitives.
126
+ ///
127
+ /// @param mode FP math mode. The possible values are:
128
+ /// #dnnl_fpmath_mode_strict,
129
+ /// #dnnl_fpmath_mode_bf16,
130
+ /// #dnnl_fpmath_mode_f16,
131
+ /// #dnnl_fpmath_mode_tf32,
132
+ /// #dnnl_fpmath_mode_any.
133
+ /// @returns #dnnl_success on success and a status describing the error
134
+ /// otherwise.
135
+ dnnl_status_t DNNL_API dnnl_set_default_fpmath_mode(dnnl_fpmath_mode_t mode);
136
+
137
+ /// @} dnnl_api_fpmath_mode
138
+
139
+ /// @addtogroup dnnl_api_service
140
+ /// @{
141
+
142
+ /// Configures verbose output to stdout.
143
+ ///
144
+ /// @note
145
+ /// Enabling verbose output affects performance.
146
+ /// This setting overrides the ONEDNN_VERBOSE environment variable.
147
+ ///
148
+ /// @param level Verbosity level:
149
+ /// - 0: no verbose output (default),
150
+ /// - 1: primitive and graph information at execution,
151
+ /// - 2: primitive and graph information at creation/compilation and execution.
152
+ /// @returns #dnnl_invalid_arguments/#dnnl::status::invalid_arguments if the
153
+ /// @p level value is invalid, and #dnnl_success/#dnnl::status::success on
154
+ /// success.
155
+ dnnl_status_t DNNL_API dnnl_set_verbose(int level);
156
+
157
+ /// Returns library version information.
158
+ /// @returns Pointer to a constant structure containing
159
+ /// - major: major version number,
160
+ /// - minor: minor version number,
161
+ /// - patch: patch release number,
162
+ /// - hash: git commit hash.
163
+ const dnnl_version_t DNNL_API *dnnl_version(void);
164
+
165
+ /// @} dnnl_api_service
166
+
167
+ /// @} dnnl_api_common
168
+
169
+ /// @} dnnl_api
170
+
171
+ #ifdef __cplusplus
172
+ }
173
+ #endif
174
+
175
+ #endif /* ONEAPI_DNNL_DNNL_COMMON_H */
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_common.hpp ADDED
@@ -0,0 +1,479 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022-2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ /// @file
18
+ /// C++ common API
19
+
20
+ #ifndef ONEAPI_DNNL_DNNL_COMMON_HPP
21
+ #define ONEAPI_DNNL_DNNL_COMMON_HPP
22
+
23
+ /// @cond DO_NOT_DOCUMENT_THIS
24
+ #include <algorithm>
25
+ #include <cstdlib>
26
+ #include <iterator>
27
+ #include <memory>
28
+ #include <string>
29
+ #include <vector>
30
+ #include <unordered_map>
31
+
32
+ #include "oneapi/dnnl/dnnl_common.h"
33
+
34
+ /// @endcond
35
+
36
+ // __cpp_exceptions is referred from
37
+ // https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html
38
+ // gcc < 5 does not define __cpp_exceptions but __EXCEPTIONS,
39
+ // Microsoft C++ Compiler does not provide an option to disable exceptions
40
+ #ifndef DNNL_ENABLE_EXCEPTIONS
41
+ #if __cpp_exceptions || __EXCEPTIONS \
42
+ || (defined(_MSC_VER) && !defined(__clang__))
43
+ #define DNNL_ENABLE_EXCEPTIONS 1
44
+ #else
45
+ #define DNNL_ENABLE_EXCEPTIONS 0
46
+ #endif
47
+ #endif
48
+
49
+ #if defined(__GNUC__) || defined(__clang__)
50
+ #define DNNL_TRAP() __builtin_trap()
51
+ #elif defined(__INTEL_COMPILER) || defined(_MSC_VER)
52
+ #define DNNL_TRAP() __debugbreak()
53
+ #else
54
+ #error "unknown compiler"
55
+ #endif
56
+
57
+ #if DNNL_ENABLE_EXCEPTIONS
58
+ #define DNNL_THROW_ERROR(status, msg) throw error(status, msg)
59
+ #else
60
+ #include <cstdio>
61
+ #define DNNL_THROW_ERROR(status, msg) \
62
+ do { \
63
+ fputs(msg, stderr); \
64
+ DNNL_TRAP(); \
65
+ } while (0)
66
+ #endif
67
+
68
+ /// @addtogroup dnnl_api oneDNN API
69
+ /// @{
70
+
71
+ /// oneDNN namespace
72
+ namespace dnnl {
73
+
74
+ /// @addtogroup dnnl_api_common Common API
75
+ /// @{
76
+
77
+ /// @addtogroup dnnl_api_utils Utilities
78
+ /// Utility types and definitions.
79
+ /// @{
80
+
81
+ /// oneDNN exception class.
82
+ ///
83
+ /// This class captures the status returned by a failed C API function and
84
+ /// the error message from the call site.
85
+ struct error : public std::exception {
86
+ dnnl_status_t status;
87
+ const char *message;
88
+
89
+ /// Constructs an instance of an exception class.
90
+ ///
91
+ /// @param status The error status returned by a C API function.
92
+ /// @param message The error message.
93
+ error(dnnl_status_t status, const char *message)
94
+ : status(status), message(message) {}
95
+
96
+ /// Returns the explanatory string.
97
+ const char *what() const noexcept override { return message; }
98
+
99
+ /// A convenience function for wrapping calls to C API functions. Checks
100
+ /// the return status and throws an dnnl::error in case of failure.
101
+ ///
102
+ /// @param status The error status returned by a C API function.
103
+ /// @param message The error message.
104
+ static void wrap_c_api(dnnl_status_t status, const char *message) {
105
+ if (status != dnnl_success) DNNL_THROW_ERROR(status, message);
106
+ }
107
+ };
108
+
109
+ /// A class that provides the destructor for a oneDNN C API handle.
110
+ template <typename T>
111
+ struct handle_traits {};
112
+
113
+ /// oneDNN C API handle wrapper class.
114
+ ///
115
+ /// This class is used as the base class for primitive (dnnl::primitive),
116
+ /// engine (dnnl::engine), and stream (dnnl::stream) classes, as well as
117
+ /// others. An object of the dnnl::handle class can be passed by value.
118
+ ///
119
+ /// A handle can be weak, in which case it follows std::weak_ptr semantics.
120
+ /// Otherwise, it follows `std::shared_ptr` semantics.
121
+ ///
122
+ /// @note
123
+ /// The implementation stores oneDNN C API handles in a `std::shared_ptr`
124
+ /// with deleter set to a dummy function in the weak mode.
125
+ ///
126
+ template <typename T, typename traits = handle_traits<T>>
127
+ struct handle {
128
+ private:
129
+ static dnnl_status_t dummy_destructor(T) { return dnnl_success; }
130
+ std::shared_ptr<typename std::remove_pointer<T>::type> data_ {0};
131
+
132
+ protected:
133
+ bool operator==(const T other) const { return other == data_.get(); }
134
+ bool operator!=(const T other) const { return !(*this == other); }
135
+
136
+ public:
137
+ /// Constructs an empty handle object.
138
+ ///
139
+ /// @warning
140
+ /// Uninitialized object cannot be used in most library calls and is
141
+ /// equivalent to a null pointer. Any attempt to use its methods, or
142
+ /// passing it to the other library function, will cause an exception
143
+ /// to be thrown.
144
+ handle() = default;
145
+
146
+ /// Copy constructor.
147
+ handle(const handle<T, traits> &) = default;
148
+ /// Assignment operator.
149
+ handle<T, traits> &operator=(const handle<T, traits> &) = default;
150
+ /// Move constructor.
151
+ handle(handle<T, traits> &&) = default;
152
+ /// Move assignment operator.
153
+ handle<T, traits> &operator=(handle<T, traits> &&) = default;
154
+
155
+ /// Constructs a handle wrapper object from a C API handle.
156
+ ///
157
+ /// @param t The C API handle to wrap.
158
+ /// @param weak A flag specifying whether to construct a weak wrapper;
159
+ /// defaults to @c false.
160
+ explicit handle(T t, bool weak = false) { reset(t, weak); }
161
+
162
+ /// Resets the handle wrapper objects to wrap a new C API handle.
163
+ ///
164
+ /// @param t The new value of the C API handle.
165
+ /// @param weak A flag specifying whether the wrapper should be weak;
166
+ /// defaults to @c false.
167
+ void reset(T t, bool weak = false) {
168
+ data_.reset(t, weak ? &dummy_destructor : traits::destructor);
169
+ }
170
+
171
+ /// Returns the underlying C API handle.
172
+ ///
173
+ /// @param allow_empty A flag signifying whether the method is allowed to
174
+ /// return an empty (null) object without throwing an exception.
175
+ /// @returns The underlying C API handle.
176
+ T get(bool allow_empty = false) const {
177
+ T result = data_.get();
178
+ if (allow_empty == false && result == nullptr)
179
+ DNNL_THROW_ERROR(
180
+ dnnl_invalid_arguments, "object is not initialized");
181
+ return result;
182
+ }
183
+
184
+ /// Converts a handle to the underlying C API handle type. Does not throw
185
+ /// and returns `nullptr` if the object is empty.
186
+ ///
187
+ /// @returns The underlying C API handle.
188
+ explicit operator T() const { return get(true); }
189
+
190
+ /// Checks whether the object is not empty.
191
+ ///
192
+ /// @returns Whether the object is not empty.
193
+ explicit operator bool() const { return get(true) != nullptr; }
194
+
195
+ /// Equality operator.
196
+ ///
197
+ /// @param other Another handle wrapper.
198
+ /// @returns @c true if this and the other handle wrapper manage the same
199
+ /// underlying C API handle, and @c false otherwise. Empty handle
200
+ /// objects are considered to be equal.
201
+ bool operator==(const handle<T, traits> &other) const {
202
+ return other.data_.get() == data_.get();
203
+ }
204
+
205
+ /// Inequality operator.
206
+ ///
207
+ /// @param other Another handle wrapper.
208
+ /// @returns @c true if this and the other handle wrapper manage different
209
+ /// underlying C API handles, and @c false otherwise. Empty handle
210
+ /// objects are considered to be equal.
211
+ bool operator!=(const handle &other) const { return !(*this == other); }
212
+ };
213
+
214
+ /// @} dnnl_api_utils
215
+
216
+ /// @addtogroup dnnl_api_engine Engine
217
+ ///
218
+ /// An abstraction of a computational device: a CPU, a specific GPU
219
+ /// card in the system, etc. Most primitives are created to execute
220
+ /// computations on one specific engine. The only exceptions are reorder
221
+ /// primitives that transfer data between two different engines.
222
+ ///
223
+ /// @sa @ref dev_guide_basic_concepts
224
+ ///
225
+ /// @{
226
+
227
+ /// @cond DO_NOT_DOCUMENT_THIS
228
+ template <>
229
+ struct handle_traits<dnnl_engine_t> {
230
+ static dnnl_status_t destructor(dnnl_engine_t p) {
231
+ return dnnl_engine_destroy(p);
232
+ }
233
+ };
234
+ /// @endcond
235
+
236
+ /// An execution engine.
237
+ struct engine : public handle<dnnl_engine_t> {
238
+ friend struct primitive;
239
+ friend struct reorder;
240
+
241
+ /// Kinds of engines.
242
+ enum class kind {
243
+ /// An unspecified engine
244
+ any = dnnl_any_engine,
245
+ /// CPU engine
246
+ cpu = dnnl_cpu,
247
+ /// GPU engine
248
+ gpu = dnnl_gpu,
249
+ };
250
+
251
+ using handle::handle;
252
+
253
+ /// Constructs an empty engine. An empty engine cannot be used in any
254
+ /// operations.
255
+ engine() = default;
256
+
257
+ /// Returns the number of engines of a certain kind.
258
+ ///
259
+ /// @param akind The kind of engines to count.
260
+ /// @returns The number of engines of the specified kind.
261
+ static size_t get_count(kind akind) {
262
+ return dnnl_engine_get_count(convert_to_c(akind));
263
+ }
264
+
265
+ /// Constructs an engine.
266
+ ///
267
+ /// @param akind The kind of engine to construct.
268
+ /// @param index The index of the engine. Must be less than the value
269
+ /// returned by #get_count() for this particular kind of engine.
270
+ engine(kind akind, size_t index) {
271
+ dnnl_engine_t engine;
272
+ error::wrap_c_api(
273
+ dnnl_engine_create(&engine, convert_to_c(akind), index),
274
+ "could not create an engine");
275
+ reset(engine);
276
+ }
277
+
278
+ /// Returns the kind of the engine.
279
+ /// @returns The kind of the engine.
280
+ kind get_kind() const {
281
+ dnnl_engine_kind_t kind;
282
+ error::wrap_c_api(dnnl_engine_get_kind(get(), &kind),
283
+ "could not get kind of an engine");
284
+ return static_cast<engine::kind>(kind);
285
+ }
286
+
287
+ private:
288
+ static dnnl_engine_kind_t convert_to_c(kind akind) {
289
+ return static_cast<dnnl_engine_kind_t>(akind);
290
+ }
291
+ };
292
+
293
+ /// Converts engine kind enum value from C++ API to C API type.
294
+ ///
295
+ /// @param akind C++ API engine kind enum value.
296
+ /// @returns Corresponding C API engine kind enum value.
297
+ inline dnnl_engine_kind_t convert_to_c(engine::kind akind) {
298
+ return static_cast<dnnl_engine_kind_t>(akind);
299
+ }
300
+
301
+ /// @} dnnl_api_engine
302
+
303
+ /// @addtogroup dnnl_api_stream Stream
304
+ ///
305
+ /// An encapsulation of execution context tied to a particular engine.
306
+ ///
307
+ /// @sa @ref dev_guide_basic_concepts
308
+ ///
309
+ /// @{
310
+
311
+ /// @cond DO_NOT_DOCUMENT_THIS
312
+ template <>
313
+ struct handle_traits<dnnl_stream_t> {
314
+ static dnnl_status_t destructor(dnnl_stream_t p) {
315
+ return dnnl_stream_destroy(p);
316
+ }
317
+ };
318
+ /// @endcond
319
+
320
+ /// An execution stream.
321
+ struct stream : public handle<dnnl_stream_t> {
322
+ using handle::handle;
323
+
324
+ /// Stream flags. Can be combined using the bitwise OR operator.
325
+ enum class flags : unsigned {
326
+ /// In-order execution.
327
+ in_order = dnnl_stream_in_order,
328
+ /// Out-of-order execution.
329
+ out_of_order = dnnl_stream_out_of_order,
330
+ /// Default stream configuration.
331
+ default_flags = dnnl_stream_default_flags,
332
+ #ifdef DNNL_EXPERIMENTAL_PROFILING
333
+ /// Enables profiling capabilities.
334
+ profiling = dnnl_stream_profiling,
335
+ #endif
336
+ };
337
+
338
+ /// Constructs an empty stream. An empty stream cannot be used in any
339
+ /// operations.
340
+ stream() = default;
341
+
342
+ /// Constructs a stream for the specified engine and with behavior
343
+ /// controlled by the specified flags.
344
+ ///
345
+ /// @param aengine Engine to create the stream on.
346
+ /// @param aflags Flags controlling stream behavior.
347
+ explicit stream(
348
+ const engine &aengine, flags aflags = flags::default_flags) {
349
+ dnnl_stream_t stream;
350
+ error::wrap_c_api(dnnl_stream_create(&stream, aengine.get(),
351
+ static_cast<dnnl_stream_flags_t>(aflags)),
352
+ "could not create a stream");
353
+ reset(stream);
354
+ }
355
+
356
+ /// Returns the associated engine.
357
+ engine get_engine() const {
358
+ dnnl_engine_t c_engine;
359
+ error::wrap_c_api(dnnl_stream_get_engine(get(), &c_engine),
360
+ "could not get an engine from a stream object");
361
+ return engine(c_engine, true);
362
+ }
363
+
364
+ /// Waits for all primitives executing in the stream to finish.
365
+ /// @returns The stream itself.
366
+ stream &wait() {
367
+ error::wrap_c_api(
368
+ dnnl_stream_wait(get()), "could not wait on a stream");
369
+ return *this;
370
+ }
371
+ };
372
+
373
+ #define DNNL_DEFINE_BITMASK_OPS(enum_name) \
374
+ inline enum_name operator|(enum_name lhs, enum_name rhs) { \
375
+ return static_cast<enum_name>( \
376
+ static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); \
377
+ } \
378
+ \
379
+ inline enum_name operator&(enum_name lhs, enum_name rhs) { \
380
+ return static_cast<enum_name>( \
381
+ static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); \
382
+ } \
383
+ \
384
+ inline enum_name operator^(enum_name lhs, enum_name rhs) { \
385
+ return static_cast<enum_name>( \
386
+ static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); \
387
+ } \
388
+ \
389
+ inline enum_name &operator|=(enum_name &lhs, enum_name rhs) { \
390
+ lhs = static_cast<enum_name>( \
391
+ static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); \
392
+ return lhs; \
393
+ } \
394
+ \
395
+ inline enum_name &operator&=(enum_name &lhs, enum_name rhs) { \
396
+ lhs = static_cast<enum_name>( \
397
+ static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); \
398
+ return lhs; \
399
+ } \
400
+ \
401
+ inline enum_name &operator^=(enum_name &lhs, enum_name rhs) { \
402
+ lhs = static_cast<enum_name>( \
403
+ static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); \
404
+ return lhs; \
405
+ } \
406
+ \
407
+ inline enum_name operator~(enum_name rhs) { \
408
+ return static_cast<enum_name>(~static_cast<unsigned>(rhs)); \
409
+ }
410
+
411
+ DNNL_DEFINE_BITMASK_OPS(stream::flags)
412
+
413
+ /// @} dnnl_api_stream
414
+
415
+ /// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
416
+ /// @{
417
+
418
+ /// Floating-point math mode
419
+ enum class fpmath_mode {
420
+ /// Default behavior, no downconversions allowed
421
+ strict = dnnl_fpmath_mode_strict,
422
+ /// Implicit f32->bf16 conversions allowed
423
+ bf16 = dnnl_fpmath_mode_bf16,
424
+ /// Implicit f32->f16 conversions allowed
425
+ f16 = dnnl_fpmath_mode_f16,
426
+ /// Implicit f32->tf32 conversions allowed
427
+ tf32 = dnnl_fpmath_mode_tf32,
428
+ /// Implicit f32->f16, f32->tf32 or f32->bf16 conversions allowed
429
+ any = dnnl_fpmath_mode_any
430
+ };
431
+
432
+ /// Converts an fpmath mode enum value from C++ API to C API type.
433
+ ///
434
+ /// @param mode C++ API fpmath mode enum value.
435
+ /// @returns Corresponding C API fpmath mode enum value.
436
+ inline dnnl_fpmath_mode_t convert_to_c(fpmath_mode mode) {
437
+ return static_cast<dnnl_fpmath_mode_t>(mode);
438
+ }
439
+
440
+ /// @} dnnl_api_fpmath_mode
441
+
442
+ /// @addtogroup dnnl_api_accumulation_mode Accumulation Mode
443
+ /// @{
444
+
445
+ /// Accumulation mode
446
+ enum class accumulation_mode {
447
+ /// Default behavior, f32 for floating point computation, s32 for integer
448
+ strict = dnnl_accumulation_mode_strict,
449
+ /// same as strict except some partial accumulators can be rounded to
450
+ /// src/dst datatype in memory.
451
+ relaxed = dnnl_accumulation_mode_relaxed,
452
+ /// uses fastest implementation, could use src/dst datatype or
453
+ /// wider datatype for accumulators
454
+ any = dnnl_accumulation_mode_any,
455
+ /// use s32 accumulators during computation
456
+ s32 = dnnl_accumulation_mode_s32,
457
+ /// use f32 accumulators during computation
458
+ f32 = dnnl_accumulation_mode_f32,
459
+ /// use f16 accumulators during computation
460
+ f16 = dnnl_accumulation_mode_f16
461
+ };
462
+
463
+ /// Converts an accumulation mode enum value from C++ API to C API type.
464
+ ///
465
+ /// @param mode C++ API accumulation mode enum value.
466
+ /// @returns Corresponding C API accumulation mode enum value.
467
+ inline dnnl_accumulation_mode_t convert_to_c(accumulation_mode mode) {
468
+ return static_cast<dnnl_accumulation_mode_t>(mode);
469
+ }
470
+
471
+ /// @} dnnl_api_accumulation_mode
472
+
473
+ /// @} dnnl_api_common
474
+
475
+ } // namespace dnnl
476
+
477
+ /// @} dnnl_api
478
+
479
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_common_types.h ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2022-2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ /// @file
18
+ /// C API common types definitions
19
+
20
+ #ifndef ONEAPI_DNNL_DNNL_COMMON_TYPES_H
21
+ #define ONEAPI_DNNL_DNNL_COMMON_TYPES_H
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ /// @cond DO_NOT_DOCUMENT_THIS
28
+ #include <stddef.h>
29
+ #include <stdint.h>
30
+
31
+ #include "oneapi/dnnl/dnnl_config.h"
32
+
33
+ /// @endcond
34
+
35
+ /// @addtogroup dnnl_api oneDNN API
36
+ /// @{
37
+
38
+ /// @addtogroup dnnl_api_common Common API
39
+ /// @{
40
+
41
+ /// @addtogroup dnnl_api_utils
42
+ /// @{
43
+
44
+ /// Status values returned by the library functions.
45
+ typedef enum {
46
+ /// The operation was successful
47
+ dnnl_success = 0,
48
+ /// The operation failed due to an out-of-memory condition
49
+ dnnl_out_of_memory = 1,
50
+ /// The operation failed because of incorrect function arguments
51
+ dnnl_invalid_arguments = 2,
52
+ /// The operation failed because requested functionality is not implemented
53
+ dnnl_unimplemented = 3,
54
+ /// The last available implementation is reached
55
+ dnnl_last_impl_reached = 4,
56
+ /// Primitive or engine failed on execution
57
+ dnnl_runtime_error = 5,
58
+ /// Queried element is not required for given primitive
59
+ dnnl_not_required = 6,
60
+ /// The graph is not legitimate
61
+ dnnl_invalid_graph = 7,
62
+ /// The operation is not legitimate according to op schema
63
+ dnnl_invalid_graph_op = 8,
64
+ /// The shape cannot be inferred or compiled
65
+ dnnl_invalid_shape = 9,
66
+ /// The data type cannot be inferred or compiled
67
+ dnnl_invalid_data_type = 10,
68
+ } dnnl_status_t;
69
+
70
+ /// @} dnnl_api_utils
71
+
72
+ /// @addtogroup dnnl_api_data_types Data types
73
+ /// @{
74
+
75
+ /// Data type specification
76
+ typedef enum {
77
+ /// Undefined data type, used for empty memory descriptors.
78
+ dnnl_data_type_undef = 0,
79
+ /// 16-bit/half-precision floating point.
80
+ dnnl_f16 = 1,
81
+ /// non-standard 16-bit (bfloat16 w/ 7 bit mantissa) floating point.
82
+ dnnl_bf16 = 2,
83
+ /// 32-bit/single-precision floating point.
84
+ dnnl_f32 = 3,
85
+ /// 32-bit signed integer.
86
+ dnnl_s32 = 4,
87
+ /// 8-bit signed integer.
88
+ dnnl_s8 = 5,
89
+ /// 8-bit unsigned integer.
90
+ dnnl_u8 = 6,
91
+ /// 64-bit/double-precision floating point.
92
+ dnnl_f64 = 7,
93
+ /// Boolean data type. Size is C++ implementation defined.
94
+ dnnl_boolean = 8,
95
+ /// [OFP8 standard 8-bit floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
96
+ /// with a 5-bit exponent and a 2-bit mantissa.
97
+ dnnl_f8_e5m2 = 9,
98
+ /// [OFP8 standard 8-bit floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
99
+ /// with a 4-bit exponent and a 3-bit mantissa.
100
+ dnnl_f8_e4m3 = 10,
101
+ /// 4-bit signed integer.
102
+ dnnl_s4 = 11,
103
+ /// 4-bit unsigned integer.
104
+ dnnl_u4 = 12,
105
+
106
+ /// Parameter to allow internal only data_types without undefined behavior.
107
+ /// This parameter is chosen to be valid for so long as sizeof(int) >= 2.
108
+ dnnl_data_type_max = 0x7fff,
109
+ } dnnl_data_type_t;
110
+
111
+ /// Maximum number of dimensions a tensor can have. Only restricts the amount
112
+ /// of space used for the tensor description. Individual computational
113
+ /// primitives may support only tensors of certain dimensions.
114
+ #define DNNL_MAX_NDIMS 12
115
+
116
+ /// A type to describe tensor dimension.
117
+ typedef int64_t dnnl_dim_t;
118
+
119
+ /// A type to describe tensor dimensions.
120
+ typedef dnnl_dim_t dnnl_dims_t[DNNL_MAX_NDIMS];
121
+
122
+ /// @} dnnl_api_data_types
123
+
124
+ /// @addtogroup dnnl_api_fpmath_mode Floating-point Math Mode
125
+ /// @{
126
+
127
+ /// Floating-point math mode
128
+ typedef enum {
129
+ /// Default behavior, no downconversions allowed
130
+ dnnl_fpmath_mode_strict,
131
+ /// Implicit f32->bf16 conversions allowed
132
+ dnnl_fpmath_mode_bf16,
133
+ /// Implicit f32->f16 conversions allowed
134
+ dnnl_fpmath_mode_f16,
135
+ /// Implicit f32->f16, f32->tf32 or f32->bf16 conversions allowed
136
+ dnnl_fpmath_mode_any,
137
+ /// Implicit f32->tf32 conversions allowed
138
+ dnnl_fpmath_mode_tf32,
139
+ } dnnl_fpmath_mode_t;
140
+
141
+ /// @} dnnl_api_fpmath_mode
142
+
143
+ /// @addtogroup dnnl_api_accumulation_mode Accumulation Mode
144
+ /// @{
145
+
146
+ /// Accumulation mode
147
+ typedef enum {
148
+ /// Default behavior, f32/f64 for floating point computation, s32
149
+ /// for integer
150
+ dnnl_accumulation_mode_strict,
151
+ /// Same as strict but allows some partial accumulators to be
152
+ /// rounded to src/dst datatype in memory.
153
+ dnnl_accumulation_mode_relaxed,
154
+ /// uses fastest implementation, could use src/dst datatype or
155
+ /// wider datatype for accumulators
156
+ dnnl_accumulation_mode_any,
157
+ /// use s32 accumulators during computation
158
+ dnnl_accumulation_mode_s32,
159
+ /// use f32 accumulators during computation
160
+ dnnl_accumulation_mode_f32,
161
+ /// use f16 accumulators during computation
162
+ dnnl_accumulation_mode_f16
163
+ } dnnl_accumulation_mode_t;
164
+
165
+ /// @} dnnl_api_accumulation_mode
166
+
167
+ /// @addtogroup dnnl_api_engine Engine
168
+ /// @{
169
+
170
+ /// @brief Kinds of engines.
171
+ typedef enum {
172
+ /// An unspecified engine.
173
+ dnnl_any_engine,
174
+ /// CPU engine.
175
+ dnnl_cpu,
176
+ /// GPU engine.
177
+ dnnl_gpu,
178
+ } dnnl_engine_kind_t;
179
+
180
+ /// @struct dnnl_engine
181
+ /// @brief An opaque structure to describe an engine.
182
+ struct dnnl_engine;
183
+ /// @brief An engine handle.
184
+ typedef struct dnnl_engine *dnnl_engine_t;
185
+ #if 0
186
+ // FIXME: looks like this never happens
187
+ /// @brief A constant engine handle.
188
+ typedef const struct dnnl_engine *const_dnnl_engine_t;
189
+ #endif
190
+
191
+ /// @} dnnl_api_engine
192
+
193
+ /// @addtogroup dnnl_api_stream Stream
194
+ /// @{
195
+
196
+ /// @brief Stream flags.
197
+ typedef enum {
198
+ // In-order execution.
199
+ dnnl_stream_in_order = 0x1U,
200
+ /// Out-of-order execution.
201
+ dnnl_stream_out_of_order = 0x2U,
202
+ /// Default stream configuration.
203
+ dnnl_stream_default_flags = dnnl_stream_in_order,
204
+ #ifdef DNNL_EXPERIMENTAL_PROFILING
205
+ /// Enables profiling capabilities.
206
+ dnnl_stream_profiling = 0x4U,
207
+ #endif
208
+ } dnnl_stream_flags_t;
209
+
210
+ /// @struct dnnl_stream
211
+ /// An opaque structure to describe an execution stream.
212
+ struct dnnl_stream;
213
+ /// An execution stream handle.
214
+ typedef struct dnnl_stream *dnnl_stream_t;
215
+ /// A constant execution stream handle.
216
+ typedef const struct dnnl_stream *const_dnnl_stream_t;
217
+
218
+ /// @} dnnl_api_stream
219
+
220
+ /// @addtogroup dnnl_api_service
221
+ /// @{
222
+
223
+ /// Structure containing version information as per [Semantic
224
+ /// Versioning](https://semver.org)
225
+ typedef struct {
226
+ int major; ///< Major version
227
+ int minor; ///< Minor version
228
+ int patch; ///< Patch version
229
+ const char *hash; ///< Git hash of the sources (may be absent)
230
+ unsigned cpu_runtime; ///< CPU runtime
231
+ unsigned gpu_runtime; ///< GPU runtime
232
+ } dnnl_version_t;
233
+
234
+ /// @} dnnl_api_service
235
+
236
+ /// @addtogroup dnnl_api_memory
237
+ /// @{
238
+
239
+ /// Special pointer value that indicates that a memory object should not have
240
+ /// an underlying buffer.
241
+ #define DNNL_MEMORY_NONE (NULL)
242
+
243
+ /// Special pointer value that indicates that the library needs to allocate an
244
+ /// underlying buffer for a memory object.
245
+ #define DNNL_MEMORY_ALLOCATE ((void *)(size_t)-1)
246
+
247
+ /// @} dnnl_api_memory
248
+
249
+ /// @} dnnl_api_common
250
+
251
+ /// @} dnnl_api
252
+
253
+ #ifdef __cplusplus
254
+ }
255
+ #endif
256
+
257
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_config.h ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2019-2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_CONFIG_H
18
+ #define ONEAPI_DNNL_DNNL_CONFIG_H
19
+
20
+ /// @cond DO_NOT_DOCUMENT_THIS
21
+
22
+ // All symbols shall be internal unless marked as DNNL_API
23
+ #if defined _WIN32 || defined __CYGWIN__
24
+ #define DNNL_HELPER_DLL_IMPORT __declspec(dllimport)
25
+ #define DNNL_HELPER_DLL_EXPORT __declspec(dllexport)
26
+ #else
27
+ #if __GNUC__ >= 4
28
+ #define DNNL_HELPER_DLL_IMPORT __attribute__((visibility("default")))
29
+ #define DNNL_HELPER_DLL_EXPORT __attribute__((visibility("default")))
30
+ #else
31
+ #define DNNL_HELPER_DLL_IMPORT
32
+ #define DNNL_HELPER_DLL_EXPORT
33
+ #endif
34
+ #endif
35
+
36
+ #ifdef DNNL_DLL
37
+ #ifdef DNNL_DLL_EXPORTS
38
+ #define DNNL_API DNNL_HELPER_DLL_EXPORT
39
+ #else
40
+ #define DNNL_API DNNL_HELPER_DLL_IMPORT
41
+ #endif
42
+ #else
43
+ #define DNNL_API
44
+ #endif
45
+
46
+ #if defined(__GNUC__)
47
+ #define DNNL_DEPRECATED __attribute__((deprecated))
48
+ #elif defined(_MSC_VER)
49
+ #define DNNL_DEPRECATED __declspec(deprecated)
50
+ #else
51
+ #define DNNL_DEPRECATED
52
+ #endif
53
+
54
+ /// @endcond
55
+
56
+ // clang-format off
57
+
58
+ /// @addtogroup dnnl_api_service
59
+ /// @{
60
+
61
+ /// No runtime (disabled)
62
+ #define DNNL_RUNTIME_NONE 0u
63
+
64
+ /// Sequential runtime (CPU only)
65
+ #define DNNL_RUNTIME_SEQ 1u
66
+
67
+ /// OpenMP runtime (CPU only)
68
+ #define DNNL_RUNTIME_OMP 2u
69
+
70
+ /// TBB runtime (CPU only)
71
+ #define DNNL_RUNTIME_TBB 4u
72
+
73
+ /// Threadpool runtime (CPU only)
74
+ #define DNNL_RUNTIME_THREADPOOL 8u
75
+
76
+ /// OpenCL runtime
77
+ #define DNNL_RUNTIME_OCL 256u
78
+
79
+ /// SYCL runtime
80
+ #define DNNL_RUNTIME_SYCL 512u
81
+
82
+ /// DPC++ runtime
83
+ #define DNNL_RUNTIME_DPCPP DNNL_RUNTIME_SYCL
84
+
85
+ /// @} dnnl_api_service
86
+
87
+ // oneDNN CPU threading runtime
88
+ #define DNNL_CPU_THREADING_RUNTIME DNNL_RUNTIME_THREADPOOL
89
+
90
+ // oneDNN CPU engine runtime
91
+ #define DNNL_CPU_RUNTIME DNNL_RUNTIME_THREADPOOL
92
+
93
+ // oneDNN GPU engine runtime
94
+ #define DNNL_GPU_RUNTIME DNNL_RUNTIME_NONE
95
+
96
+ // clang-format on
97
+
98
+ #if defined(DNNL_CPU_RUNTIME) && defined(DNNL_GPU_RUNTIME)
99
+ #if (DNNL_CPU_RUNTIME == DNNL_RUNTIME_OCL)
100
+ #error "Unexpected DNNL_CPU_RUNTIME"
101
+ #endif
102
+ #if (DNNL_GPU_RUNTIME != DNNL_RUNTIME_NONE) \
103
+ && (DNNL_GPU_RUNTIME != DNNL_RUNTIME_OCL) \
104
+ && (DNNL_GPU_RUNTIME != DNNL_RUNTIME_SYCL)
105
+ #error "Unexpected DNNL_GPU_RUNTIME"
106
+ #endif
107
+ #if (DNNL_CPU_RUNTIME == DNNL_RUNTIME_NONE \
108
+ && DNNL_GPU_RUNTIME == DNNL_RUNTIME_NONE)
109
+ #error "At least one runtime must be specified"
110
+ #endif
111
+ #else
112
+ #error "BOTH DNNL_CPU_RUNTIME and DNNL_GPU_RUNTIME must be defined"
113
+ #endif
114
+
115
+ // For SYCL CPU, a primitive may be created and executed in different threads
116
+ // hence the global scratchpad does not work. This enables concurrent execution
117
+ // when CPU runtime is SYCL to avoid the issue.
118
+ #if DNNL_CPU_RUNTIME == DNNL_RUNTIME_SYCL
119
+ #ifndef DNNL_ENABLE_CONCURRENT_EXEC
120
+ #define DNNL_ENABLE_CONCURRENT_EXEC
121
+ #endif
122
+ #endif
123
+
124
+ // When defined, primitive cache stores runtime objects.
125
+ #undef DNNL_USE_RT_OBJECTS_IN_PRIMITIVE_CACHE
126
+
127
+ // When defined, DPCPP is supported.
128
+ #undef DNNL_WITH_SYCL
129
+
130
+ // When defined, Level Zero is supported.
131
+ #undef DNNL_WITH_LEVEL_ZERO
132
+
133
+ // When defined, SYCL CUDA backend is used.
134
+ #undef DNNL_SYCL_CUDA
135
+
136
+ // When defined, SYCL HIP backend is used.
137
+ #undef DNNL_SYCL_HIP
138
+
139
+ // When defined, stack checker is enabled.
140
+ #undef DNNL_ENABLE_STACK_CHECKER
141
+
142
+ // When defined, experimental features are enabled.
143
+ #undef DNNL_EXPERIMENTAL
144
+
145
+ // When defined, experimental functionality for sparse domain is enabled.
146
+ #define DNNL_EXPERIMENTAL_SPARSE
147
+
148
+ // When defined, experimental functionality for ukernels is enabled.
149
+ #undef DNNL_EXPERIMENTAL_UKERNEL
150
+
151
+ // When defined, graph component is enabled.
152
+ #define ONEDNN_BUILD_GRAPH
153
+
154
+ // When defined, experimental profiling capabilities are enabled.
155
+ #undef DNNL_EXPERIMENTAL_PROFILING
156
+
157
+ // List of configurating build controls
158
+ // Workload controls
159
+ #define BUILD_TRAINING 1
160
+ #define BUILD_INFERENCE 0
161
+ // Primitive controls
162
+ #define BUILD_PRIMITIVE_ALL 1
163
+ #define BUILD_BATCH_NORMALIZATION 0
164
+ #define BUILD_BINARY 0
165
+ #define BUILD_CONCAT 0
166
+ #define BUILD_CONVOLUTION 0
167
+ #define BUILD_DECONVOLUTION 0
168
+ #define BUILD_ELTWISE 0
169
+ #define BUILD_GROUP_NORMALIZATION 1
170
+ #define BUILD_INNER_PRODUCT 0
171
+ #define BUILD_LAYER_NORMALIZATION 0
172
+ #define BUILD_LRN 0
173
+ #define BUILD_MATMUL 0
174
+ #define BUILD_POOLING 0
175
+ #define BUILD_PRELU 0
176
+ #define BUILD_REDUCTION 0
177
+ #define BUILD_REORDER 0
178
+ #define BUILD_RESAMPLING 0
179
+ #define BUILD_RNN 0
180
+ #define BUILD_SHUFFLE 0
181
+ #define BUILD_SOFTMAX 0
182
+ #define BUILD_SUM 0
183
+ // Primitives CPU ISA controls
184
+ #define BUILD_PRIMITIVE_CPU_ISA_ALL 1
185
+ #define BUILD_SSE41 0
186
+ #define BUILD_AVX2 0
187
+ #define BUILD_AVX512 0
188
+ #define BUILD_AMX 0
189
+ // Primitives GPU ISA controls
190
+ #define BUILD_PRIMITIVE_GPU_ISA_ALL 0
191
+ #define BUILD_GEN9 0
192
+ #define BUILD_GEN11 0
193
+ #define BUILD_XELP 0
194
+ #define BUILD_XEHP 0
195
+ #define BUILD_XEHPG 0
196
+ #define BUILD_XEHPC 0
197
+ #define BUILD_XE2 0
198
+ // GeMM kernels ISA controls
199
+ #define BUILD_GEMM_KERNELS_ALL 1
200
+ #define BUILD_GEMM_KERNELS_NONE 0
201
+ #define BUILD_GEMM_SSE41 1
202
+ #define BUILD_GEMM_AVX2 1
203
+ #define BUILD_GEMM_AVX512 1
204
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_config.h.in ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2019-2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_CONFIG_H
18
+ #define ONEAPI_DNNL_DNNL_CONFIG_H
19
+
20
+ /// @cond DO_NOT_DOCUMENT_THIS
21
+
22
+ // All symbols shall be internal unless marked as DNNL_API
23
+ #if defined _WIN32 || defined __CYGWIN__
24
+ #define DNNL_HELPER_DLL_IMPORT __declspec(dllimport)
25
+ #define DNNL_HELPER_DLL_EXPORT __declspec(dllexport)
26
+ #else
27
+ #if __GNUC__ >= 4
28
+ #define DNNL_HELPER_DLL_IMPORT __attribute__((visibility("default")))
29
+ #define DNNL_HELPER_DLL_EXPORT __attribute__((visibility("default")))
30
+ #else
31
+ #define DNNL_HELPER_DLL_IMPORT
32
+ #define DNNL_HELPER_DLL_EXPORT
33
+ #endif
34
+ #endif
35
+
36
+ #ifdef DNNL_DLL
37
+ #ifdef DNNL_DLL_EXPORTS
38
+ #define DNNL_API DNNL_HELPER_DLL_EXPORT
39
+ #else
40
+ #define DNNL_API DNNL_HELPER_DLL_IMPORT
41
+ #endif
42
+ #else
43
+ #define DNNL_API
44
+ #endif
45
+
46
+ #if defined(__GNUC__)
47
+ #define DNNL_DEPRECATED __attribute__((deprecated))
48
+ #elif defined(_MSC_VER)
49
+ #define DNNL_DEPRECATED __declspec(deprecated)
50
+ #else
51
+ #define DNNL_DEPRECATED
52
+ #endif
53
+
54
+ /// @endcond
55
+
56
+ // clang-format off
57
+
58
+ /// @addtogroup dnnl_api_service
59
+ /// @{
60
+
61
+ /// No runtime (disabled)
62
+ #define DNNL_RUNTIME_NONE 0u
63
+
64
+ /// Sequential runtime (CPU only)
65
+ #define DNNL_RUNTIME_SEQ 1u
66
+
67
+ /// OpenMP runtime (CPU only)
68
+ #define DNNL_RUNTIME_OMP 2u
69
+
70
+ /// TBB runtime (CPU only)
71
+ #define DNNL_RUNTIME_TBB 4u
72
+
73
+ /// Threadpool runtime (CPU only)
74
+ #define DNNL_RUNTIME_THREADPOOL 8u
75
+
76
+ /// OpenCL runtime
77
+ #define DNNL_RUNTIME_OCL 256u
78
+
79
+ /// SYCL runtime
80
+ #define DNNL_RUNTIME_SYCL 512u
81
+
82
+ /// DPC++ runtime
83
+ #define DNNL_RUNTIME_DPCPP DNNL_RUNTIME_SYCL
84
+
85
+ /// @} dnnl_api_service
86
+
87
+ // oneDNN CPU threading runtime
88
+ #cmakedefine DNNL_CPU_THREADING_RUNTIME DNNL_RUNTIME_${DNNL_CPU_THREADING_RUNTIME}
89
+
90
+ // oneDNN CPU engine runtime
91
+ #cmakedefine DNNL_CPU_RUNTIME DNNL_RUNTIME_${DNNL_CPU_RUNTIME}
92
+
93
+ // oneDNN GPU engine runtime
94
+ #cmakedefine DNNL_GPU_RUNTIME DNNL_RUNTIME_${DNNL_GPU_RUNTIME}
95
+
96
+ // clang-format on
97
+
98
+ #if defined(DNNL_CPU_RUNTIME) && defined(DNNL_GPU_RUNTIME)
99
+ #if (DNNL_CPU_RUNTIME == DNNL_RUNTIME_OCL)
100
+ #error "Unexpected DNNL_CPU_RUNTIME"
101
+ #endif
102
+ #if (DNNL_GPU_RUNTIME != DNNL_RUNTIME_NONE) \
103
+ && (DNNL_GPU_RUNTIME != DNNL_RUNTIME_OCL) \
104
+ && (DNNL_GPU_RUNTIME != DNNL_RUNTIME_SYCL)
105
+ #error "Unexpected DNNL_GPU_RUNTIME"
106
+ #endif
107
+ #if (DNNL_CPU_RUNTIME == DNNL_RUNTIME_NONE \
108
+ && DNNL_GPU_RUNTIME == DNNL_RUNTIME_NONE)
109
+ #error "At least one runtime must be specified"
110
+ #endif
111
+ #else
112
+ #error "BOTH DNNL_CPU_RUNTIME and DNNL_GPU_RUNTIME must be defined"
113
+ #endif
114
+
115
+ // For SYCL CPU, a primitive may be created and executed in different threads
116
+ // hence the global scratchpad does not work. This enables concurrent execution
117
+ // when CPU runtime is SYCL to avoid the issue.
118
+ #if DNNL_CPU_RUNTIME == DNNL_RUNTIME_SYCL
119
+ #ifndef DNNL_ENABLE_CONCURRENT_EXEC
120
+ #define DNNL_ENABLE_CONCURRENT_EXEC
121
+ #endif
122
+ #endif
123
+
124
+ // When defined, primitive cache stores runtime objects.
125
+ #cmakedefine DNNL_USE_RT_OBJECTS_IN_PRIMITIVE_CACHE
126
+
127
+ // When defined, DPCPP is supported.
128
+ #cmakedefine DNNL_WITH_SYCL
129
+
130
+ // When defined, Level Zero is supported.
131
+ #cmakedefine DNNL_WITH_LEVEL_ZERO
132
+
133
+ // When defined, SYCL CUDA backend is used.
134
+ #cmakedefine DNNL_SYCL_CUDA
135
+
136
+ // When defined, SYCL HIP backend is used.
137
+ #cmakedefine DNNL_SYCL_HIP
138
+
139
+ // When defined, stack checker is enabled.
140
+ #cmakedefine DNNL_ENABLE_STACK_CHECKER
141
+
142
+ // When defined, experimental features are enabled.
143
+ #cmakedefine DNNL_EXPERIMENTAL
144
+
145
+ // When defined, experimental functionality for sparse domain is enabled.
146
+ #cmakedefine DNNL_EXPERIMENTAL_SPARSE
147
+
148
+ // When defined, experimental functionality for ukernels is enabled.
149
+ #cmakedefine DNNL_EXPERIMENTAL_UKERNEL
150
+
151
+ // When defined, graph component is enabled.
152
+ #cmakedefine ONEDNN_BUILD_GRAPH
153
+
154
+ // When defined, experimental profiling capabilities are enabled.
155
+ #cmakedefine DNNL_EXPERIMENTAL_PROFILING
156
+
157
+ // List of configurating build controls
158
+ // Workload controls
159
+ #cmakedefine01 BUILD_TRAINING
160
+ #cmakedefine01 BUILD_INFERENCE
161
+ // Primitive controls
162
+ #cmakedefine01 BUILD_PRIMITIVE_ALL
163
+ #cmakedefine01 BUILD_BATCH_NORMALIZATION
164
+ #cmakedefine01 BUILD_BINARY
165
+ #cmakedefine01 BUILD_CONCAT
166
+ #cmakedefine01 BUILD_CONVOLUTION
167
+ #cmakedefine01 BUILD_DECONVOLUTION
168
+ #cmakedefine01 BUILD_ELTWISE
169
+ #cmakedefine01 BUILD_GROUP_NORMALIZATION
170
+ #cmakedefine01 BUILD_INNER_PRODUCT
171
+ #cmakedefine01 BUILD_LAYER_NORMALIZATION
172
+ #cmakedefine01 BUILD_LRN
173
+ #cmakedefine01 BUILD_MATMUL
174
+ #cmakedefine01 BUILD_POOLING
175
+ #cmakedefine01 BUILD_PRELU
176
+ #cmakedefine01 BUILD_REDUCTION
177
+ #cmakedefine01 BUILD_REORDER
178
+ #cmakedefine01 BUILD_RESAMPLING
179
+ #cmakedefine01 BUILD_RNN
180
+ #cmakedefine01 BUILD_SHUFFLE
181
+ #cmakedefine01 BUILD_SOFTMAX
182
+ #cmakedefine01 BUILD_SUM
183
+ // Primitives CPU ISA controls
184
+ #cmakedefine01 BUILD_PRIMITIVE_CPU_ISA_ALL
185
+ #cmakedefine01 BUILD_SSE41
186
+ #cmakedefine01 BUILD_AVX2
187
+ #cmakedefine01 BUILD_AVX512
188
+ #cmakedefine01 BUILD_AMX
189
+ // Primitives GPU ISA controls
190
+ #cmakedefine01 BUILD_PRIMITIVE_GPU_ISA_ALL
191
+ #cmakedefine01 BUILD_GEN9
192
+ #cmakedefine01 BUILD_GEN11
193
+ #cmakedefine01 BUILD_XELP
194
+ #cmakedefine01 BUILD_XEHP
195
+ #cmakedefine01 BUILD_XEHPG
196
+ #cmakedefine01 BUILD_XEHPC
197
+ #cmakedefine01 BUILD_XE2
198
+ // GeMM kernels ISA controls
199
+ #cmakedefine01 BUILD_GEMM_KERNELS_ALL
200
+ #cmakedefine01 BUILD_GEMM_KERNELS_NONE
201
+ #cmakedefine01 BUILD_GEMM_SSE41
202
+ #cmakedefine01 BUILD_GEMM_AVX2
203
+ #cmakedefine01 BUILD_GEMM_AVX512
204
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_debug.h ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2018-2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ // DO NOT EDIT, AUTO-GENERATED
18
+ // Use this script to update the file: scripts/generate_dnnl_debug.py
19
+
20
+ // clang-format off
21
+
22
+ #ifndef ONEAPI_DNNL_DNNL_DEBUG_H
23
+ #define ONEAPI_DNNL_DNNL_DEBUG_H
24
+
25
+ /// @file
26
+ /// Debug capabilities
27
+
28
+ #include "oneapi/dnnl/dnnl_config.h"
29
+ #include "oneapi/dnnl/dnnl_types.h"
30
+
31
+ #ifdef __cplusplus
32
+ extern "C" {
33
+ #endif
34
+
35
+ const char DNNL_API *dnnl_status2str(dnnl_status_t v);
36
+ const char DNNL_API *dnnl_dt2str(dnnl_data_type_t v);
37
+ const char DNNL_API *dnnl_fpmath_mode2str(dnnl_fpmath_mode_t v);
38
+ const char DNNL_API *dnnl_accumulation_mode2str(dnnl_accumulation_mode_t v);
39
+ const char DNNL_API *dnnl_engine_kind2str(dnnl_engine_kind_t v);
40
+ #ifdef DNNL_EXPERIMENTAL_SPARSE
41
+ const char DNNL_API *dnnl_sparse_encoding2str(dnnl_sparse_encoding_t v);
42
+ #endif
43
+ const char DNNL_API *dnnl_fmt_tag2str(dnnl_format_tag_t v);
44
+ const char DNNL_API *dnnl_prop_kind2str(dnnl_prop_kind_t v);
45
+ const char DNNL_API *dnnl_prim_kind2str(dnnl_primitive_kind_t v);
46
+ const char DNNL_API *dnnl_alg_kind2str(dnnl_alg_kind_t v);
47
+ const char DNNL_API *dnnl_rnn_flags2str(dnnl_rnn_flags_t v);
48
+ const char DNNL_API *dnnl_rnn_direction2str(dnnl_rnn_direction_t v);
49
+ const char DNNL_API *dnnl_scratchpad_mode2str(dnnl_scratchpad_mode_t v);
50
+ const char DNNL_API *dnnl_cpu_isa2str(dnnl_cpu_isa_t v);
51
+ const char DNNL_API *dnnl_cpu_isa_hints2str(dnnl_cpu_isa_hints_t v);
52
+
53
+ const char DNNL_API *dnnl_runtime2str(unsigned v);
54
+ const char DNNL_API *dnnl_fmt_kind2str(dnnl_format_kind_t v);
55
+
56
+ #ifdef __cplusplus
57
+ }
58
+ #endif
59
+
60
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph.h ADDED
@@ -0,0 +1,735 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2023 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ /// @file
18
+ /// C API
19
+
20
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_H
21
+ #define ONEAPI_DNNL_DNNL_GRAPH_H
22
+
23
+ #include "oneapi/dnnl/dnnl_common.h"
24
+ #include "oneapi/dnnl/dnnl_config.h"
25
+ #include "oneapi/dnnl/dnnl_graph_types.h"
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ /// @addtogroup dnnl_graph_api
32
+ /// @{
33
+
34
+ /// @addtogroup dnnl_graph_api_allocator
35
+ /// @{
36
+
37
+ /// Creates a host allocator with the given allocation and deallocation
38
+ /// call-back function pointers.
39
+ ///
40
+ /// @param allocator Output allocator.
41
+ /// @param host_malloc A pointer to malloc function for host.
42
+ /// @param host_free A pointer to free function for host.
43
+ /// @returns #dnnl_success on success or a status describing the error
44
+ /// otherwise.
45
+ dnnl_status_t DNNL_API dnnl_graph_allocator_create(
46
+ dnnl_graph_allocator_t *allocator,
47
+ dnnl_graph_host_allocate_f host_malloc,
48
+ dnnl_graph_host_deallocate_f host_free);
49
+
50
+ /// Destroys an allocator.
51
+ ///
52
+ /// @param allocator The allocator to be destroyed.
53
+ /// @returns #dnnl_success on success or a status describing the error
54
+ /// otherwise.
55
+ dnnl_status_t DNNL_API dnnl_graph_allocator_destroy(
56
+ dnnl_graph_allocator_t allocator);
57
+
58
+ /// @} dnnl_graph_api_allocator
59
+
60
+ /// @addtogroup dnnl_graph_api_engine
61
+ /// @{
62
+
63
+ /// This API is a supplement for existing onednn engine API.
64
+ dnnl_status_t DNNL_API dnnl_graph_make_engine_with_allocator(
65
+ dnnl_engine_t *engine, dnnl_engine_kind_t kind, size_t index,
66
+ const_dnnl_graph_allocator_t alloc);
67
+
68
+ /// @} dnnl_graph_api_engine
69
+
70
+ /// @addtogroup dnnl_graph_api_logical_tensor
71
+ /// @{
72
+
73
+ /// Initializes a logical tensor with id, data type, number of dimensions,
74
+ /// layout type, and property. The logical tensor's dims are unknown with this
75
+ /// interface.
76
+ ///
77
+ /// @param logical_tensor Output logical tensor.
78
+ /// @param tid The unique id of the output logical tensor.
79
+ /// @param dtype Elements data type.
80
+ /// @param ndims Number of dimensions.
81
+ /// @param ltype Layout type of the underlying tensor buffer.
82
+ /// @param ptype Tensor property type.
83
+ /// @returns #dnnl_success on success or a status describing the error
84
+ /// otherwise.
85
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init(
86
+ dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
87
+ dnnl_data_type_t dtype, int32_t ndims, dnnl_graph_layout_type_t ltype,
88
+ dnnl_graph_tensor_property_t ptype);
89
+
90
+ /// Initializes a logical tensor with basic information and dims. The logical
91
+ /// tensor's dimensions and layout will be initialized according to the input
92
+ /// arguments.
93
+ ///
94
+ /// @note
95
+ /// If dims contains all valid values and layout type is
96
+ /// #dnnl_graph_layout_type_strided. The strides field in
97
+ /// #dnnl_graph_logical_tensor_t will be calculated in a row major and
98
+ /// contiguous way. Otherwise, Accessing the strides field is an undefined
99
+ /// behavior.
100
+ ///
101
+ /// Eg. dims (2, 3, 4, 5) will get strides (60, 20, 5, 1)
102
+ ///
103
+ /// @param logical_tensor Output logical tensor.
104
+ /// @param tid The unique id of output logical tensor.
105
+ /// @param dtype Elements data type.
106
+ /// @param ndims Number of dimensions.
107
+ /// @param dims Array of dimensions.
108
+ /// @param ltype Layout type of the underlying tensor memory.
109
+ /// @param ptype Tensor property type.
110
+ /// @returns #dnnl_success on success or a status describing the error
111
+ /// otherwise.
112
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init_with_dims(
113
+ dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
114
+ dnnl_data_type_t dtype, int32_t ndims, const dnnl_dims_t dims,
115
+ dnnl_graph_layout_type_t ltype, dnnl_graph_tensor_property_t ptype);
116
+
117
+ /// Initializes a logical tensor with dimensions and strides provided by user.
118
+ ///
119
+ /// @note
120
+ /// Once strides are explicitly provided through the API, the `layout_type`
121
+ /// in #dnnl_graph_logical_tensor_t can only be
122
+ /// #dnnl_graph_layout_type_strided or #dnnl_graph_layout_type_any.
123
+ ///
124
+ /// @param logical_tensor Output logical tensor.
125
+ /// @param tid The unique id of output logical tensor.
126
+ /// @param dtype Elements data type.
127
+ /// @param ndims Number of dimensions.
128
+ /// @param dims Array of dimensions.
129
+ /// @param strides Array of strides.
130
+ /// @param ptype Tensor property type.
131
+ /// @returns #dnnl_success on success or a status describing the error
132
+ /// otherwise.
133
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_init_with_strides(
134
+ dnnl_graph_logical_tensor_t *logical_tensor, size_t tid,
135
+ dnnl_data_type_t dtype, int32_t ndims, const dnnl_dims_t dims,
136
+ const dnnl_dims_t strides, dnnl_graph_tensor_property_t ptype);
137
+
138
+ /// Returns the memory size described by the logical tensor. If it's a strided
139
+ /// layout, the size will be calculated by `dims` and `strides`. If it's an
140
+ /// opaque layout, the size will be decided by `layout_id`.
141
+ ///
142
+ /// @param logical_tensor Logical tensor.
143
+ /// @param size Output memory size in bytes.
144
+ /// @returns #dnnl_success on success or a status describing the error
145
+ /// otherwise.
146
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_get_mem_size(
147
+ const dnnl_graph_logical_tensor_t *logical_tensor, size_t *size);
148
+
149
+ /// Compares if two logical tenors are equal. Users can decide accordingly
150
+ /// if layout reordering is needed for two logical tensors. The method will
151
+ /// return true for below two circumstances:
152
+ ///
153
+ /// 1. the two logical tensors are equal regarding each field in the struct,
154
+ /// eg. id, ndims, dims, layout type, property, etc.
155
+ /// 2. If all other fields are equal but the layout types in two logical
156
+ /// tensors are different, the method will return true when the underlying
157
+ /// memory layout is the same. For example, one logical tensor has strided
158
+ /// layout type while the other one has opaque layout type, but underneath,
159
+ /// both layouts are NHWC, the method will still return true for this case.
160
+ ///
161
+ /// @param lt1 The handle of first logical tensor.
162
+ /// @param lt2 The handle of second logical tensor.
163
+ /// @param is_equal 1 if these two logical tensors are equal, 0 otherwise.
164
+ /// @returns #dnnl_success on success or a status describing the error
165
+ /// otherwise.
166
+ dnnl_status_t DNNL_API dnnl_graph_logical_tensor_is_equal(
167
+ const dnnl_graph_logical_tensor_t *lt1,
168
+ const dnnl_graph_logical_tensor_t *lt2, uint8_t *is_equal);
169
+
170
+ /// @} dnnl_graph_api_logical_tensor
171
+
172
+ /// @addtogroup dnnl_graph_api_tensor
173
+ /// @{
174
+
175
+ /// Creates a tensor with logical tensor, engine, and data handle.
176
+ ///
177
+ /// @param tensor Output tensor.
178
+ /// @param logical_tensor Description for this tensor.
179
+ /// @param engine Engine to use.
180
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
181
+ /// - A pointer to the user-allocated buffer. In this case the library
182
+ /// doesn't own the buffer.
183
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
184
+ /// allocate the buffer for the tensor. In this case the library
185
+ /// owns the buffer.
186
+ /// - DNNL_MEMORY_NONE to create tensor without an underlying buffer.
187
+ /// @returns #dnnl_success on success or a status describing the error
188
+ /// otherwise.
189
+ dnnl_status_t DNNL_API dnnl_graph_tensor_create(dnnl_graph_tensor_t *tensor,
190
+ const dnnl_graph_logical_tensor_t *logical_tensor, dnnl_engine_t engine,
191
+ void *handle);
192
+
193
+ /// Destroys a tensor.
194
+ ///
195
+ /// @param tensor The tensor to be destroyed.
196
+ /// @returns #dnnl_success on success or a status describing the error
197
+ /// otherwise.
198
+ dnnl_status_t DNNL_API dnnl_graph_tensor_destroy(dnnl_graph_tensor_t tensor);
199
+
200
+ /// Gets the data handle of a tensor.
201
+ ///
202
+ /// @param tensor The input tensor.
203
+ /// @param handle Pointer to the data of input tensor.
204
+ /// @returns #dnnl_success on success or a status describing the error
205
+ /// otherwise.
206
+ dnnl_status_t DNNL_API dnnl_graph_tensor_get_data_handle(
207
+ const_dnnl_graph_tensor_t tensor, void **handle);
208
+
209
+ /// Set data handle for a tensor.
210
+ ///
211
+ /// @param tensor The input tensor.
212
+ /// @param handle New data handle for tensor.
213
+ /// @returns #dnnl_success on success or a status describing the error
214
+ /// otherwise.
215
+ dnnl_status_t DNNL_API dnnl_graph_tensor_set_data_handle(
216
+ dnnl_graph_tensor_t tensor, void *handle);
217
+
218
+ /// Returns the engine of a tensor object.
219
+ ///
220
+ /// @param tensor The input tensor.
221
+ /// @param engine Output engine on which the tensor is located.
222
+ /// @returns #dnnl_success on success or a status describing the error
223
+ /// otherwise.
224
+ dnnl_status_t DNNL_API dnnl_graph_tensor_get_engine(
225
+ const_dnnl_graph_tensor_t tensor, dnnl_engine_t *engine);
226
+
227
+ /// @} dnnl_graph_api_tensor
228
+
229
+ /// @addtogroup dnnl_graph_api_op
230
+ /// @{
231
+
232
+ /// Initializes an op with unique id, kind, and name.
233
+ ///
234
+ /// @param op Output op
235
+ /// @param id The unique id of the output op.
236
+ /// @param kind The op kind.
237
+ /// @param verbose_name The string added as the op name.
238
+ /// @returns #dnnl_success on success or a status describing the error
239
+ /// otherwise.
240
+ dnnl_status_t DNNL_API dnnl_graph_op_create(dnnl_graph_op_t *op, size_t id,
241
+ dnnl_graph_op_kind_t kind, const char *verbose_name);
242
+
243
+ /// Destroys an op.
244
+ ///
245
+ /// @param op The op to be destroyed.
246
+ /// @returns #dnnl_success on success or a status describing the error
247
+ /// otherwise.
248
+ dnnl_status_t DNNL_API dnnl_graph_op_destroy(dnnl_graph_op_t op);
249
+
250
+ /// Adds input logical tensor to the op.
251
+ ///
252
+ /// @param op Input op.
253
+ /// @param input The input logical tensor to be added.
254
+ /// @returns #dnnl_success on success or a status describing the error
255
+ /// otherwise.
256
+ dnnl_status_t DNNL_API dnnl_graph_op_add_input(
257
+ dnnl_graph_op_t op, const dnnl_graph_logical_tensor_t *input);
258
+
259
+ /// Adds output logical tensor to the op.
260
+ ///
261
+ /// @param op Input op.
262
+ /// @param output The output logical tensor to be added.
263
+ /// @returns #dnnl_success on success or a status describing the error
264
+ /// otherwise.
265
+ dnnl_status_t DNNL_API dnnl_graph_op_add_output(
266
+ dnnl_graph_op_t op, const dnnl_graph_logical_tensor_t *output);
267
+
268
+ /// Sets floating point attribute to an op.
269
+ ///
270
+ /// @param op Input op.
271
+ /// @param name The attribute's name.
272
+ /// @param value The attribute's value.
273
+ /// @param value_len The number of value element.
274
+ /// @returns #dnnl_success on success or a status describing the error
275
+ /// otherwise.
276
+ dnnl_status_t DNNL_API dnnl_graph_op_set_attr_f32(dnnl_graph_op_t op,
277
+ dnnl_graph_op_attr_t name, const float *value, size_t value_len);
278
+
279
+ /// Sets boolean attribute to an op.
280
+ ///
281
+ /// @param op Input op.
282
+ /// @param name The attribute's name.
283
+ /// @param value The attribute's value.
284
+ /// @param value_len The number of value element.
285
+ /// @returns #dnnl_success on success or a status describing the error
286
+ /// otherwise.
287
+ dnnl_status_t DNNL_API dnnl_graph_op_set_attr_bool(dnnl_graph_op_t op,
288
+ dnnl_graph_op_attr_t name, const uint8_t *value, size_t value_len);
289
+
290
+ /// Sets integer attribute to an op.
291
+ ///
292
+ /// @param op Input op.
293
+ /// @param name The attribute's name.
294
+ /// @param value The attribute's value.
295
+ /// @param value_len The number of value element.
296
+ /// @returns #dnnl_success on success or a status describing the error
297
+ /// otherwise.
298
+ dnnl_status_t DNNL_API dnnl_graph_op_set_attr_s64(dnnl_graph_op_t op,
299
+ dnnl_graph_op_attr_t name, const int64_t *value, size_t value_len);
300
+
301
+ /// Sets string attribute to an op.
302
+ ///
303
+ /// @param op Input op.
304
+ /// @param name The attribute's name.
305
+ /// @param value The attribute's value.
306
+ /// @param value_len The length of the string value.
307
+ /// @returns #dnnl_success on success or a status describing the error
308
+ /// otherwise.
309
+ dnnl_status_t DNNL_API dnnl_graph_op_set_attr_str(dnnl_graph_op_t op,
310
+ dnnl_graph_op_attr_t name, const char *value, size_t value_len);
311
+
312
+ /// Returns the unique id of an op.
313
+ ///
314
+ /// @param op Input op.
315
+ /// @param id Output the unique id.
316
+ /// @returns #dnnl_success on success or a status describing the error
317
+ /// otherwise.
318
+ dnnl_status_t DNNL_API dnnl_graph_op_get_id(
319
+ const_dnnl_graph_op_t op, size_t *id);
320
+
321
+ /// Returns the kind of an op.
322
+ ///
323
+ /// @param op Input op.
324
+ /// @param kind Output op kind.
325
+ /// @returns #dnnl_success on success or a status describing the error
326
+ /// otherwise.
327
+ dnnl_status_t DNNL_API dnnl_graph_op_get_kind(
328
+ const_dnnl_graph_op_t op, dnnl_graph_op_kind_t *kind);
329
+
330
+ /// @} dnnl_graph_api_op
331
+
332
+ /// @addtogroup dnnl_graph_api_partition
333
+ /// @{
334
+
335
+ /// Creates a new partition with a given operator and engine kind. The API is
336
+ /// used to create a partition from an operation directly without creating the
337
+ /// graph and calling `get_partitions()`. The output partition contains only one
338
+ /// operation specified by the parameter. The output partition instance should
339
+ /// be destroyed via #dnnl_graph_partition_destroy after use.
340
+ ///
341
+ /// @param partition The handle of output partition.
342
+ /// @param op The operation used to create partition.
343
+ /// @param ekind The engine kind used to create partition.
344
+ /// @returns #dnnl_success on success or a status describing the error
345
+ /// otherwise.
346
+ dnnl_status_t DNNL_API dnnl_graph_partition_create_with_op(
347
+ dnnl_graph_partition_t *partition, const_dnnl_graph_op_t op,
348
+ dnnl_engine_kind_t ekind);
349
+
350
+ /// Destroys a partition.
351
+ ///
352
+ /// @param partition The partition to be destroyed.
353
+ /// @returns #dnnl_success on success or a status describing the error
354
+ /// otherwise.
355
+ dnnl_status_t DNNL_API dnnl_graph_partition_destroy(
356
+ dnnl_graph_partition_t partition);
357
+
358
+ /// Returns the number of operations in a partition.
359
+ ///
360
+ /// @param partition The target partition.
361
+ /// @param num Output the number of operations.
362
+ /// @returns #dnnl_success on success or a status describing the error
363
+ /// otherwise.
364
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_op_num(
365
+ const_dnnl_graph_partition_t partition, size_t *num);
366
+
367
+ /// Returns the list of op IDs of the partition.
368
+ ///
369
+ /// @param partition The target partition.
370
+ /// @param num The number of ops.
371
+ /// @param ids Output the op IDs.
372
+ /// @returns #dnnl_success on success or a status describing the error
373
+ /// otherwise.
374
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_ops(
375
+ dnnl_graph_partition_t partition, size_t num, size_t *ids);
376
+
377
+ /// Returns the ID of a partition.
378
+ ///
379
+ /// @param partition The target partition.
380
+ /// @param id Output the ID of the partition.
381
+ /// @returns #dnnl_success on success or a status describing the error
382
+ /// otherwise.
383
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_id(
384
+ const_dnnl_graph_partition_t partition, size_t *id);
385
+
386
+ /// Compiles a partition with given input and output logical tensors. The output
387
+ /// logical tensors can contain unknown dimensions. For this case, the
388
+ /// compilation will deduce the output shapes according to input shapes. The
389
+ /// output logical tensors can also have layout type `any`. The compilation will
390
+ /// choose the optimal layout for output tensors. The optimal layout will be
391
+ /// represented as an opaque layout ID saved in the output logical tensor.
392
+ ///
393
+ /// @param partition The target partition.
394
+ /// @param compiled_partition Output compiled partition.
395
+ /// @param in_num The number of input logical tensors.
396
+ /// @param inputs A list of input logical tensors.
397
+ /// @param out_num The number of output logical tensors.
398
+ /// @param outputs A list of output logical tensors.
399
+ /// @param engine The target engine of the compilation.
400
+ /// @returns #dnnl_success on success or a status describing the error
401
+ /// otherwise.
402
+ dnnl_status_t DNNL_API dnnl_graph_partition_compile(
403
+ dnnl_graph_partition_t partition,
404
+ dnnl_graph_compiled_partition_t compiled_partition, size_t in_num,
405
+ const dnnl_graph_logical_tensor_t **inputs, size_t out_num,
406
+ const dnnl_graph_logical_tensor_t **outputs, dnnl_engine_t engine);
407
+
408
+ /// Returns the number of input logical tensors of a partition.
409
+ ///
410
+ /// @param partition The target partition.
411
+ /// @param num Output the number of input logical tensors.
412
+ /// @returns #dnnl_success on success or a status describing the error
413
+ /// otherwise.
414
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_input_ports_num(
415
+ const_dnnl_graph_partition_t partition, size_t *num);
416
+
417
+ /// Returns a list of input logical tensors from a partition.
418
+ ///
419
+ /// @param partition The target partition.
420
+ /// @param num The number of input logical tensors.
421
+ /// @param inputs The list of input logical tensors.
422
+ /// @returns #dnnl_success on success or a status describing the error
423
+ /// otherwise.
424
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_input_ports(
425
+ const_dnnl_graph_partition_t partition, size_t num,
426
+ dnnl_graph_logical_tensor_t *inputs);
427
+
428
+ /// Returns the number of output logical tensors of a partition.
429
+ ///
430
+ /// @param partition The target partition.
431
+ /// @param num Output the number of output logical tensors.
432
+ /// @returns #dnnl_success on success or a status describing the error
433
+ /// otherwise.
434
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_output_ports_num(
435
+ const_dnnl_graph_partition_t partition, size_t *num);
436
+
437
+ /// Returns a list of output logical tensors from a partition.
438
+ ///
439
+ /// @param partition The target partition.
440
+ /// @param num The number of output logical tensors.
441
+ /// @param outputs The list of output logical tensors.
442
+ /// @returns #dnnl_success on success or a status describing the error
443
+ /// otherwise.
444
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_output_ports(
445
+ const_dnnl_graph_partition_t partition, size_t num,
446
+ dnnl_graph_logical_tensor_t *outputs);
447
+
448
+ /// Returns the supporting status of a partition. Some operations may not be
449
+ /// supported by the library under certain circumstances. During partitioning
450
+ /// stage, unsupported partitions will be returned to users with each containing
451
+ /// an unsupported operation. Users should check the supporting status of a
452
+ /// partition before transforming the computation graph or compiling the
453
+ /// partition.
454
+ ///
455
+ /// @param partition The target partition.
456
+ /// @param is_supported Output flag to indicate the supporting status. 0 means
457
+ /// unsupported while 1 means supported.
458
+ /// @returns #dnnl_success on success or a status describing the error
459
+ /// otherwise.
460
+ dnnl_status_t DNNL_API dnnl_graph_partition_is_supported(
461
+ const_dnnl_graph_partition_t partition, uint8_t *is_supported);
462
+
463
+ /// Returns the engine kind of a partition.
464
+ ///
465
+ /// @param partition The target partition.
466
+ /// @param kind The output engine kind.
467
+ /// @returns #dnnl_success on success or a status describing the error
468
+ /// otherwise.
469
+ dnnl_status_t DNNL_API dnnl_graph_partition_get_engine_kind(
470
+ const_dnnl_graph_partition_t partition, dnnl_engine_kind_t *kind);
471
+
472
+ /// @} dnnl_graph_api_partition
473
+
474
+ /// @addtogroup dnnl_graph_api_compiled_partition
475
+ /// @{
476
+
477
+ /// Creates a new compiled partition handle.
478
+ ///
479
+ /// @param compiled_partition The handle of output compiled partition.
480
+ /// @param partition The handle of input partition.
481
+ /// @returns #dnnl_success on success or a status describing the error
482
+ /// otherwise.
483
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_create(
484
+ dnnl_graph_compiled_partition_t *compiled_partition,
485
+ dnnl_graph_partition_t partition);
486
+
487
+ /// Executes a compiled partition.
488
+ ///
489
+ /// @param compiled_partition The handle of target compiled partition.
490
+ /// @param stream The stream used for execution.
491
+ /// @param num_inputs The number of input tensors.
492
+ /// @param inputs A list of input tensors.
493
+ /// @param num_outputs The number of output tensors.
494
+ /// @param outputs A non-empty list of output tensors.
495
+ /// @returns #dnnl_success on success or a status describing the error
496
+ /// otherwise.
497
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_execute(
498
+ const_dnnl_graph_compiled_partition_t compiled_partition,
499
+ dnnl_stream_t stream, size_t num_inputs,
500
+ const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
501
+ const_dnnl_graph_tensor_t *outputs);
502
+
503
+ /// Destroys a compiled partition.
504
+ ///
505
+ /// @param compiled_partition The compiled partition to be destroyed.
506
+ /// @returns #dnnl_success on success or a status describing the error
507
+ /// otherwise.
508
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_destroy(
509
+ dnnl_graph_compiled_partition_t compiled_partition);
510
+
511
+ /// Queries an input or output logical tensor according to tensor ID. If the
512
+ /// tensor ID doesn't belong to any input or output of the compiled partition,
513
+ /// an error status #dnnl_invalid_arguments will be returned by the API.
514
+ ///
515
+ /// @param compiled_partition The handle of target compiled_partition.
516
+ /// @param tid The unique id of required tensor.
517
+ /// @param lt The output logical tensor.
518
+ /// @returns #dnnl_success on success or a status describing the error
519
+ /// otherwise.
520
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_query_logical_tensor(
521
+ const_dnnl_graph_compiled_partition_t compiled_partition, size_t tid,
522
+ dnnl_graph_logical_tensor_t *lt);
523
+
524
+ /// Returns the hint of in-place pairs from a compiled partition. It indicates
525
+ /// that an input and an output of the partition can share the same memory
526
+ /// buffer for computation. In-place computation helps to reduce the memory
527
+ /// footprint and improves cache locality. But since the library may not have a
528
+ /// global view of user's application, it's possible that the tensor with
529
+ /// `input_id` is used at other places in user's computation graph. In this
530
+ /// case, the user should take the in-place pair as a hint and pass a different
531
+ /// memory buffer for output tensor to avoid overwriting the input memory buffer
532
+ /// which will probably cause unexpected incorrect results.
533
+ ///
534
+ /// @param compiled_partition The handle of target compiled_partition.
535
+ /// @param num_inplace_pairs The number of in-place pairs.
536
+ /// @param inplace_pairs The handle of in-place pairs.
537
+ /// @returns #dnnl_success on success or a status describing the error
538
+ /// otherwise.
539
+ dnnl_status_t DNNL_API dnnl_graph_compiled_partition_get_inplace_ports(
540
+ const_dnnl_graph_compiled_partition_t compiled_partition,
541
+ size_t *num_inplace_pairs,
542
+ const dnnl_graph_inplace_pair_t **inplace_pairs);
543
+
544
+ /// @} dnnl_graph_api_compiled_partition
545
+
546
+ /// @addtogroup dnnl_graph_api_graph
547
+ /// @{
548
+
549
+ /// Creates a new empty graph. A graph is associated to a specific engine kind.
550
+ /// The partitions returned from the graph will inherit the engine kind of the
551
+ /// graph.
552
+ ///
553
+ /// @param graph The handle of output graph.
554
+ /// @param engine_kind The target engine kind.
555
+ /// @returns #dnnl_success on success or a status describing the error
556
+ /// otherwise.
557
+ dnnl_status_t DNNL_API dnnl_graph_graph_create(
558
+ dnnl_graph_graph_t *graph, dnnl_engine_kind_t engine_kind);
559
+
560
+ /// Creates a new empty graph with an engine kind and a floating-point math
561
+ /// mode. All partitions returned from the graph will inherit the engine kind
562
+ /// and floating-point math mode.
563
+ ///
564
+ /// @param graph The handle of output graph.
565
+ /// @param engine_kind The kind for engine.
566
+ /// @param mode The floating-point math mode.
567
+ /// @returns #dnnl_success on success or a status describing the error
568
+ /// otherwise.
569
+ dnnl_status_t DNNL_API dnnl_graph_graph_create_with_fpmath_mode(
570
+ dnnl_graph_graph_t *graph, dnnl_engine_kind_t engine_kind,
571
+ dnnl_fpmath_mode_t mode);
572
+
573
+ /// Destroys a graph.
574
+ ///
575
+ /// @param graph The graph to be destroyed.
576
+ /// @returns #dnnl_success on success or a status describing the error
577
+ /// otherwise.
578
+ dnnl_status_t DNNL_API dnnl_graph_graph_destroy(dnnl_graph_graph_t graph);
579
+
580
+ /// Adds an operation into a graph. The API will return failure if the operator
581
+ /// has already been added to the graph or the operation cannot pass the schema
582
+ /// check in the library (eg. input and output numbers and data types, the
583
+ /// attributes of the operation, etc.).
584
+ ///
585
+ /// @param graph The target graph.
586
+ /// @param op The operation to be added.
587
+ /// @returns #dnnl_success on success or a status describing the error
588
+ /// otherwise.
589
+ dnnl_status_t DNNL_API dnnl_graph_add_op(
590
+ dnnl_graph_graph_t graph, dnnl_graph_op_t op);
591
+
592
+ /// Finalizes a graph. It means users have finished adding operations into the
593
+ /// graph and the graph is ready for partitioning. Adding a new operation into a
594
+ /// finalized graph will return failures. Similarly, partitioning on a
595
+ /// un-finalized graph will also return failures.
596
+ ///
597
+ /// @param graph The target graph to be finalized.
598
+ /// @returns #dnnl_success on success or a status describing the error
599
+ /// otherwise.
600
+ dnnl_status_t DNNL_API dnnl_graph_graph_finalize(dnnl_graph_graph_t graph);
601
+
602
+ /// Checks if a graph is finalized.
603
+ ///
604
+ /// @param graph The target graph to be finalized.
605
+ /// @param finalized Output the finalization status. 0 means then graph is not
606
+ /// finalized. Other values means the graph is finalized.
607
+ /// @returns #dnnl_success on success or a status describing the error
608
+ /// otherwise.
609
+ dnnl_status_t DNNL_API dnnl_graph_graph_is_finalized(
610
+ dnnl_graph_graph_t graph, uint8_t *finalized);
611
+
612
+ /// Filters a graph. Partitions will be claimed internally according to the
613
+ /// capability of the library, the engine kind, and the policy.
614
+ ///
615
+ /// @param graph The target graph.
616
+ /// @param policy The partition policy.
617
+ /// @returns #dnnl_success on success or a status describing the error
618
+ /// otherwise.
619
+ dnnl_status_t DNNL_API dnnl_graph_graph_filter(
620
+ dnnl_graph_graph_t graph, dnnl_graph_partition_policy_t policy);
621
+
622
+ /// Returns the number of partitions of a graph. The API should be called after
623
+ /// a partition is already filtered. Otherwise, the output number is zero.
624
+ ///
625
+ /// @param graph The graph.
626
+ /// @param num Output the number of partitions.
627
+ /// @returns #dnnl_success on success or a status describing the error
628
+ /// otherwise.
629
+ dnnl_status_t DNNL_API dnnl_graph_graph_get_partition_num(
630
+ const_dnnl_graph_graph_t graph, size_t *num);
631
+
632
+ /// Returns the partitions from a filtered graph. Output partition instances
633
+ /// will be written into the parameter `partitions`. Users need to make sure
634
+ /// `partitions` is valid and has enough space to accept the partition
635
+ /// instances. Each output partition instance should be destroyed via
636
+ /// #dnnl_graph_partition_destroy explicitly after use.
637
+ ///
638
+ /// @param graph The target graph.
639
+ /// @param num The number of partitions.
640
+ /// @param partitions Output the partitions.
641
+ /// @returns #dnnl_success on success or a status describing the error
642
+ /// otherwise.
643
+ dnnl_status_t DNNL_API dnnl_graph_graph_get_partitions(dnnl_graph_graph_t graph,
644
+ size_t num, dnnl_graph_partition_t *partitions);
645
+
646
+ /// @} dnnl_graph_api_graph
647
+
648
+ /// @addtogroup dnnl_graph_api_compiled_partition_cache
649
+ /// @{
650
+
651
+ /// Returns the number of compiled partitions that can be held in the compiled
652
+ /// partition cache at the same time.
653
+ ///
654
+ /// @param capacity Compiled partition cache capacity to query. Concurrently
655
+ /// accessing @p capacity is safe.
656
+ /// @returns #dnnl_invalid_arguments if the @p capacity value
657
+ /// is invalid, and #dnnl_success on success.
658
+ dnnl_status_t DNNL_API dnnl_graph_get_compiled_partition_cache_capacity(
659
+ int *capacity);
660
+
661
+ /// Sets a number of compiled partitions that can be held in the compiled
662
+ /// partition cache at the same time. The default capacity of compiled partition
663
+ /// cache is 1024.
664
+ ///
665
+ /// @param capacity Compiled partition cache capacity to set. The default cache
666
+ /// capacity is 1024. If a new @p capacity is less than a number of compiled
667
+ /// partition that the compiled partition cache already has, then the excess
668
+ /// entries will be evicted. Setting the @p capacity to 0 clears the compiled
669
+ /// partition cache and disables it. Concurrently modifying @p capacity is safe.
670
+ /// @returns #dnnl_invalid_arguments if the @p capacity value
671
+ /// is invalid, and #dnnl_success on success.
672
+ dnnl_status_t DNNL_API dnnl_graph_set_compiled_partition_cache_capacity(
673
+ int capacity);
674
+
675
+ /// @} dnnl_graph_api_compiled_partition_cache
676
+
677
+ /// @addtogroup dnnl_graph_api_constant_tensor_cache
678
+ /// @{
679
+
680
+ /// Control the enabling or disabling of constant tensor cache. This API must
681
+ /// be called once before compilation stage. By default, constant tensor cache is
682
+ /// disabled in the library.
683
+ ///
684
+ /// @param flag Set to positive value to enable the cache and set to 0 to
685
+ /// disable the cache. Negative values are invalid.
686
+ /// @returns #dnnl_invalid_arguments if the @p flag value is
687
+ /// invalid, and #dnnl_success on success.
688
+ /// @note This API is deprecated and will be removed in future release, please
689
+ /// use the dnnl_graph_set_constant_tensor_cache_capacity API to disable
690
+ /// constant tensor cache by setting it's capacity to zero.
691
+ dnnl_status_t DNNL_API dnnl_graph_set_constant_tensor_cache(int flag);
692
+
693
+ /// Return the enabling or disabling status of constant tensor cache.
694
+ ///
695
+ /// @param flag The constant tensor cache enabling status to query.
696
+ /// @returns #dnnl_invalid_arguments if the @p flag value is
697
+ /// nullptr, and #dnnl_success on success.
698
+ /// @note This API is deprecated and will be removed in future release, please
699
+ /// use the dnnl_graph_get_constant_tensor_cache_capacity API to check the
700
+ /// enabling status by checking it's capacity.
701
+ dnnl_status_t DNNL_API dnnl_graph_get_constant_tensor_cache(int *flag);
702
+
703
+ /// Control the capacity for the constant tensor cache that used for specific
704
+ /// engine kind. This API is thread safe and can be called multiple times at
705
+ /// runtime. The capacity is set to zero by default which means the cache is
706
+ /// disabled. When calling this API, the corresponding cache will be flushed.
707
+ /// Setting capacity to 0 means to clear all cached tensors and disable cache.
708
+ /// Once the capacity limit is reached, no new tensors will be cached. If there
709
+ /// are multiple devices for an engine kind, the capacity set here is for each
710
+ /// device.
711
+ ///
712
+ /// @param eng_kind The engine kind that the constant tensor cache used for.
713
+ /// @param size The constant tensor cache capacity size to set.
714
+ /// @returns #dnnl_invalid_arguments if the @p eng_kind value is invalid, and
715
+ /// #dnnl_success on success.
716
+ dnnl_status_t DNNL_API dnnl_graph_set_constant_tensor_cache_capacity(
717
+ dnnl_engine_kind_t eng_kind, size_t size);
718
+
719
+ /// Return the current capacity of constant tensor cache.
720
+ ///
721
+ /// @param eng_kind The engine kind that the constant tensor cache used for.
722
+ /// @param size The constant tensor cache capacity size to query.
723
+ /// @returns #dnnl_invalid_arguments if the @p eng_kind value is
724
+ /// nullptr or the @p size is nullptr, and #dnnl_success on success.
725
+ dnnl_status_t DNNL_API dnnl_graph_get_constant_tensor_cache_capacity(
726
+ dnnl_engine_kind_t eng_kind, size_t *size);
727
+
728
+ /// @} dnnl_graph_api_constant_tensor_cache
729
+
730
+ /// @} dnnl_graph_api
731
+
732
+ #ifdef __cplusplus
733
+ }
734
+ #endif
735
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph.hpp ADDED
@@ -0,0 +1,1569 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_HPP
18
+ #define ONEAPI_DNNL_DNNL_GRAPH_HPP
19
+
20
+ #include "oneapi/dnnl/dnnl_common.hpp"
21
+ #include "oneapi/dnnl/dnnl_graph.h"
22
+
23
+ #include <limits>
24
+ #include <memory>
25
+ #include <string>
26
+ #include <utility>
27
+ #include <vector>
28
+
29
+ /// @addtogroup dnnl_api
30
+ /// @{
31
+
32
+ /// @addtogroup dnnl_graph_api Graph API
33
+ /// @{
34
+
35
+ namespace dnnl {
36
+ namespace graph {
37
+
38
+ /// @cond DO_NOT_DOCUMENT_THIS
39
+
40
+ // Alias for common engine and stream API.
41
+ using engine = dnnl::engine;
42
+ using stream = dnnl::stream;
43
+ using fpmath_mode = dnnl::fpmath_mode;
44
+
45
+ /// @endcond
46
+
47
+ /// @addtogroup dnnl_graph_api_utils Utilities
48
+ /// Utility types and definitions
49
+ /// @{
50
+
51
+ /// @cond DO_NOT_DOCUMENT_THIS
52
+
53
+ /// A class that provides the destructor for a oneDNN graph C API handle.
54
+ template <typename T>
55
+ struct graph_handle_traits : public dnnl::handle_traits<T> {};
56
+
57
+ template <>
58
+ struct graph_handle_traits<dnnl_graph_op_t> {
59
+ static dnnl_status_t destructor(dnnl_graph_op_t p) {
60
+ return dnnl_graph_op_destroy(p);
61
+ }
62
+ };
63
+
64
+ template <>
65
+ struct graph_handle_traits<dnnl_graph_graph_t> {
66
+ static dnnl_status_t destructor(dnnl_graph_graph_t p) {
67
+ return dnnl_graph_graph_destroy(p);
68
+ }
69
+ };
70
+
71
+ template <>
72
+ struct graph_handle_traits<dnnl_graph_tensor_t> {
73
+ static dnnl_status_t destructor(dnnl_graph_tensor_t p) {
74
+ return dnnl_graph_tensor_destroy(p);
75
+ }
76
+ };
77
+
78
+ template <>
79
+ struct graph_handle_traits<dnnl_graph_partition_t> {
80
+ static dnnl_status_t destructor(dnnl_graph_partition_t p) {
81
+ return dnnl_graph_partition_destroy(p);
82
+ }
83
+ };
84
+
85
+ template <>
86
+ struct graph_handle_traits<dnnl_graph_compiled_partition_t> {
87
+ static dnnl_status_t destructor(dnnl_graph_compiled_partition_t p) {
88
+ return dnnl_graph_compiled_partition_destroy(p);
89
+ }
90
+ };
91
+
92
+ template <>
93
+ struct graph_handle_traits<dnnl_graph_allocator_t> {
94
+ static dnnl_status_t destructor(dnnl_graph_allocator_t p) {
95
+ return dnnl_graph_allocator_destroy(p);
96
+ }
97
+ };
98
+
99
+ #define DNNL_GRAPH_HANDLE_ALIAS(type) \
100
+ using type##_handle = dnnl::handle<dnnl_graph_##type##_t, \
101
+ graph_handle_traits<dnnl_graph_##type##_t>>
102
+
103
+ DNNL_GRAPH_HANDLE_ALIAS(allocator);
104
+ DNNL_GRAPH_HANDLE_ALIAS(graph);
105
+ DNNL_GRAPH_HANDLE_ALIAS(op);
106
+ DNNL_GRAPH_HANDLE_ALIAS(tensor);
107
+ DNNL_GRAPH_HANDLE_ALIAS(compiled_partition);
108
+ DNNL_GRAPH_HANDLE_ALIAS(partition);
109
+
110
+ #undef DNNL_GRAPH_HANDLE_ALIAS
111
+
112
+ template <bool B>
113
+ using req = typename std::enable_if<B, bool>::type;
114
+
115
+ /// @endcond
116
+
117
+ /// @} dnnl_graph_api_utils
118
+
119
+ /// @addtogroup dnnl_graph_api_status Status
120
+ /// Definitions of status values returned by the library functions.
121
+ ///
122
+ /// @{
123
+
124
+ /// Status values returned by the library functions.
125
+ enum class status {
126
+ /// The operation was successful
127
+ success = dnnl_success,
128
+ /// The operation failed due to an out-of-memory condition
129
+ out_of_memory = dnnl_out_of_memory,
130
+ /// The operation failed because of incorrect function arguments
131
+ invalid_arguments = dnnl_invalid_arguments,
132
+ /// The operation failed because requested functionality is not implemented
133
+ unimplemented = dnnl_unimplemented,
134
+ /// The last available implementation is reached
135
+ last_impl_reached = dnnl_last_impl_reached,
136
+ /// Primitive or engine failed on execution
137
+ runtime_error = dnnl_runtime_error,
138
+ /// Queried element is not required for given primitive
139
+ not_required = dnnl_not_required,
140
+ /// The graph is not legitimate
141
+ invalid_graph = dnnl_invalid_graph,
142
+ /// The operation is not legitimate according to op schema
143
+ invalid_graph_op = dnnl_invalid_graph_op,
144
+ /// The shape cannot be inferred or compiled
145
+ invalid_shape = dnnl_invalid_shape,
146
+ /// The data type cannot be inferred or compiled
147
+ invalid_data_type = dnnl_invalid_data_type,
148
+ };
149
+
150
+ /// @} dnnl_api_status
151
+
152
+ /// @addtogroup dnnl_graph_api_allocator Allocator
153
+ ///
154
+ /// Definitions of allocator which is used to acquire memory resources in
155
+ /// partition compilation and execution. SYCL allocator
156
+ /// (#dnnl::graph::sycl_interop::make_allocator) should be used for SYCL runtime
157
+ /// and host allocator should be used for non-SYCL.
158
+ ///
159
+ /// @{
160
+
161
+ /// Allocator
162
+ class allocator : public allocator_handle {
163
+ public:
164
+ using allocator_handle::handle;
165
+
166
+ /// Constructs an allocator according to given function pointers
167
+ ///
168
+ /// @param host_malloc A pointer to malloc function for CPU
169
+ /// @param host_free A pointer to free function for CPU
170
+ allocator(dnnl_graph_host_allocate_f host_malloc,
171
+ dnnl_graph_host_deallocate_f host_free) {
172
+ dnnl_graph_allocator_t a = nullptr;
173
+ error::wrap_c_api(
174
+ dnnl_graph_allocator_create(&a, host_malloc, host_free),
175
+ "could not create allocator for cpu");
176
+ reset(a);
177
+ }
178
+
179
+ /// Default constructor
180
+ allocator() {
181
+ dnnl_graph_allocator_t a = nullptr;
182
+ error::wrap_c_api(dnnl_graph_allocator_create(&a, nullptr, nullptr),
183
+ "could not create allocator");
184
+ reset(a);
185
+ }
186
+ };
187
+
188
+ /// @} dnnl_graph_api_allocator
189
+
190
+ /// @addtogroup dnnl_graph_api_engine Engine
191
+ /// @{
192
+
193
+ /// This API is a supplement for existing onednn engine API.
194
+ inline engine make_engine_with_allocator(
195
+ engine::kind kind, size_t index, const allocator &alloc) {
196
+ dnnl_engine_t c_engine;
197
+ error::wrap_c_api(
198
+ dnnl_graph_make_engine_with_allocator(&c_engine,
199
+ static_cast<dnnl_engine_kind_t>(kind), index, alloc.get()),
200
+ "could not make an engine with allocator");
201
+ return engine(c_engine);
202
+ }
203
+
204
+ /// @} dnnl_graph_api_engine
205
+
206
+ /// @addtogroup dnnl_graph_api_logical_tensor Logical Tensor
207
+ ///
208
+ /// Logical tensor describes the meta-data of the input or output tensor, like
209
+ /// elements data type, number of dimensions, size for each dimension (shape),
210
+ /// layout, and the property of the tensor.
211
+ ///
212
+ /// Each logical tensor has an unique ID. The library uses logical tensor IDs to
213
+ /// build up the connections between operations if the output of one operation
214
+ /// has the same ID as the input of another operation. The meta-data in a
215
+ /// logical tensor may be enriched in the framework graph as it progresses
216
+ /// toward final execution. For example, the library doesn't require detailed
217
+ /// shape information at the operation and graph creation stage. But shape
218
+ /// information of input logical tensor will be required at partition
219
+ /// compilation stage. Logical tensor is not mutable. Users must create a new
220
+ /// logical tensor with the same ID to pass any new additional information to
221
+ /// oneDNN Graph API. Please note that the library also has unique IDs for
222
+ /// operations. The ID should be unique among different logical tensors, but it
223
+ /// can have the same value between a logical tensor and an operation.
224
+ ///
225
+ /// @{
226
+
227
+ /// Logical tensor object
228
+ class logical_tensor {
229
+ friend class op;
230
+ friend class tensor;
231
+ friend class partition;
232
+ friend class compiled_partition;
233
+
234
+ dnnl_graph_logical_tensor_t data;
235
+
236
+ public:
237
+ /// Integer type for representing dimension sizes and indices.
238
+ using dim = dnnl_dim_t;
239
+ /// Vector of dimensions. Implementations are free to force a limit on the
240
+ /// vector's length.
241
+ using dims = std::vector<dim>;
242
+
243
+ /// Data Type
244
+ enum class data_type {
245
+ undef = dnnl_data_type_undef,
246
+ /// 16-bit/half-precision floating point.
247
+ f16 = dnnl_f16,
248
+ /// non-standard 16-bit (bfloat16 w/ 7 bit mantissa) floating point.
249
+ bf16 = dnnl_bf16,
250
+ /// 32-bit/single-precision floating point.
251
+ f32 = dnnl_f32,
252
+ /// 32-bit signed integer.
253
+ s32 = dnnl_s32,
254
+ /// 8-bit signed integer.
255
+ s8 = dnnl_s8,
256
+ /// 8-bit unsigned integer.
257
+ u8 = dnnl_u8,
258
+ /// Boolean data type. Size is C++ implementation defined.
259
+ boolean = dnnl_boolean,
260
+ /// [OFP8 standard 8-bit
261
+ /// floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
262
+ /// with a 5-bit exponent and a 2-bit mantissa.
263
+ f8_e5m2 = dnnl_f8_e5m2,
264
+ /// [OFP8 standard 8-bit
265
+ /// floating-point](https://www.opencompute.org/documents/ocp-8-bit-floating-point-specification-ofp8-revision-1-0-2023-06-20-pdf)
266
+ /// with a 4-bit exponent and a 3-bit mantissa.
267
+ f8_e4m3 = dnnl_f8_e4m3,
268
+ };
269
+
270
+ /// Layout type
271
+ enum class layout_type {
272
+ /// Undefined layout type.
273
+ undef = dnnl_graph_layout_type_undef,
274
+ /// Any means to let the library to decide the layout for a tensor
275
+ /// during partition compilation.
276
+ any = dnnl_graph_layout_type_any,
277
+ /// Strided means that the layout of a tensor is determined by the
278
+ /// strides field in the logical tensor.
279
+ strided = dnnl_graph_layout_type_strided,
280
+ /// Opaque means that the layout of a tensor is the library specific.
281
+ /// Usually, an opaque layout is generated by a partition which is
282
+ /// compiled with layout type any.
283
+ opaque = dnnl_graph_layout_type_opaque,
284
+ };
285
+
286
+ /// Tensor property
287
+ enum class property_type {
288
+ /// Undefined tensor property.
289
+ undef = dnnl_graph_tensor_property_undef,
290
+ /// Variable means the tensor may be changed during computation or
291
+ /// between different iterations.
292
+ variable = dnnl_graph_tensor_property_variable,
293
+ /// Constant means the tensor will keep unchanged during computation and
294
+ /// between different iterations. It's useful for the library to apply
295
+ /// optimizations for constant tensors or cache constant tensors inside
296
+ /// the library. For example, constant weight tensors in inference
297
+ /// scenarios.
298
+ constant = dnnl_graph_tensor_property_constant,
299
+ };
300
+
301
+ /// default constructor
302
+ /// construct an empty object
303
+ logical_tensor() = default;
304
+
305
+ /// Constructs a logical tensor object
306
+ explicit logical_tensor(const dnnl_graph_logical_tensor_t &c_data)
307
+ : data(c_data) {}
308
+
309
+ /// Copy
310
+ logical_tensor(const logical_tensor &other) = default;
311
+
312
+ /// Assign
313
+ logical_tensor &operator=(const logical_tensor &other) = default;
314
+
315
+ /// Constructs a logical tensor object with ID, data type, ndims, layout
316
+ /// type, and property type.
317
+ ///
318
+ /// @param tid Logical tensor ID.
319
+ /// @param dtype Elements data type.
320
+ /// @param ndims Number of dimensions. -1 means unknown (see
321
+ /// #DNNL_GRAPH_UNKNOWN_NDIMS) and 0 means a scalar tensor.
322
+ /// @param ltype Layout type.
323
+ /// @param ptype Property type.
324
+ logical_tensor(size_t tid, data_type dtype, int32_t ndims,
325
+ layout_type ltype, property_type ptype = property_type::undef) {
326
+ dnnl_graph_logical_tensor_t val;
327
+ error::wrap_c_api(
328
+ dnnl_graph_logical_tensor_init(&val, tid, convert_to_c(dtype),
329
+ ndims, convert_to_c(ltype), convert_to_c(ptype)),
330
+ "could not create logical_tensor with property");
331
+ data = val;
332
+ }
333
+
334
+ /// Delegated constructor.
335
+ ///
336
+ /// @param tid Logical tensor ID.
337
+ /// @param dtype Elements data type.
338
+ /// @param ltype Layout type.
339
+ logical_tensor(
340
+ size_t tid, data_type dtype, layout_type ltype = layout_type::undef)
341
+ : logical_tensor(tid, dtype, DNNL_GRAPH_UNKNOWN_NDIMS, ltype) {}
342
+
343
+ /// Constructs a logical tensor object with basic information and detailed
344
+ /// dims.
345
+ ///
346
+ /// @param tid Logical tensor ID.
347
+ /// @param dtype Elements data type.
348
+ /// @param adims Logical tensor dimensions. #DNNL_GRAPH_UNKNOWN_DIM means
349
+ /// the size of that dimension is unknown. 0 is used to define
350
+ /// zero-dimension tensor.
351
+ /// @param ltype Layout type. If it's strided, the strides field in the
352
+ /// output logical tensor will be deduced accordingly.
353
+ /// @param ptype Property type.
354
+ logical_tensor(size_t tid, data_type dtype, const dims &adims,
355
+ layout_type ltype, property_type ptype = property_type::undef) {
356
+ dnnl_graph_logical_tensor_t val;
357
+ // if dimension size equals to 0, it's a scalar
358
+ if (adims.size() == 0)
359
+ error::wrap_c_api(dnnl_graph_logical_tensor_init(&val, tid,
360
+ convert_to_c(dtype), 0,
361
+ convert_to_c(ltype), convert_to_c(ptype)),
362
+ "could not create logical_tensor with property");
363
+ else
364
+ error::wrap_c_api(
365
+ dnnl_graph_logical_tensor_init_with_dims(&val, tid,
366
+ convert_to_c(dtype),
367
+ static_cast<int32_t>(adims.size()), adims.data(),
368
+ convert_to_c(ltype), convert_to_c(ptype)),
369
+ "could not create logical_tensor with dims and property");
370
+ data = val;
371
+ }
372
+
373
+ /// Constructs a logical tensor object with detailed dims and strides. The
374
+ /// layout_type of the output logical tensor object will always be strided.
375
+ ///
376
+ /// @param tid Logical tensor ID.
377
+ /// @param dtype Elements data type.
378
+ /// @param adims Logical tensor dimensions. #DNNL_GRAPH_UNKNOWN_DIM means
379
+ /// the size of that dimension is unknown. 0 is used to define
380
+ /// zero-dimension tensor.
381
+ /// @param strides Logical tensor strides. #DNNL_GRAPH_UNKNOWN_DIM means
382
+ /// the stride of the dimension is unknown. The library currently
383
+ /// doesn't support other negative stride values.
384
+ /// @param ptype Property type.
385
+ logical_tensor(size_t tid, data_type dtype, const dims &adims,
386
+ const dims &strides, property_type ptype = property_type::undef) {
387
+ dnnl_graph_logical_tensor_t val;
388
+ // TODO(lvtao): check the size of adims and strides.
389
+ // They should be same.
390
+ error::wrap_c_api(
391
+ dnnl_graph_logical_tensor_init_with_strides(&val, tid,
392
+ convert_to_c(dtype), static_cast<int32_t>(adims.size()),
393
+ adims.data(), strides.data(), convert_to_c(ptype)),
394
+ "could not create logical_tensor with strides and property");
395
+ data = val;
396
+ }
397
+
398
+ /// Constructs a logical tensor object with detailed dims and an opaque
399
+ /// layout ID. layout_type of the output logical tensor object will always
400
+ /// be opaque.
401
+ ///
402
+ /// @param tid Logical tensor ID.
403
+ /// @param dtype Elements data type.
404
+ /// @param adims Logical tensor dimensions. #DNNL_GRAPH_UNKNOWN_DIM means
405
+ /// the size of that dimension is unknown. 0 is used to define
406
+ /// zero-dimension tensor.
407
+ /// @param lid Opaque layout id.
408
+ /// @param ptype Property type
409
+ logical_tensor(size_t tid, data_type dtype, const dims &adims, size_t lid,
410
+ property_type ptype = property_type::undef) {
411
+ dnnl_graph_logical_tensor_t val;
412
+
413
+ if (adims.size() == 0) {
414
+ error::wrap_c_api(dnnl_graph_logical_tensor_init(&val, tid,
415
+ convert_to_c(dtype), 0,
416
+ convert_to_c(layout_type::opaque),
417
+ convert_to_c(ptype)),
418
+ "could not create logical_tensor");
419
+ } else {
420
+ error::wrap_c_api(
421
+ dnnl_graph_logical_tensor_init_with_dims(&val, tid,
422
+ convert_to_c(dtype),
423
+ static_cast<int32_t>(adims.size()), adims.data(),
424
+ convert_to_c(layout_type::opaque),
425
+ convert_to_c(ptype)),
426
+ "could not create logical_tensor with dims");
427
+ }
428
+
429
+ val.layout.layout_id = lid;
430
+ data = val;
431
+ }
432
+
433
+ /// Returns dimensions of a logical tensor.
434
+ ///
435
+ /// @returns A vector describing the size of each dimension.
436
+ dims get_dims() const {
437
+ if (data.ndims < 0) {
438
+ error::wrap_c_api(dnnl_invalid_arguments,
439
+ "cannot return dims when ndims < 0");
440
+ }
441
+
442
+ return {data.dims, data.dims + data.ndims};
443
+ }
444
+
445
+ /// Returns the unique id of a logical tensor.
446
+ ///
447
+ /// @returns An integer value describing the ID.
448
+ size_t get_id() const { return data.id; }
449
+
450
+ /// Returns the data type of a logical tensor.
451
+ ///
452
+ /// @returns The data type.
453
+ data_type get_data_type() const {
454
+ return static_cast<data_type>(data.data_type);
455
+ }
456
+
457
+ /// Returns the property type of a logical tensor.
458
+ ///
459
+ /// @returns The property type.
460
+ property_type get_property_type() const {
461
+ return static_cast<property_type>(data.property);
462
+ }
463
+
464
+ /// Returns the layout type of a logical tensor.
465
+ ///
466
+ /// @returns The layout type.
467
+ layout_type get_layout_type() const {
468
+ return static_cast<layout_type>(data.layout_type);
469
+ }
470
+
471
+ /// Returns the layout ID of a logical tensor. The API should be called on a
472
+ /// logical tensor with opaque layout type. Otherwise, an exception will be
473
+ /// raised.
474
+ ///
475
+ /// @returns Layout ID.
476
+ size_t get_layout_id() const {
477
+ if (get_layout_type() != layout_type::opaque) {
478
+ error::wrap_c_api(
479
+ dnnl_invalid_arguments, "layout type should be opaque");
480
+ }
481
+
482
+ return data.layout.layout_id;
483
+ }
484
+
485
+ /// Returns the strides of a logical tensor. The API should be called on a
486
+ /// logical tensor with strided layout type. Otherwise, an exception will be
487
+ /// raised.
488
+ ///
489
+ /// @returns A vector describing the stride size of each dimension.
490
+ dims get_strides() const {
491
+ if (get_layout_type() != layout_type::strided) {
492
+ error::wrap_c_api(
493
+ dnnl_invalid_arguments, "layout type should be strided");
494
+ }
495
+
496
+ if (data.ndims < 0) {
497
+ error::wrap_c_api(dnnl_invalid_arguments,
498
+ "cannot return strides when ndims < 0");
499
+ }
500
+
501
+ return {data.layout.strides, data.layout.strides + data.ndims};
502
+ }
503
+
504
+ /// Returns memory size in bytes required by this logical tensor.
505
+ ///
506
+ /// @returns The memory size in bytes.
507
+ size_t get_mem_size() const {
508
+ size_t size = 0;
509
+ error::wrap_c_api(dnnl_graph_logical_tensor_get_mem_size(&data, &size),
510
+ "could not get memory size from the logical_tensor");
511
+ return size;
512
+ }
513
+
514
+ /// Compares if two logical tenors are equal. Users can decide accordingly
515
+ /// if layout reordering is needed for two logical tensors. The method will
516
+ /// return true for below two circumstances:
517
+ ///
518
+ /// 1. the two logical tensors are equal regarding each field in the struct,
519
+ /// eg. id, ndims, dims, layout type, property, etc.
520
+ /// 2. If all other fields are equal but the layout types in two logical
521
+ /// tensors are different, the method will return true when the underlying
522
+ /// memory layout is the same. For example, one logical tensor has strided
523
+ /// layout type while the other one has opaque layout type, but underneath,
524
+ /// both layouts are NHWC, the method will still return true for this case.
525
+ ///
526
+ /// @param lt The input logical tensor to be compared.
527
+ /// @returns @c true if the two logical tensors are equal. @c false otherwise
528
+ bool is_equal(const logical_tensor &lt) const {
529
+ uint8_t equal = 0;
530
+ error::wrap_c_api(
531
+ dnnl_graph_logical_tensor_is_equal(&data, &lt.data, &equal),
532
+ "could not compare between the two logical tensors");
533
+ return equal != 0;
534
+ }
535
+
536
+ private:
537
+ static dnnl_data_type_t convert_to_c(data_type dtype) {
538
+ return static_cast<dnnl_data_type_t>(dtype);
539
+ }
540
+
541
+ static dnnl_graph_layout_type_t convert_to_c(layout_type ltype) {
542
+ return static_cast<dnnl_graph_layout_type_t>(ltype);
543
+ }
544
+
545
+ static dnnl_graph_tensor_property_t convert_to_c(property_type ptype) {
546
+ return static_cast<dnnl_graph_tensor_property_t>(ptype);
547
+ }
548
+ };
549
+
550
+ /// @} dnnl_graph_api_logical_tensor
551
+
552
+ /// @addtogroup dnnl_graph_api_tensor Tensor
553
+ ///
554
+ /// Tensor is an abstraction for multi-dimensional input and output data needed
555
+ /// in the execution of a compiled partition. A tensor object encapsulates a
556
+ /// handle to a memory buffer allocated on a specific engine and a logical
557
+ /// tensor which describes the dimensions, elements data type, and memory
558
+ /// layout.
559
+ ///
560
+ /// @{
561
+
562
+ /// A tensor object
563
+ class tensor : public tensor_handle {
564
+ public:
565
+ /// Default constructor. Constructs an empty object.
566
+ tensor() = default;
567
+
568
+ /// Constructs a tensor object according to a given logical tensor, an
569
+ /// engine, and a memory handle.
570
+ ///
571
+ /// @param lt The given logical tensor
572
+ /// @param aengine Engine to store the data on.
573
+ /// @param handle Handle of memory buffer to use as an underlying storage.
574
+ /// - A pointer to the user-allocated buffer. In this case the library
575
+ /// doesn't own the buffer.
576
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
577
+ /// allocate the buffer for the tensor. In this case the library
578
+ /// owns the buffer.
579
+ /// - DNNL_MEMORY_NONE to create tensor without an underlying buffer.
580
+ tensor(const logical_tensor &lt, const engine &aengine, void *handle) {
581
+ dnnl_graph_tensor_t t = nullptr;
582
+ error::wrap_c_api(
583
+ dnnl_graph_tensor_create(&t, &(lt.data), aengine.get(), handle),
584
+ "could not create tensor object with the logical_tensor, "
585
+ "engine, and handle");
586
+ reset(t);
587
+ }
588
+
589
+ /// Constructs a tensor object.
590
+ /// The underlying buffer for the memory will be allocated by the library.
591
+ ///
592
+ /// @param lt The given logical tensor
593
+ /// @param aengine Engine to store the data on.
594
+ tensor(const logical_tensor &lt, const engine &aengine)
595
+ : tensor(lt, aengine, DNNL_MEMORY_ALLOCATE) {}
596
+
597
+ /// Returns the underlying memory buffer.
598
+ ///
599
+ /// On the CPU engine, or when using USM, this is a pointer to the
600
+ /// allocated memory.
601
+ void *get_data_handle() const {
602
+ void *handle = nullptr;
603
+ error::wrap_c_api(dnnl_graph_tensor_get_data_handle(get(), &handle),
604
+ "could not get data handle from the tensor");
605
+ return handle;
606
+ }
607
+
608
+ /// Sets the underlying memory handle.
609
+ ///
610
+ /// @param handle Memory handle.
611
+ void set_data_handle(void *handle) {
612
+ error::wrap_c_api(dnnl_graph_tensor_set_data_handle(get(), handle),
613
+ "setting data handle to the tensor failed");
614
+ }
615
+
616
+ /// Returns the associated engine.
617
+ ///
618
+ /// @returns An engine object
619
+ engine get_engine() const {
620
+ dnnl_engine_t c_engine = nullptr;
621
+ error::wrap_c_api(dnnl_graph_tensor_get_engine(get(), &c_engine),
622
+ "could not get an engine from a tensor object");
623
+ return engine(c_engine, true);
624
+ }
625
+ };
626
+
627
+ /// @} dnnl_graph_api_tensor
628
+
629
+ /// @addtogroup dnnl_graph_api_compiled_partition Compiled Partition
630
+ ///
631
+ /// A compiled partition represents the generated kernels specialized for a
632
+ /// partition on a target hardware (engine) with input and output information
633
+ /// specified by the logical tensors.
634
+ ///
635
+ /// @{
636
+
637
+ /// A compiled partition object.
638
+ class compiled_partition : public compiled_partition_handle {
639
+ public:
640
+ /// Default constructor. Constructs an empty object.
641
+ compiled_partition() = default;
642
+
643
+ /// Constructs a compiled partition object
644
+ compiled_partition(dnnl_graph_compiled_partition_t compiled_partition) {
645
+ reset(compiled_partition, false);
646
+ }
647
+
648
+ /// Queries an input or output logical tensor according to tensor ID. If the
649
+ /// tensor ID doesn't belong to any input or output of the compiled
650
+ /// partition, an exception will be raised by the API.
651
+ ///
652
+ /// @param tid The unique id of required tensor.
653
+ /// @returns The logical tensor.
654
+ logical_tensor query_logical_tensor(size_t tid) const {
655
+ dnnl_graph_logical_tensor_t lt;
656
+ error::wrap_c_api(dnnl_graph_compiled_partition_query_logical_tensor(
657
+ get(), tid, &lt),
658
+ "query logical tensor from compiled_partition failed");
659
+ return logical_tensor {lt};
660
+ }
661
+
662
+ /// Returns the hint of in-place pairs from a compiled partition. It
663
+ /// indicates that an input and an output of the partition can share the
664
+ /// same memory buffer for computation. In-place computation helps to reduce
665
+ /// the memory footprint and improves cache locality. But since the library
666
+ /// may not have a global view of user's application, it's possible that the
667
+ /// input tensor is used at other places in user's computation graph. In
668
+ /// this case, the user should take the in-place pair as a hint and pass a
669
+ /// different memory buffer for output tensor to avoid overwriting the input
670
+ /// memory buffer which will probably cause unexpected incorrect results.
671
+ ///
672
+ /// @returns A list of pairs of input and output IDs.
673
+ std::vector<std::pair<size_t, size_t>> get_inplace_ports() const {
674
+ size_t num = 0;
675
+ const dnnl_graph_inplace_pair_t *inplace_pairs;
676
+
677
+ error::wrap_c_api(dnnl_graph_compiled_partition_get_inplace_ports(
678
+ get(), &num, &inplace_pairs),
679
+ "could not get the in-place pairs from a compiled partition");
680
+ if (num == 0) return {};
681
+
682
+ std::vector<std::pair<size_t, size_t>> inplace_options;
683
+ inplace_options.reserve(num);
684
+ for (size_t i = 0; i < num; ++i) {
685
+ const dnnl_graph_inplace_pair_t *inplace_pair = inplace_pairs + i;
686
+ inplace_options.emplace_back(
687
+ inplace_pair->input_id, inplace_pair->output_id);
688
+ }
689
+ return inplace_options;
690
+ }
691
+
692
+ /// Execute a compiled partition.
693
+ ///
694
+ /// @param astream Stream object to run over.
695
+ /// @param inputs A list of input tensors.
696
+ /// @param outputs A list of output tensors.
697
+ void execute(stream &astream, const std::vector<tensor> &inputs,
698
+ const std::vector<tensor> &outputs) const {
699
+ std::vector<const_dnnl_graph_tensor_t> c_inputs;
700
+ c_inputs.reserve(inputs.size());
701
+ for (auto &in : inputs) {
702
+ c_inputs.push_back(in.get());
703
+ }
704
+ std::vector<const_dnnl_graph_tensor_t> c_outputs;
705
+ c_outputs.reserve(outputs.size());
706
+ for (auto &out : outputs) {
707
+ c_outputs.push_back(out.get());
708
+ }
709
+
710
+ error::wrap_c_api(
711
+ dnnl_graph_compiled_partition_execute(get(), astream.get(),
712
+ c_inputs.size(), c_inputs.data(), c_outputs.size(),
713
+ c_outputs.data()),
714
+ "could not execute the compiled_partition");
715
+ }
716
+ };
717
+
718
+ /// @} dnnl_graph_api_compiled_partition
719
+
720
+ /// @addtogroup dnnl_graph_api_op Op
721
+ ///
722
+ /// OP is an abstraction of computation logic for deep neural network
723
+ /// operations. An op object encapsulates an operation kind which describes the
724
+ /// computation logic, an unique ID which differentiates operations with the
725
+ /// same kind, and logical tensors which describes the input and output of the
726
+ /// operation and its connections to other operations in the graph.
727
+ ///
728
+ /// @{
729
+
730
+ /// An op object.
731
+ class op : public op_handle {
732
+ public:
733
+ /// Kinds of operations
734
+ enum class kind {
735
+ Abs = dnnl_graph_op_abs,
736
+ AbsBackward = dnnl_graph_op_abs_backward,
737
+ Add = dnnl_graph_op_add,
738
+ AvgPool = dnnl_graph_op_avg_pool,
739
+ AvgPoolBackward = dnnl_graph_op_avg_pool_backward,
740
+ BatchNormForwardTraining = dnnl_graph_op_batch_norm_forward_training,
741
+ BatchNormInference = dnnl_graph_op_batch_norm_inference,
742
+ BatchNormTrainingBackward = dnnl_graph_op_batch_norm_backward,
743
+ BiasAdd = dnnl_graph_op_bias_add,
744
+ BiasAddBackward = dnnl_graph_op_bias_add_backward,
745
+ Clamp = dnnl_graph_op_clamp,
746
+ ClampBackward = dnnl_graph_op_clamp_backward,
747
+ Concat = dnnl_graph_op_concat,
748
+ Convolution = dnnl_graph_op_convolution,
749
+ ConvolutionBackwardData = dnnl_graph_op_convolution_backward_data,
750
+ ConvolutionBackwardWeights = dnnl_graph_op_convolution_backward_weights,
751
+ ConvTranspose = dnnl_graph_op_conv_transpose,
752
+ ConvTransposeBackwardData = dnnl_graph_op_conv_transpose_backward_data,
753
+ ConvTransposeBackwardWeights
754
+ = dnnl_graph_op_conv_transpose_backward_weights,
755
+ Dequantize = dnnl_graph_op_dequantize,
756
+ Divide = dnnl_graph_op_divide,
757
+ DynamicDequantize = dnnl_graph_op_dynamic_dequantize,
758
+ DynamicQuantize = dnnl_graph_op_dynamic_quantize,
759
+ Elu = dnnl_graph_op_elu,
760
+ EluBackward = dnnl_graph_op_elu_backward,
761
+ End = dnnl_graph_op_end,
762
+ Exp = dnnl_graph_op_exp,
763
+ GELU = dnnl_graph_op_gelu,
764
+ GELUBackward = dnnl_graph_op_gelu_backward,
765
+ HardSigmoid = dnnl_graph_op_hard_sigmoid,
766
+ HardSigmoidBackward = dnnl_graph_op_hard_sigmoid_backward,
767
+ HardSwish = dnnl_graph_op_hard_swish,
768
+ HardSwishBackward = dnnl_graph_op_hard_swish_backward,
769
+ Interpolate = dnnl_graph_op_interpolate,
770
+ InterpolateBackward = dnnl_graph_op_interpolate_backward,
771
+ LayerNorm = dnnl_graph_op_layer_norm,
772
+ LayerNormBackward = dnnl_graph_op_layer_norm_backward,
773
+ LeakyReLU = dnnl_graph_op_leaky_relu,
774
+ Log = dnnl_graph_op_log,
775
+ LogSoftmax = dnnl_graph_op_log_softmax,
776
+ LogSoftmaxBackward = dnnl_graph_op_log_softmax_backward,
777
+ MatMul = dnnl_graph_op_matmul,
778
+ Maximum = dnnl_graph_op_maximum,
779
+ MaxPool = dnnl_graph_op_max_pool,
780
+ MaxPoolBackward = dnnl_graph_op_max_pool_backward,
781
+ Minimum = dnnl_graph_op_minimum,
782
+ Mish = dnnl_graph_op_mish,
783
+ MishBackward = dnnl_graph_op_mish_backward,
784
+ Multiply = dnnl_graph_op_multiply,
785
+ Pow = dnnl_graph_op_pow,
786
+ PReLU = dnnl_graph_op_prelu,
787
+ PReLUBackward = dnnl_graph_op_prelu_backward,
788
+ Quantize = dnnl_graph_op_quantize,
789
+ Reciprocal = dnnl_graph_op_reciprocal,
790
+ ReduceL1 = dnnl_graph_op_reduce_l1,
791
+ ReduceL2 = dnnl_graph_op_reduce_l2,
792
+ ReduceMax = dnnl_graph_op_reduce_max,
793
+ ReduceMean = dnnl_graph_op_reduce_mean,
794
+ ReduceMin = dnnl_graph_op_reduce_min,
795
+ ReduceProd = dnnl_graph_op_reduce_prod,
796
+ ReduceSum = dnnl_graph_op_reduce_sum,
797
+ ReLU = dnnl_graph_op_relu,
798
+ ReLUBackward = dnnl_graph_op_relu_backward,
799
+ Reorder = dnnl_graph_op_reorder,
800
+ Round = dnnl_graph_op_round,
801
+ Select = dnnl_graph_op_select,
802
+ Sigmoid = dnnl_graph_op_sigmoid,
803
+ SigmoidBackward = dnnl_graph_op_sigmoid_backward,
804
+ SoftMax = dnnl_graph_op_softmax,
805
+ SoftMaxBackward = dnnl_graph_op_softmax_backward,
806
+ SoftPlus = dnnl_graph_op_softplus,
807
+ SoftPlusBackward = dnnl_graph_op_softplus_backward,
808
+ Sqrt = dnnl_graph_op_sqrt,
809
+ SqrtBackward = dnnl_graph_op_sqrt_backward,
810
+ Square = dnnl_graph_op_square,
811
+ SquaredDifference = dnnl_graph_op_squared_difference,
812
+ StaticReshape = dnnl_graph_op_static_reshape,
813
+ StaticTranspose = dnnl_graph_op_static_transpose,
814
+ Subtract = dnnl_graph_op_subtract,
815
+ Tanh = dnnl_graph_op_tanh,
816
+ TanhBackward = dnnl_graph_op_tanh_backward,
817
+ TypeCast = dnnl_graph_op_type_cast,
818
+ Wildcard = dnnl_graph_op_wildcard,
819
+ // Sentinel
820
+ LastSymbol = dnnl_graph_op_last_symbol,
821
+ };
822
+
823
+ /// Attributes of operations. Different operations support different
824
+ /// attributes. Check the document of each operation for what attributes are
825
+ /// supported and what are the potential values for them. Missing required
826
+ /// attribute or illegal attribute value may lead to failure when adding the
827
+ /// operation to a graph.
828
+ enum class attr {
829
+ /// Undefined op attribute.
830
+ undef = dnnl_graph_op_attr_undef,
831
+
832
+ // float32 attributes. The value of these attributes can be any single
833
+ // float32 number.
834
+
835
+ /// Specifies an alpha attribute to an op.
836
+ alpha = dnnl_graph_op_attr_alpha,
837
+ /// Specifies an beta attribute to an op.
838
+ beta = dnnl_graph_op_attr_beta,
839
+ /// Specifies an epsilon attribute to an op.
840
+ epsilon = dnnl_graph_op_attr_epsilon,
841
+ /// Specifies a max attribute to an op.
842
+ max = dnnl_graph_op_attr_max,
843
+ /// Specifies a min attribute to an op.
844
+ min = dnnl_graph_op_attr_min,
845
+ /// Specifies a momentum attribute to an op.
846
+ momentum = dnnl_graph_op_attr_momentum,
847
+
848
+ // float32 vector attributes. The value of these attributes can be a
849
+ // vector of float32 numbers.
850
+
851
+ /// Specifies a scales attribute to an op.
852
+ scales = dnnl_graph_op_attr_scales,
853
+
854
+ // int64_t attributes. The value of these attributes can be any single
855
+ // int64 number.
856
+
857
+ /// Specifies an axis attribute to an op.
858
+ axis = dnnl_graph_op_attr_axis,
859
+ /// Specifies a begin_norm_axis attribute to an op.
860
+ begin_norm_axis = dnnl_graph_op_attr_begin_norm_axis,
861
+ /// Specifies a groups attribute to an op.
862
+ groups = dnnl_graph_op_attr_groups,
863
+
864
+ // int64_t vector attributes. The value of these attributes can be a
865
+ // vector of int64 numbers.
866
+
867
+ /// Specifies an axes attribute to an op.
868
+ axes = dnnl_graph_op_attr_axes,
869
+ /// Specifies a dilations attribute to an op.
870
+ dilations = dnnl_graph_op_attr_dilations,
871
+ /// Specifies an dst_shape attribute to an op.
872
+ dst_shape = dnnl_graph_op_attr_dst_shape,
873
+ /// Specifies a kernel attribute to an op.
874
+ kernel = dnnl_graph_op_attr_kernel,
875
+ /// Specifies an order attribute to an op.
876
+ order = dnnl_graph_op_attr_order,
877
+ /// Specifies an output_padding attribute to an op.
878
+ output_padding = dnnl_graph_op_attr_output_padding,
879
+ /// Specifies a pads_begin attribute to an op.
880
+ pads_begin = dnnl_graph_op_attr_pads_begin,
881
+ /// Specifies a pads_end attribute to an op.
882
+ pads_end = dnnl_graph_op_attr_pads_end,
883
+ /// Specifies a shape attribute to an op.
884
+ shape = dnnl_graph_op_attr_shape,
885
+ /// Specifies a sizes attribute to an op.
886
+ sizes = dnnl_graph_op_attr_sizes,
887
+ /// Specifies an src_shape attribute to an op.
888
+ src_shape = dnnl_graph_op_attr_src_shape,
889
+ /// Specifies a strides attribute to an op.
890
+ strides = dnnl_graph_op_attr_strides,
891
+ /// Specifies a weight_shape attribute to an op.
892
+ weights_shape = dnnl_graph_op_attr_weights_shape,
893
+ /// Specifies a zps attribute to an op.
894
+ zps = dnnl_graph_op_attr_zps,
895
+
896
+ // bool attributes. The value of these attributes can be any single bool
897
+ // value.
898
+
899
+ /// Specifies an exclude_pad attribute to an op.
900
+ exclude_pad = dnnl_graph_op_attr_exclude_pad,
901
+ /// Specifies a keep_dims attribute to an op.
902
+ keep_dims = dnnl_graph_op_attr_keep_dims,
903
+ /// Specifies a keep_stats attribute to an op.
904
+ keep_stats = dnnl_graph_op_attr_keep_stats,
905
+ /// Specifies a per_channel_broadcast attribute to an op.
906
+ per_channel_broadcast = dnnl_graph_op_attr_per_channel_broadcast,
907
+ /// Specifies a special_zero attribute to an op.
908
+ special_zero = dnnl_graph_op_attr_special_zero,
909
+ /// Specifies a transpose_a attribute to an op.
910
+ transpose_a = dnnl_graph_op_attr_transpose_a,
911
+ /// Specifies a transpose_b attribute to an op.
912
+ transpose_b = dnnl_graph_op_attr_transpose_b,
913
+ /// Specifies an use_affine attribute to an op.
914
+ use_affine = dnnl_graph_op_attr_use_affine,
915
+ /// Specifies an use_dst attribute to an op.
916
+ use_dst = dnnl_graph_op_attr_use_dst,
917
+
918
+ // string attributes. The value of these attributes can be a string.
919
+
920
+ /// Specifies an auto_broadcast attribute to an op. The value can be
921
+ /// "none" or "numpy".
922
+ auto_broadcast = dnnl_graph_op_attr_auto_broadcast,
923
+ /// Specifies an auto_pad attribute to an op. The value can be "none",
924
+ /// "same_upper", "same_lower", or "valid".
925
+ auto_pad = dnnl_graph_op_attr_auto_pad,
926
+ /// Specifies an coordinate_transformation_mode attribute to an op. The
927
+ /// value can be "half_pixel" or "align_corners". The attribute is
928
+ /// defined for Interpolate operations.
929
+ coordinate_transformation_mode
930
+ = dnnl_graph_op_attr_coordinate_transformation_mode,
931
+ /// Specifies a data_format of an op. The value can be "NCX" or "NXC".
932
+ data_format = dnnl_graph_op_attr_data_format,
933
+ /// Specifies a mode attribute of an op. The value can be "nearest",
934
+ /// "linear", "bilinear", or "trilinear". The attribute is defined for
935
+ /// Interpolate operations.
936
+ mode = dnnl_graph_op_attr_mode,
937
+ /// Specifies a qtype attribute to an op. The value can be "per_channel"
938
+ /// or "per_tensor". The attribute is defined for quantization
939
+ /// operations.
940
+ qtype = dnnl_graph_op_attr_qtype,
941
+ /// Specifies a rounding_type attribute to an op. The value can be
942
+ /// "ceil" or "floor".
943
+ rounding_type = dnnl_graph_op_attr_rounding_type,
944
+ /// Specifies a weights_format of an op. The value can be "OIX", "XIO",
945
+ /// "IOX", or "XOI". Different operations may support different values.
946
+ weights_format = dnnl_graph_op_attr_weights_format,
947
+
948
+ /// Specifies the end of all above exteral attributes for check.
949
+ end = dnnl_graph_op_attr_end,
950
+ };
951
+
952
+ /// Constructs an op object with an unique ID, an operation kind, and a name
953
+ /// string.
954
+ ///
955
+ /// @param id The unique ID of the op.
956
+ /// @param akind The op kind specifies which computation is represented by
957
+ /// the op, such as Convolution or ReLU.
958
+ /// @param verbose_name The string added as the op name.
959
+ op(size_t id, kind akind, const std::string &verbose_name = "") {
960
+ dnnl_graph_op_t op = nullptr;
961
+ error::wrap_c_api(dnnl_graph_op_create(&op, id, convert_to_c(akind),
962
+ verbose_name.c_str()),
963
+ "could not create op with id and op kind");
964
+ reset(op);
965
+ }
966
+
967
+ /// Constructs an op object with an unique ID, an operation kind, and
968
+ /// input/output logical tensors.
969
+ ///
970
+ /// @param id The unique ID of this op.
971
+ /// @param akind The op kind specifies which computation is represented by
972
+ /// this op, such as Convolution or ReLU.
973
+ /// @param inputs Input logical tensor to be bound to this op.
974
+ /// @param outputs Output logical tensor to be bound to this op.
975
+ /// @param verbose_name The string added as the op name.
976
+ op(size_t id, kind akind, const std::vector<logical_tensor> &inputs,
977
+ const std::vector<logical_tensor> &outputs,
978
+ const std::string &verbose_name = "")
979
+ : op(id, akind, verbose_name) {
980
+ for (const auto &input : inputs) {
981
+ error::wrap_c_api(dnnl_graph_op_add_input(get(), &(input.data)),
982
+ "adding input to the op failed");
983
+ }
984
+ for (const auto &output : outputs) {
985
+ error::wrap_c_api(dnnl_graph_op_add_output(get(), &(output.data)),
986
+ "adding output to the op failed");
987
+ }
988
+ }
989
+
990
+ /// Adds an input logical tensor to the op.
991
+ ///
992
+ /// @param t Input logical tensor.
993
+ void add_input(const logical_tensor &t) {
994
+ error::wrap_c_api(dnnl_graph_op_add_input(get(), &(t.data)),
995
+ "adding input to the op failed");
996
+ }
997
+
998
+ /// Adds a vector of input logical tensors to the op.
999
+ ///
1000
+ /// @param ts The list of input logical tensors.
1001
+ void add_inputs(const std::vector<logical_tensor> &ts) {
1002
+ for (const auto &t : ts) {
1003
+ error::wrap_c_api(dnnl_graph_op_add_input(get(), &(t.data)),
1004
+ "adding input to the op failed");
1005
+ }
1006
+ }
1007
+
1008
+ /// Adds an output logical tensor to the op.
1009
+ ///
1010
+ /// @param t Output logical tensor.
1011
+ void add_output(const logical_tensor &t) {
1012
+ error::wrap_c_api(dnnl_graph_op_add_output(get(), &(t.data)),
1013
+ "adding output to the op failed");
1014
+ }
1015
+
1016
+ /// Adds a vector of output logical tensors to the op.
1017
+ ///
1018
+ /// @param ts The list of output logical tensors.
1019
+ void add_outputs(const std::vector<logical_tensor> &ts) {
1020
+ for (const auto &t : ts) {
1021
+ error::wrap_c_api(dnnl_graph_op_add_output(get(), &(t.data)),
1022
+ "adding output to the op failed");
1023
+ }
1024
+ }
1025
+
1026
+ /// Sets the attribute according to the name and type (int64_t).
1027
+ ///
1028
+ /// @tparam Type Attribute's type.
1029
+ /// @param name Attribute's name.
1030
+ /// @param value The attribute's value.
1031
+ /// @returns The Op self.
1032
+ template <typename Type, req<std::is_same<Type, int64_t>::value> = true>
1033
+ op &set_attr(attr name, const Type &value) {
1034
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1035
+ error::wrap_c_api(dnnl_graph_op_set_attr_s64(get(), attr, &value, 1),
1036
+ "could not set attribute to the op");
1037
+ return *this;
1038
+ }
1039
+
1040
+ /// Sets the attribute according to the name and type (float).
1041
+ ///
1042
+ /// @tparam Type Attribute's type.
1043
+ /// @param name Attribute's name.
1044
+ /// @param value The attribute's value.
1045
+ /// @returns The Op self.
1046
+ template <typename Type, req<std::is_same<Type, float>::value> = true>
1047
+ op &set_attr(attr name, const Type &value) {
1048
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1049
+ error::wrap_c_api(dnnl_graph_op_set_attr_f32(get(), attr, &value, 1),
1050
+ "could not set attribute to the op");
1051
+ return *this;
1052
+ }
1053
+
1054
+ /// Sets the attribute according to the name and type (bool).
1055
+ ///
1056
+ /// @tparam Type Attribute's type.
1057
+ /// @param name Attribute's name.
1058
+ /// @param value The attribute's value.
1059
+ /// @returns The Op self.
1060
+ template <typename Type, req<std::is_same<Type, bool>::value> = true>
1061
+ op &set_attr(attr name, const Type &value) {
1062
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1063
+ const uint8_t val = value;
1064
+ error::wrap_c_api(dnnl_graph_op_set_attr_bool(get(), attr, &val, 1),
1065
+ "could not set attribute to the op");
1066
+ return *this;
1067
+ }
1068
+
1069
+ /// Sets the attribute according to the name and type (string).
1070
+ ///
1071
+ /// @tparam Type Attribute's type.
1072
+ /// @param name Attribute's name.
1073
+ /// @param value The attribute's value.
1074
+ /// @returns The Op self.
1075
+ template <typename Type, req<std::is_same<Type, std::string>::value> = true>
1076
+ op &set_attr(attr name, const Type &value) {
1077
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1078
+ error::wrap_c_api(dnnl_graph_op_set_attr_str(
1079
+ get(), attr, value.c_str(), value.size()),
1080
+ "could not set attribute to the op");
1081
+ return *this;
1082
+ }
1083
+
1084
+ /// Sets the attribute according to the name and type
1085
+ /// (std::vector<int64_t>).
1086
+ ///
1087
+ /// @tparam Type Attribute's type.
1088
+ /// @param name Attribute's name.
1089
+ /// @param value The attribute's value.
1090
+ /// @returns The Op self.
1091
+ template <typename Type,
1092
+ req<std::is_same<Type, std::vector<int64_t>>::value> = true>
1093
+ op &set_attr(attr name, const Type &value) {
1094
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1095
+ error::wrap_c_api(dnnl_graph_op_set_attr_s64(
1096
+ get(), attr, value.data(), value.size()),
1097
+ "could not set attribute to the op");
1098
+ return *this;
1099
+ }
1100
+
1101
+ /// Sets the attribute according to the name and type (std::vector<float>).
1102
+ ///
1103
+ /// @tparam Type Attribute's type.
1104
+ /// @param name Attribute's name.
1105
+ /// @param value The attribute's value.
1106
+ /// @returns The Op self.
1107
+ template <typename Type,
1108
+ req<std::is_same<Type, std::vector<float>>::value> = true>
1109
+ op &set_attr(attr name, const Type &value) {
1110
+ dnnl_graph_op_attr_t attr = convert_to_c(name);
1111
+ error::wrap_c_api(dnnl_graph_op_set_attr_f32(
1112
+ get(), attr, value.data(), value.size()),
1113
+ "could not set attribute to the op");
1114
+ return *this;
1115
+ }
1116
+
1117
+ private:
1118
+ dnnl_graph_op_kind_t convert_to_c(kind akind) {
1119
+ return static_cast<dnnl_graph_op_kind_t>(akind);
1120
+ }
1121
+
1122
+ dnnl_graph_op_attr_t convert_to_c(attr aattr) {
1123
+ return static_cast<dnnl_graph_op_attr_t>(aattr);
1124
+ }
1125
+ };
1126
+
1127
+ /// @} dnnl_graph_api_op
1128
+
1129
+ /// @addtogroup dnnl_graph_api_partition Partition
1130
+ ///
1131
+ /// Partition represents a collection of operations and their input and output
1132
+ /// logical tensors identified by library as the basic unit for compilation and
1133
+ /// execution.
1134
+ ///
1135
+ /// @{
1136
+
1137
+ /// A partition object.
1138
+ class partition : public partition_handle {
1139
+ public:
1140
+ /// Policy specifications for partitioning.
1141
+ enum class policy {
1142
+ /// Fusion policy returns partitions with typical post-op fusions, eg.
1143
+ /// Convolution + ReLU or other element-wise operations or a chian of
1144
+ /// post-ops.
1145
+ fusion = dnnl_graph_partition_policy_fusion,
1146
+ /// Debug policy doesn't not apply any fusions. It returns partitions
1147
+ /// with single operations in each partition. The policy is useful when
1148
+ /// users notice any bug or correctness issue in fusion policy.
1149
+ debug = dnnl_graph_partition_policy_debug,
1150
+ };
1151
+
1152
+ partition() = default;
1153
+
1154
+ /// Constructs a partition object
1155
+ ///
1156
+ /// @param p A raw pointer to the C API handle
1157
+ partition(dnnl_graph_partition_t p) { reset(p, false); }
1158
+
1159
+ /// Creates a new partition with a given operator and engine kind. The API
1160
+ /// is used to create a partition from an operation directly without
1161
+ /// creating the graph and calling `get_partitions()`. The output partition
1162
+ /// contains only one operation.
1163
+ ///
1164
+ /// @param aop An operation used to create the partition.
1165
+ /// @param ekind Engine kind.
1166
+ partition(const op &aop, engine::kind ekind) {
1167
+ dnnl_graph_partition_t p = nullptr;
1168
+ error::wrap_c_api(dnnl_graph_partition_create_with_op(&p, aop.get(),
1169
+ static_cast<dnnl_engine_kind_t>(ekind)),
1170
+ "could not create a partition with the op and engine kind");
1171
+ reset(p);
1172
+ }
1173
+
1174
+ /// Returns the number of operations contained in the partition.
1175
+ ///
1176
+ /// @returns Number of operations.
1177
+ size_t get_ops_num() const {
1178
+ size_t num {0};
1179
+ error::wrap_c_api(dnnl_graph_partition_get_op_num(get(), &num),
1180
+ "could not get number of ops from the partition");
1181
+ return num;
1182
+ }
1183
+
1184
+ /// Returns all operation IDs contained in the partition.
1185
+ ///
1186
+ /// @returns An unordered set of operation IDs.
1187
+ std::vector<size_t> get_ops() const {
1188
+ auto num = get_ops_num();
1189
+ std::vector<size_t> ops(num);
1190
+
1191
+ error::wrap_c_api(dnnl_graph_partition_get_ops(get(), num, ops.data()),
1192
+ "could not get op ids from the partition");
1193
+ return ops;
1194
+ }
1195
+
1196
+ /// Returns the unique ID of the partition. Partition ID is generated by the
1197
+ /// library internally. The ID can be used for debugging purpose or verbose.
1198
+ ///
1199
+ /// @returns ID of the partition.
1200
+ size_t get_id() const {
1201
+ size_t id {};
1202
+ error::wrap_c_api(dnnl_graph_partition_get_id(get(), &id),
1203
+ "could not get id of the partition");
1204
+ return id;
1205
+ }
1206
+
1207
+ /// Compiles a partition with given input and output logical tensors. The
1208
+ /// output logical tensors can contain unknown dimensions. For this case,
1209
+ /// the compilation will deduce the output shapes according to input shapes.
1210
+ /// The output logical tensors can also have layout type `any`. The
1211
+ /// compilation will choose the optimal layout for output tensors. The
1212
+ /// optimal layout will be represented as an opaque layout ID saved in the
1213
+ /// output logical tensor.
1214
+ ///
1215
+ /// @param inputs A list of input logical tensors.
1216
+ /// @param outputs A list of output logical tensors.
1217
+ /// @param e The engine used to compile the partition.
1218
+ /// @returns A compiled partition.
1219
+ compiled_partition compile(const std::vector<logical_tensor> &inputs,
1220
+ const std::vector<logical_tensor> &outputs, const engine &e) const {
1221
+ if (!is_supported()) {
1222
+ error::wrap_c_api(dnnl_invalid_arguments,
1223
+ "could not compile an unsupported partition");
1224
+ }
1225
+
1226
+ return compile_(inputs, outputs, e);
1227
+ }
1228
+
1229
+ /// Returns the supporting status of a partition. Some operations may not be
1230
+ /// supported by the library under certain circumstances. During
1231
+ /// partitioning stage, unsupported partitions will be returned to users
1232
+ /// with each containing an unsupported operation. Users should check the
1233
+ /// supporting status of a partition before transforming the computation
1234
+ /// graph or compiling the partition.
1235
+ ///
1236
+ /// @returns @c true if this partition is supported or @c false if this
1237
+ /// partition isn't supported by the library
1238
+ bool is_supported() const {
1239
+ uint8_t supported {0};
1240
+ error::wrap_c_api(dnnl_graph_partition_is_supported(get(), &supported),
1241
+ "could not get supporting status of the partition");
1242
+ return supported != 0;
1243
+ }
1244
+
1245
+ /// Returns a list of input logical tensors from the partition.
1246
+ ///
1247
+ /// @returns A list of input logical tensors.
1248
+ std::vector<logical_tensor> get_input_ports() const {
1249
+ size_t num = 0;
1250
+ error::wrap_c_api(dnnl_graph_partition_get_input_ports_num(get(), &num),
1251
+ "could not get number of inputs of the partition");
1252
+ if (num == 0) return {};
1253
+
1254
+ std::vector<dnnl_graph_logical_tensor_t> c_inputs(num);
1255
+ error::wrap_c_api(dnnl_graph_partition_get_input_ports(
1256
+ get(), num, c_inputs.data()),
1257
+ "could not get input logical tensors of the partition");
1258
+
1259
+ std::vector<logical_tensor> inputs;
1260
+ inputs.reserve(num);
1261
+ for (auto &c_lt : c_inputs)
1262
+ inputs.emplace_back(c_lt);
1263
+ return inputs;
1264
+ }
1265
+
1266
+ /// Returns a list of output logical tensors from the partition.
1267
+ ///
1268
+ /// @returns A list of output logical tensor.
1269
+ std::vector<logical_tensor> get_output_ports() const {
1270
+ size_t num = 0;
1271
+ error::wrap_c_api(
1272
+ dnnl_graph_partition_get_output_ports_num(get(), &num),
1273
+ "cannot get number of outputs of the partition");
1274
+ if (num == 0) return {};
1275
+
1276
+ std::vector<dnnl_graph_logical_tensor_t> c_outputs(num);
1277
+ error::wrap_c_api(dnnl_graph_partition_get_output_ports(
1278
+ get(), num, c_outputs.data()),
1279
+ "could not get output logical tensors of the partition");
1280
+
1281
+ std::vector<logical_tensor> outputs;
1282
+ outputs.reserve(num);
1283
+ for (auto &c_lt : c_outputs)
1284
+ outputs.emplace_back(c_lt);
1285
+ return outputs;
1286
+ }
1287
+
1288
+ /// Returns the engine kind of the partition
1289
+ ///
1290
+ /// @returns The engine kind
1291
+ engine::kind get_engine_kind() const {
1292
+ dnnl_engine_kind_t akind;
1293
+ error::wrap_c_api(dnnl_graph_partition_get_engine_kind(get(), &akind),
1294
+ "cannot get the engine kind from the partition");
1295
+
1296
+ return static_cast<engine::kind>(akind);
1297
+ }
1298
+
1299
+ private:
1300
+ compiled_partition compile_(const std::vector<logical_tensor> &inputs,
1301
+ const std::vector<logical_tensor> &outputs, const engine &e) const {
1302
+ std::vector<const dnnl_graph_logical_tensor_t *> c_inputs;
1303
+ std::vector<const dnnl_graph_logical_tensor_t *> c_outputs;
1304
+
1305
+ c_inputs.reserve(inputs.size());
1306
+ for (const auto &in : inputs) {
1307
+ c_inputs.push_back(&(in.data));
1308
+ }
1309
+
1310
+ c_outputs.reserve(outputs.size());
1311
+ for (const auto &out : outputs) {
1312
+ c_outputs.push_back(&(out.data));
1313
+ }
1314
+
1315
+ dnnl_graph_compiled_partition_t cpartitions = nullptr;
1316
+ error::wrap_c_api(
1317
+ dnnl_graph_compiled_partition_create(&cpartitions, get()),
1318
+ "could not create compiled_partition");
1319
+ error::wrap_c_api(dnnl_graph_partition_compile(get(), cpartitions,
1320
+ c_inputs.size(), c_inputs.data(),
1321
+ c_outputs.size(), c_outputs.data(), e.get()),
1322
+ "partition compile failed");
1323
+
1324
+ return compiled_partition(cpartitions);
1325
+ }
1326
+ };
1327
+
1328
+ /// @} dnnl_graph_api_partition
1329
+
1330
+ /// @addtogroup dnnl_graph_api_graph Graph
1331
+ ///
1332
+ /// Graph represents a computational DAG with a set of operations.
1333
+ /// #dnnl::graph::graph::add_op() adds an operation and its input and output
1334
+ /// logical tensors into a graph. The library accumulates the operations and
1335
+ /// logical tensors and constructs and validates the graph as an internal state.
1336
+ /// A graph object is associated to a specific engine kind. The partitions
1337
+ /// returned from the graph will inherit the engine kind of the graph.
1338
+ ///
1339
+ /// @{
1340
+
1341
+ /// A graph object.
1342
+ class graph : public graph_handle {
1343
+ public:
1344
+ /// Constructs a graph with an engine kind.
1345
+ ///
1346
+ /// @param engine_kind Engine kind.
1347
+ graph(engine::kind engine_kind) {
1348
+ dnnl_graph_graph_t g = nullptr;
1349
+ error::wrap_c_api(
1350
+ dnnl_graph_graph_create(&g, convert_to_c(engine_kind)),
1351
+ "could not create graph with engine kind");
1352
+ reset(g);
1353
+ }
1354
+
1355
+ /// Creates a new empty graph with an engine kind and a floating-point math
1356
+ /// mode. All partitions returned from the graph will inherit the engine
1357
+ /// kind and floating-point math mode.
1358
+ ///
1359
+ /// @param engine_kind Engine kind.
1360
+ /// @param mode Floating-point math mode.
1361
+ graph(engine::kind engine_kind, fpmath_mode mode) {
1362
+ dnnl_graph_graph_t g = nullptr;
1363
+ error::wrap_c_api(
1364
+ dnnl_graph_graph_create_with_fpmath_mode(
1365
+ &g, convert_to_c(engine_kind), convert_to_c(mode)),
1366
+ "could not create graph with engine kind and math mode");
1367
+ reset(g);
1368
+ }
1369
+
1370
+ /// Adds an op into the graph to construct a computational DAG. The API will
1371
+ /// return failure if the operator has already been added to the graph or
1372
+ /// the operation cannot pass the schema check in the library (eg. input and
1373
+ /// output numbers and data types, the attributes of the operation, etc.).
1374
+ ///
1375
+ /// @param op An operation to be added.
1376
+ /// @param allow_exception A flag indicating whether the method is allowed
1377
+ /// to throw an exception if it fails to add the op to the graph.
1378
+ /// @returns #status::success or a status describing the error otherwise.
1379
+ status add_op(const op &op, bool allow_exception = true) {
1380
+ dnnl_status_t ret = dnnl_graph_add_op(get(), op.get());
1381
+
1382
+ if (allow_exception) {
1383
+ error::wrap_c_api(ret, "could not add op to the graph");
1384
+ }
1385
+
1386
+ return static_cast<status>(ret);
1387
+ }
1388
+
1389
+ /// Finalizes a graph. It means users have finished adding operations into
1390
+ /// the graph and the graph is ready for partitioning. Adding a new
1391
+ /// operation into a finalized graph will return failures. Similarly,
1392
+ /// partitioning on a un-finalized graph will also return failures.
1393
+ void finalize() {
1394
+ error::wrap_c_api(dnnl_graph_graph_finalize(get()),
1395
+ "could not finalize the graph");
1396
+ }
1397
+
1398
+ /// Checks if a graph is finalized.
1399
+ ///
1400
+ /// @return True if the graph is finalized or false if the graph is not
1401
+ /// finalized.
1402
+ bool is_finalized() const {
1403
+ uint8_t ret = 0;
1404
+ error::wrap_c_api(dnnl_graph_graph_is_finalized(get(), &ret),
1405
+ "could not get the finalization status of the graph");
1406
+
1407
+ return ret != 0;
1408
+ }
1409
+
1410
+ /// Gets filtered partitions from a graph. Partitions will be claimed
1411
+ /// internally according to the capability of the library, the engine kind
1412
+ /// of the graph, and the policy.
1413
+ ///
1414
+ /// @param policy Partition policy, defaults to policy
1415
+ /// #dnnl::graph::partition::policy::fusion.
1416
+ /// @return A vector storing the partitions.
1417
+ std::vector<partition> get_partitions(
1418
+ partition::policy policy = partition::policy::fusion) {
1419
+ if (!is_finalized()) {
1420
+ error::wrap_c_api(
1421
+ dnnl_invalid_graph, "the graph is not finalized yet");
1422
+ }
1423
+
1424
+ error::wrap_c_api(
1425
+ dnnl_graph_graph_filter(get(),
1426
+ static_cast<dnnl_graph_partition_policy_t>(policy)),
1427
+ "could not filter the graph");
1428
+
1429
+ size_t num = 0;
1430
+ error::wrap_c_api(dnnl_graph_graph_get_partition_num(get(), &num),
1431
+ "could not get number of partitions from the graph");
1432
+
1433
+ // return early if there is no partitions in the graph.
1434
+ if (num == 0) return {};
1435
+
1436
+ std::vector<partition> out_list;
1437
+ out_list.reserve(num);
1438
+
1439
+ std::vector<dnnl_graph_partition_t> partitions(num);
1440
+ error::wrap_c_api(
1441
+ dnnl_graph_graph_get_partitions(get(), num, partitions.data()),
1442
+ "could not get partitions from the graph");
1443
+
1444
+ for (auto p : partitions) {
1445
+ out_list.emplace_back(p);
1446
+ }
1447
+
1448
+ return out_list;
1449
+ }
1450
+
1451
+ private:
1452
+ static dnnl_fpmath_mode_t convert_to_c(fpmath_mode mode) {
1453
+ return static_cast<dnnl_fpmath_mode_t>(mode);
1454
+ }
1455
+
1456
+ static dnnl_engine_kind_t convert_to_c(engine::kind akind) {
1457
+ return static_cast<dnnl_engine_kind_t>(akind);
1458
+ }
1459
+ };
1460
+
1461
+ /// @} dnnl_graph_api_graph
1462
+
1463
+ /// @addtogroup dnnl_graph_api_compiled_partition_cache Compiled Partition Cache
1464
+ ///
1465
+ /// A set of functions that provide compiled partition cache control.
1466
+ ///
1467
+ /// @{
1468
+
1469
+ /// Returns the number of compiled partition that can be held in the compiled
1470
+ /// partition cache at the same time.
1471
+ inline int get_compiled_partition_cache_capacity() {
1472
+ int result = 0;
1473
+ error::wrap_c_api(dnnl_graph_get_compiled_partition_cache_capacity(&result),
1474
+ "could not get compiled partition cache capacity");
1475
+ return result;
1476
+ }
1477
+
1478
+ /// @copydoc dnnl_graph_set_compiled_partition_cache_capacity(int capacity)
1479
+ inline void set_compiled_partition_cache_capacity(int capacity) {
1480
+ error::wrap_c_api(
1481
+ dnnl_graph_set_compiled_partition_cache_capacity(capacity),
1482
+ "could not set compiled partition cache capacity");
1483
+ }
1484
+
1485
+ /// @} dnnl_graph_api_compiled_partition_cache
1486
+
1487
+ /// @addtogroup dnnl_graph_api_constant_tensor_cache Constant Tensor Cache
1488
+ ///
1489
+ /// A set of functions that provide constant tensor cache control
1490
+ ///
1491
+ /// @{
1492
+
1493
+ /// Control the enabling or disabling of constant tensor cache. This API must be
1494
+ /// called once before compilation stage. By default, constant tensor cache is
1495
+ /// disabled in the library.
1496
+ /// @note This API is deprecated and will be removed in future release, please
1497
+ /// use the set_constant_tensor_cache_capacity API to disable
1498
+ /// constant tensor cache by setting it's capacity to zero.
1499
+ ///
1500
+ /// @param flag Set to positive value to enable the cache and set to 0 to
1501
+ /// disable the cache. Negative values are invalid.
1502
+ inline void set_constant_tensor_cache(int flag) {
1503
+ error::wrap_c_api(dnnl_graph_set_constant_tensor_cache(flag),
1504
+ "fail to set constant tensor cache");
1505
+ }
1506
+
1507
+ /// Return the enabling status of constant tensor cache.
1508
+ /// @note This API is deprecated and will be removed in future release, please
1509
+ /// use the get_constant_tensor_cache_capacity API to check the
1510
+ /// enabling status by checking it's capacity.
1511
+ inline int get_constant_tensor_cache() {
1512
+ int result = 0;
1513
+ error::wrap_c_api(dnnl_graph_get_constant_tensor_cache(&result),
1514
+ "fail to get constant tensor cache");
1515
+ return result;
1516
+ }
1517
+
1518
+ /// Control the capacity for the constant tensor cache that used for specific
1519
+ /// engine kind. This API is thread safe and can be called multiple times at
1520
+ /// runtime. The capacity is set to zero by default which means the cache is
1521
+ /// disabled. When calling this API, the corresponding cache will be flushed.
1522
+ /// Setting capacity to 0 means to clear all cached tensors and disable cache.
1523
+ /// Once the capacity limit is reached, no new tensors will be cached. If there
1524
+ /// are multiple devices for an engine kind, the capacity set here is for each
1525
+ /// device.
1526
+ ///
1527
+ /// @param kind The engine kind that the constant tensor cache used for.
1528
+ /// @param size The constant tensor cache capacity size to set.
1529
+ inline void set_constant_tensor_cache_capacity(engine::kind kind, size_t size) {
1530
+ error::wrap_c_api(dnnl_graph_set_constant_tensor_cache_capacity(
1531
+ static_cast<dnnl_engine_kind_t>(kind), size),
1532
+ "fail to set constant tensor cache capacity");
1533
+ }
1534
+
1535
+ /// Return the current capacity of constant tensor cache.
1536
+ ///
1537
+ /// @param kind The engine kind that the constant tensor cache used for.
1538
+ inline size_t get_constant_tensor_cache_capacity(engine::kind kind) {
1539
+ size_t size = 0;
1540
+ error::wrap_c_api(dnnl_graph_get_constant_tensor_cache_capacity(
1541
+ static_cast<dnnl_engine_kind_t>(kind), &size),
1542
+ "fail to get constant tensor cache capacity");
1543
+ return size;
1544
+ }
1545
+
1546
+ /// @} dnnl_graph_constant_tensor_cache
1547
+
1548
+ } // namespace graph
1549
+ } // namespace dnnl
1550
+
1551
+ /// @cond DO_NOT_DOCUMENT_THIS
1552
+
1553
+ /// oneAPI namespace
1554
+ // Contains the oneapi::dnnl namespace as an alias to the ::dnnl namespace.
1555
+ namespace oneapi {
1556
+ // Note: without this guard, doxygen warns of potentially recursive namespace
1557
+ #ifndef DOXYGEN_SHOULD_SKIP_THIS
1558
+ /// oneDNN alias namespace
1559
+ namespace dnnl = ::dnnl;
1560
+ #endif
1561
+ } // namespace oneapi
1562
+
1563
+ /// @endcond
1564
+
1565
+ /// @} dnnl_graph_api
1566
+
1567
+ /// @} dnnl_api
1568
+
1569
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_ocl.h ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_OCL_H
18
+ #define ONEAPI_DNNL_DNNL_GRAPH_OCL_H
19
+
20
+ #include "oneapi/dnnl/dnnl_graph.h"
21
+
22
+ /// @cond DO_NOT_DOCUMENT_THIS
23
+ // Set target version for OpenCL explicitly to suppress a compiler warning.
24
+ #ifndef CL_TARGET_OPENCL_VERSION
25
+ #define CL_TARGET_OPENCL_VERSION 120
26
+ #endif
27
+
28
+ #include <CL/cl.h>
29
+ /// @endcond
30
+
31
+ #ifdef __cplusplus
32
+ extern "C" {
33
+ #endif
34
+
35
+ /// @addtogroup dnnl_graph_api
36
+ /// @{
37
+
38
+ /// @addtogroup dnnl_graph_api_interop
39
+ /// @{
40
+
41
+ /// @addtogroup dnnl_graph_api_ocl_interop
42
+ /// @{
43
+
44
+ /// Allocation call-back function interface for OpenCL. OpenCL allocator should
45
+ /// be used for OpenCL GPU runtime. The call-back should return a USM device
46
+ /// memory pointer.
47
+ ///
48
+ /// @param size Memory size in bytes for requested allocation
49
+ /// @param alignment The minimum alignment in bytes for the requested allocation
50
+ /// @param device A valid OpenCL device used to allocate
51
+ /// @param context A valid OpenCL context used to allocate
52
+ /// @returns The memory address of the requested USM allocation.
53
+ typedef void *(*dnnl_graph_ocl_allocate_f)(
54
+ size_t size, size_t alignment, cl_device_id device, cl_context context);
55
+
56
+ /// Deallocation call-back function interface for OpenCL. OpenCL allocator
57
+ /// should be used for OpenCL runtime. The call-back should deallocate a USM
58
+ /// device memory returned by #dnnl_graph_ocl_allocate_f. The event should be
59
+ /// completed before deallocate the USM.
60
+ ///
61
+ /// @param buf The USM allocation to be released
62
+ /// @param device A valid OpenCL device the USM associated with
63
+ /// @param context A valid OpenCL context used to free the USM allocation
64
+ /// @param event A event which the USM deallocation depends on
65
+ typedef void (*dnnl_graph_ocl_deallocate_f)(
66
+ void *buf, cl_device_id device, cl_context context, cl_event event);
67
+
68
+ /// Creates an allocator with the given allocation and deallocation call-back
69
+ /// function pointers.
70
+ ///
71
+ /// @param allocator Output allocator
72
+ /// @param ocl_malloc A pointer to OpenCL malloc function
73
+ /// @param ocl_free A pointer to OpenCL free function
74
+ /// @returns #dnnl_success on success and a status describing the
75
+ /// error otherwise.
76
+ dnnl_status_t DNNL_API dnnl_graph_ocl_interop_allocator_create(
77
+ dnnl_graph_allocator_t *allocator, dnnl_graph_ocl_allocate_f ocl_malloc,
78
+ dnnl_graph_ocl_deallocate_f ocl_free);
79
+
80
+ /// This API is a supplement for existing oneDNN engine API:
81
+ /// dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create(
82
+ /// dnnl_engine_t *engine, cl_device_id device, cl_context context);
83
+ ///
84
+ /// @param engine Output engine.
85
+ /// @param device Underlying OpenCL device to use for the engine.
86
+ /// @param context Underlying OpenCL context to use for the engine.
87
+ /// @param alloc Underlying allocator to use for the engine.
88
+ /// @returns #dnnl_success on success and a status describing the error
89
+ /// otherwise.
90
+ dnnl_status_t DNNL_API dnnl_graph_ocl_interop_make_engine_with_allocator(
91
+ dnnl_engine_t *engine, cl_device_id device, cl_context context,
92
+ const_dnnl_graph_allocator_t alloc);
93
+
94
+ /// This API is a supplement for existing oneDNN engine API:
95
+ /// dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create_from_cache_blob(
96
+ /// dnnl_engine_t *engine, cl_device_id device, cl_context context,
97
+ /// size_t size, const uint8_t *cache_blob);
98
+ ///
99
+ /// @param engine Output engine.
100
+ /// @param device The OpenCL device that this engine will encapsulate.
101
+ /// @param context The OpenCL context (containing the device) that this
102
+ /// engine will use for all operations.
103
+ /// @param alloc Underlying allocator to use for the engine.
104
+ /// @param size Size of the cache blob in bytes.
105
+ /// @param cache_blob Cache blob of size @p size.
106
+ /// @returns #dnnl_success on success and a status describing the error
107
+ /// otherwise.
108
+ dnnl_status_t DNNL_API
109
+ dnnl_graph_ocl_interop_make_engine_from_cache_blob_with_allocator(
110
+ dnnl_engine_t *engine, cl_device_id device, cl_context context,
111
+ const_dnnl_graph_allocator_t alloc, size_t size,
112
+ const uint8_t *cache_blob);
113
+
114
+ /// Execute a compiled partition with OpenCL runtime.
115
+ ///
116
+ /// @param compiled_partition The handle of target compiled_partition.
117
+ /// @param stream The stream used for execution
118
+ /// @param num_inputs The number of input tensors
119
+ /// @param inputs A list of input tensors
120
+ /// @param num_outputs The number of output tensors
121
+ /// @param outputs A non-empty list of output tensors
122
+ /// @param deps Optional handle of list with `cl_event` dependencies.
123
+ /// @param ndeps Number of dependencies.
124
+ /// @param return_event The handle of cl_event.
125
+ /// @returns #dnnl_success on success and a status describing the
126
+ /// error otherwise.
127
+ dnnl_status_t DNNL_API dnnl_graph_ocl_interop_compiled_partition_execute(
128
+ const_dnnl_graph_compiled_partition_t compiled_partition,
129
+ dnnl_stream_t stream, size_t num_inputs,
130
+ const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
131
+ const_dnnl_graph_tensor_t *outputs, const cl_event *deps, int ndeps,
132
+ cl_event *return_event);
133
+
134
+ /// @} dnnl_graph_api_ocl_interop
135
+
136
+ /// @} dnnl_graph_api_interop
137
+
138
+ /// @} dnnl_graph_api
139
+
140
+ #ifdef __cplusplus
141
+ }
142
+ #endif
143
+
144
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_ocl.hpp ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_OCL_HPP
18
+ #define ONEAPI_DNNL_DNNL_GRAPH_OCL_HPP
19
+
20
+ /// @cond DO_NOT_DOCUMENT_THIS
21
+ #include <vector>
22
+
23
+ #include <CL/cl.h>
24
+
25
+ #include "oneapi/dnnl/dnnl_graph.hpp"
26
+ #include "oneapi/dnnl/dnnl_graph_ocl.h"
27
+ #include "oneapi/dnnl/dnnl_ocl.hpp"
28
+ /// @endcond
29
+
30
+ /// @addtogroup dnnl_graph_api
31
+ /// @{
32
+
33
+ namespace dnnl {
34
+ namespace graph {
35
+
36
+ /// @addtogroup dnnl_graph_api_interop Runtime interoperability API
37
+ /// API extensions to interact with the underlying run-time.
38
+ /// @{
39
+
40
+ /// @addtogroup dnnl_graph_api_ocl_interop OpenCL interoperability API API
41
+ /// extensions to interact with the underlying OpenCL run-time.
42
+ ///
43
+ /// @{
44
+
45
+ /// OpenCL interoperability namespace
46
+ namespace ocl_interop {
47
+
48
+ /// Constructs an allocator from OpenCL malloc and free function pointer. OpenCL
49
+ /// allocator should be used for OpenCL GPU runtime. Currently, only device USM
50
+ /// allocator is supported.
51
+ ///
52
+ /// @param ocl_malloc The pointer to OpenCL malloc function
53
+ /// @param ocl_free The pointer to OpenCL free function
54
+ /// @returns Created allocator
55
+ inline allocator make_allocator(dnnl_graph_ocl_allocate_f ocl_malloc,
56
+ dnnl_graph_ocl_deallocate_f ocl_free) {
57
+ dnnl_graph_allocator_t c_allocator = nullptr;
58
+ error::wrap_c_api(dnnl_graph_ocl_interop_allocator_create(
59
+ &c_allocator, ocl_malloc, ocl_free),
60
+ "could not create allocator for opencl device");
61
+ return allocator(c_allocator);
62
+ }
63
+
64
+ /// Constructs an engine from an OpenCL device, an OpenCL context, and an
65
+ /// allocator.
66
+ ///
67
+ /// @param device A valid OpenCL device to construct the engine
68
+ /// @param context A valid OpenCL context to construct the engine
69
+ /// @param alloc An allocator to associate with the engine
70
+ /// @returns Created engine
71
+ inline engine make_engine_with_allocator(
72
+ cl_device_id device, cl_context context, const allocator &alloc) {
73
+ dnnl_engine_t c_engine;
74
+ error::wrap_c_api(dnnl_graph_ocl_interop_make_engine_with_allocator(
75
+ &c_engine, device, context, alloc.get()),
76
+ "could not make an engine with allocator");
77
+ return engine(c_engine);
78
+ }
79
+
80
+ /// Constructs an engine from an OpenCL device, an OpenCL context, an
81
+ /// allocator, and a serialized engine cache blob.
82
+ ///
83
+ /// @param device A valid OpenCL device to construct the engine
84
+ /// @param context A valid OpenCL context to construct the engine
85
+ /// @param alloc An allocator to associate with the engine
86
+ /// @param cache_blob Cache blob serialized beforehand
87
+ /// @returns Created engine
88
+ inline engine make_engine_with_allocator(cl_device_id device,
89
+ cl_context context, const allocator &alloc,
90
+ const std::vector<uint8_t> &cache_blob) {
91
+ dnnl_engine_t c_engine;
92
+ error::wrap_c_api(
93
+ dnnl_graph_ocl_interop_make_engine_from_cache_blob_with_allocator(
94
+ &c_engine, device, context, alloc.get(), cache_blob.size(),
95
+ cache_blob.data()),
96
+ "could not make an engine with allocator from cache blob");
97
+ return engine(c_engine);
98
+ }
99
+
100
+ /// Executes a compiled partition in a specified stream and returns a OpenCL
101
+ /// event.
102
+ ///
103
+ /// @param c_partition Compiled partition to execute.
104
+ /// @param astream Stream object to run over
105
+ /// @param inputs Arguments map.
106
+ /// @param outputs Arguments map.
107
+ /// @param deps Optional vector with `cl_event` dependencies.
108
+ /// @returns Output event.
109
+ inline cl_event execute(compiled_partition &c_partition, stream &astream,
110
+ const std::vector<tensor> &inputs, std::vector<tensor> &outputs,
111
+ const std::vector<cl_event> &deps = {}) {
112
+ std::vector<const_dnnl_graph_tensor_t> c_inputs;
113
+ c_inputs.reserve(inputs.size());
114
+ for (auto &in : inputs) {
115
+ c_inputs.push_back(in.get());
116
+ }
117
+ std::vector<const_dnnl_graph_tensor_t> c_outputs;
118
+ c_outputs.reserve(outputs.size());
119
+ for (auto &out : outputs) {
120
+ c_outputs.push_back(out.get());
121
+ }
122
+
123
+ const cl_event *c_deps = deps.empty() ? nullptr : deps.data();
124
+
125
+ cl_event ocl_event;
126
+ error::wrap_c_api(
127
+ dnnl_graph_ocl_interop_compiled_partition_execute(c_partition.get(),
128
+ astream.get(), c_inputs.size(), c_inputs.data(),
129
+ c_outputs.size(), c_outputs.data(), c_deps,
130
+ (int)deps.size(), &ocl_event),
131
+ "could not execute the compiled_partition on a specified opencl "
132
+ "stream");
133
+ return ocl_event;
134
+ }
135
+
136
+ } // namespace ocl_interop
137
+
138
+ /// @} dnnl_graph_api_ocl_interop
139
+
140
+ /// @} dnnl_graph_api_interop
141
+
142
+ } // namespace graph
143
+ } // namespace dnnl
144
+
145
+ /// @} dnnl_graph_api
146
+
147
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_sycl.h ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2022 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_SYCL_H
18
+ #define ONEAPI_DNNL_DNNL_GRAPH_SYCL_H
19
+
20
+ #include "oneapi/dnnl/dnnl_graph.h"
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ /// @addtogroup dnnl_graph_api
27
+ /// @{
28
+
29
+ /// @addtogroup dnnl_graph_api_interop
30
+ /// @{
31
+
32
+ /// @addtogroup dnnl_graph_api_sycl_interop
33
+ /// @{
34
+
35
+ /// Allocation call-back function interface for SYCL. SYCL allocator should be
36
+ /// used for SYCL runtime and host allocator should be used for non-SYCL. The
37
+ /// call-back should return a USM device memory pointer.
38
+ typedef void *(*dnnl_graph_sycl_allocate_f)(
39
+ size_t size, size_t alignment, const void *dev, const void *context);
40
+
41
+ /// Deallocation call-back function interface for SYCL. SYCL allocator should be
42
+ /// used for SYCL runtime and host allocator should be used for non-SYCL. The
43
+ /// call-back should deallocate a USM device memory returned by
44
+ /// #dnnl_graph_sycl_allocate_f.
45
+ typedef void (*dnnl_graph_sycl_deallocate_f)(
46
+ void *buf, const void *dev, const void *context, void *event);
47
+
48
+ /// Creates an allocator with the given allocation and deallocation call-back
49
+ /// function pointers.
50
+ ///
51
+ /// @param allocator Output allocator
52
+ /// @param sycl_malloc A pointer to SYCL malloc function
53
+ /// @param sycl_free A pointer to SYCL free function
54
+ /// @returns #dnnl_success on success and a status describing the
55
+ /// error otherwise.
56
+ dnnl_status_t DNNL_API dnnl_graph_sycl_interop_allocator_create(
57
+ dnnl_graph_allocator_t *allocator,
58
+ dnnl_graph_sycl_allocate_f sycl_malloc,
59
+ dnnl_graph_sycl_deallocate_f sycl_free);
60
+
61
+ /// This API is a supplement for existing onednn engine API.
62
+ dnnl_status_t DNNL_API dnnl_graph_sycl_interop_make_engine_with_allocator(
63
+ dnnl_engine_t *engine, const void *device, const void *context,
64
+ const_dnnl_graph_allocator_t alloc);
65
+
66
+ /// Execute a compiled partition with sycl runtime.
67
+ ///
68
+ /// @param compiled_partition The handle of target compiled_partition.
69
+ /// @param stream The stream used for execution
70
+ /// @param num_inputs The number of input tensors
71
+ /// @param inputs A list of input tensors
72
+ /// @param num_outputs The number of output tensors
73
+ /// @param outputs A non-empty list of output tensors
74
+ /// @param deps Optional handle of list with `sycl::event` dependencies.
75
+ /// @param sycl_event The handle of sycl event.
76
+ /// @returns #dnnl_success on success and a status describing the
77
+ /// error otherwise.
78
+ dnnl_status_t DNNL_API dnnl_graph_sycl_interop_compiled_partition_execute(
79
+ const_dnnl_graph_compiled_partition_t compiled_partition,
80
+ dnnl_stream_t stream, size_t num_inputs,
81
+ const_dnnl_graph_tensor_t *inputs, size_t num_outputs,
82
+ const_dnnl_graph_tensor_t *outputs, const void *deps, void *sycl_event);
83
+
84
+ /// @} dnnl_graph_api_sycl_interop
85
+
86
+ /// @} dnnl_graph_api_interop
87
+
88
+ /// @} dnnl_graph_api
89
+
90
+ #ifdef __cplusplus
91
+ }
92
+ #endif
93
+
94
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_sycl.hpp ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2022 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_SYCL_HPP
18
+ #define ONEAPI_DNNL_DNNL_GRAPH_SYCL_HPP
19
+
20
+ /// @cond DO_NOT_DOCUMENT_THIS
21
+ #include <vector>
22
+
23
+ #if __has_include(<sycl/sycl.hpp>)
24
+ #include <sycl/sycl.hpp>
25
+ #elif __has_include(<CL/sycl.hpp>)
26
+ #include <CL/sycl.hpp>
27
+ #else
28
+ #error "Unsupported compiler"
29
+ #endif
30
+
31
+ #include "oneapi/dnnl/dnnl_graph.hpp"
32
+ #include "oneapi/dnnl/dnnl_graph_sycl.h"
33
+ /// @endcond
34
+
35
+ /// @addtogroup dnnl_graph_api
36
+ /// @{
37
+
38
+ namespace dnnl {
39
+ namespace graph {
40
+
41
+ /// @addtogroup dnnl_graph_api_interop Runtime interoperability API
42
+ /// API extensions to interact with the underlying run-time.
43
+ /// @{
44
+
45
+ /// @addtogroup dnnl_graph_api_sycl_interop SYCL interoperability API
46
+ /// API extensions to interact with the underlying SYCL run-time.
47
+ ///
48
+ /// @{
49
+
50
+ /// SYCL interoperability namespace
51
+ namespace sycl_interop {
52
+
53
+ /// Constructs an allocator from SYCL malloc and free function pointer. SYCL
54
+ /// allocator should be used for SYCL runtime and host allocator should be used
55
+ /// for non-SYCL. Currently, only device USM allocator is supported.
56
+ ///
57
+ /// @param sycl_malloc The pointer to SYCL malloc function
58
+ /// @param sycl_free The pointer to SYCL free function
59
+ /// @returns Created allocator
60
+ inline allocator make_allocator(dnnl_graph_sycl_allocate_f sycl_malloc,
61
+ dnnl_graph_sycl_deallocate_f sycl_free) {
62
+ dnnl_graph_allocator_t c_allocator = nullptr;
63
+ error::wrap_c_api(dnnl_graph_sycl_interop_allocator_create(
64
+ &c_allocator, sycl_malloc, sycl_free),
65
+ "could not create allocator for sycl device");
66
+ return allocator(c_allocator);
67
+ }
68
+
69
+ inline engine make_engine_with_allocator(const sycl::device &adevice,
70
+ const sycl::context &acontext, const allocator &alloc) {
71
+ dnnl_engine_t c_engine;
72
+ error::wrap_c_api(
73
+ dnnl_graph_sycl_interop_make_engine_with_allocator(&c_engine,
74
+ static_cast<const void *>(&adevice),
75
+ static_cast<const void *>(&acontext), alloc.get()),
76
+ "could not make an engine with allocator");
77
+ return engine(c_engine);
78
+ }
79
+
80
+ /// Executes a compiled partition in a specified stream and returns a SYCL
81
+ /// event.
82
+ ///
83
+ /// @param c_partition Compiled partition to execute.
84
+ /// @param astream Stream object to run over
85
+ /// @param inputs Arguments map.
86
+ /// @param outputs Arguments map.
87
+ /// @param deps Optional vector with `sycl::event` dependencies.
88
+ /// @returns Output event.
89
+ inline sycl::event execute(compiled_partition &c_partition, stream &astream,
90
+ const std::vector<tensor> &inputs, std::vector<tensor> &outputs,
91
+ const std::vector<sycl::event> &deps = {}) {
92
+ std::vector<const_dnnl_graph_tensor_t> c_inputs;
93
+ c_inputs.reserve(inputs.size());
94
+ for (auto &in : inputs) {
95
+ c_inputs.push_back(in.get());
96
+ }
97
+ std::vector<const_dnnl_graph_tensor_t> c_outputs;
98
+ c_outputs.reserve(outputs.size());
99
+ for (auto &out : outputs) {
100
+ c_outputs.push_back(out.get());
101
+ }
102
+
103
+ sycl::event sycl_event;
104
+ error::wrap_c_api(dnnl_graph_sycl_interop_compiled_partition_execute(
105
+ c_partition.get(), astream.get(), c_inputs.size(),
106
+ c_inputs.data(), c_outputs.size(),
107
+ c_outputs.data(), &deps, &sycl_event),
108
+ "could not execute the compiled_partition on a specified sycl "
109
+ "stream");
110
+ return sycl_event;
111
+ }
112
+
113
+ } // namespace sycl_interop
114
+
115
+ /// @} dnnl_graph_api_sycl_interop
116
+
117
+ /// @} dnnl_graph_api_interop
118
+
119
+ } // namespace graph
120
+ } // namespace dnnl
121
+
122
+ /// @} dnnl_graph_api
123
+
124
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_graph_types.h ADDED
@@ -0,0 +1,465 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ /// @file
18
+ /// C API definitions
19
+
20
+ #ifndef ONEAPI_DNNL_DNNL_GRAPH_TYPES_H
21
+ #define ONEAPI_DNNL_DNNL_GRAPH_TYPES_H
22
+
23
+ #ifdef __cplusplus
24
+ extern "C" {
25
+ #endif
26
+
27
+ /// @cond DO_NOT_DOCUMENT_THIS
28
+ #include <limits.h>
29
+ #include <stddef.h>
30
+
31
+ #include "oneapi/dnnl/dnnl_common_types.h"
32
+ /// @endcond
33
+
34
+ /// @addtogroup dnnl_graph_api
35
+ /// @{
36
+
37
+ /// @addtogroup dnnl_graph_api_logical_tensor
38
+ /// @{
39
+
40
+ /// A wildcard value for number of dimensions which is unknown at a tensor or
41
+ /// operation creation time.
42
+ #define DNNL_GRAPH_UNKNOWN_NDIMS -1
43
+
44
+ /// A wildcard value for dimensions that are unknown at a tensor or operation
45
+ /// creation time.
46
+ #define DNNL_GRAPH_UNKNOWN_DIM INT64_MIN
47
+
48
+ /// Layout type specification
49
+ typedef enum {
50
+ /// Undefined layout type
51
+ dnnl_graph_layout_type_undef = 0,
52
+ /// Any means to let the library to decide the layout for a tensor during
53
+ /// partition compilation.
54
+ dnnl_graph_layout_type_any = 1,
55
+ /// Strided means that the layout of a tensor is determined by the strides
56
+ /// field in the logical tensor.
57
+ dnnl_graph_layout_type_strided = 2,
58
+ /// Opaque means that the layout of a tensor is the library specific.
59
+ /// Usually, an opaque layout is generated by a partition which is compiled
60
+ /// with layout type any.
61
+ dnnl_graph_layout_type_opaque = 3,
62
+ } dnnl_graph_layout_type_t;
63
+
64
+ /// Logical tensor property
65
+ typedef enum {
66
+ /// Undefined tensor property
67
+ dnnl_graph_tensor_property_undef = 0,
68
+ /// Variable means the tensor may be changed during computation or between
69
+ /// different iterations.
70
+ dnnl_graph_tensor_property_variable = 1,
71
+ /// Constant means the tensor will keep unchanged during computation and
72
+ /// between different iterations. It's useful for the library to apply
73
+ /// optimizations for constant tensors or cache constant tensors inside the
74
+ /// library. For example, constant weight tensors in inference scenarios.
75
+ dnnl_graph_tensor_property_constant = 2,
76
+ } dnnl_graph_tensor_property_t;
77
+
78
+ /// Logical tensor. It is based on an ID, a number of dimensions, dimensions
79
+ /// themselves, element data type, tensor property and tensor memory layout.
80
+ typedef struct {
81
+ /// Unique id of each logical tensor. The library uses logical tensor IDs to
82
+ /// build up the connections between operations if the output of one
83
+ /// operation has the same ID as the input of another operation.
84
+ size_t id;
85
+
86
+ /// Number of dimensions. -1 means unknown (DNNL_GRAPH_UNKNOWN_NDIMS). 0 is
87
+ /// used to define scalar tensor.
88
+ int ndims;
89
+
90
+ /// Size of each dimension. #DNNL_GRAPH_UNKNOWN_DIM means the size of that
91
+ /// dimension is unknown. 0 is used to define zero-dimension tensor. The
92
+ /// library supports to deduce output shapes according to input shapes
93
+ /// during compilation. Unlike memory descriptor in oneDNN primitive API,
94
+ /// the order of dimensions is not defined in logical tensor. It is defined
95
+ /// by the operations which respect the order through the attributes
96
+ /// #dnnl_graph_op_attr_data_format or #dnnl_graph_op_attr_weights_format.
97
+ /// For example, for a Convolution with `data_format=NXC`, it means the
98
+ /// first element of dims of activation tensor is mini-batch size, the last
99
+ /// effective element of dims is channel size, and other elements between
100
+ /// them are spatial dimensions.
101
+ dnnl_dims_t dims;
102
+
103
+ /// Data type of the tensor elements.
104
+ dnnl_data_type_t data_type;
105
+
106
+ /// Property type of the tensor.
107
+ dnnl_graph_tensor_property_t property;
108
+
109
+ /// Layout type of the tensor.
110
+ dnnl_graph_layout_type_t layout_type;
111
+ union {
112
+ /// The field is valid when `layout_type` is
113
+ /// #dnnl_graph_layout_type_strided. #DNNL_GRAPH_UNKNOWN_DIM means the
114
+ /// stride of the dimension is unknown. The library currently doesn't
115
+ /// support other negative stride values.
116
+ dnnl_dims_t strides;
117
+
118
+ /// The field is valid when `layout_type` is
119
+ /// #dnnl_graph_layout_type_opaque. An opaque layout ID is usually
120
+ /// generated by a partition which is compiled with layout type any.
121
+ size_t layout_id;
122
+ } layout;
123
+ } dnnl_graph_logical_tensor_t;
124
+
125
+ /// @} dnnl_graph_api_logical_tensor
126
+
127
+ /// @addtogroup dnnl_graph_api_partition
128
+ /// @{
129
+
130
+ /// Policy specifications for partitioning
131
+ typedef enum {
132
+ /// Fusion policy returns partitions with typical post-op fusions, eg.
133
+ /// Convolution + ReLU or other element-wise operations or a chian of
134
+ /// post-ops.
135
+ dnnl_graph_partition_policy_fusion = 1,
136
+ /// Debug policy doesn't not apply any fusions. It returns partitions with
137
+ /// single operation in each partition. The policy is useful when users
138
+ /// notice any bug or correctness issue in fusion policy.
139
+ dnnl_graph_partition_policy_debug = 2,
140
+ } dnnl_graph_partition_policy_t;
141
+
142
+ /// An opaque structure to describe a partition.
143
+ struct dnnl_graph_partition;
144
+
145
+ /// A partition handle.
146
+ typedef struct dnnl_graph_partition *dnnl_graph_partition_t;
147
+
148
+ /// A constant partition handle.
149
+ typedef const struct dnnl_graph_partition *const_dnnl_graph_partition_t;
150
+
151
+ /// @} dnnl_graph_api_partition
152
+
153
+ /// @addtogroup dnnl_graph_api_graph
154
+ /// @{
155
+
156
+ /// An opaque structure to describe a graph.
157
+ struct dnnl_graph_graph;
158
+
159
+ /// A graph handle.
160
+ typedef struct dnnl_graph_graph *dnnl_graph_graph_t;
161
+
162
+ /// A constant graph handle.
163
+ typedef const struct dnnl_graph_graph *const_dnnl_graph_graph_t;
164
+
165
+ /// @}
166
+
167
+ /// @addtogroup dnnl_graph_api_op
168
+ /// @{
169
+
170
+ /// Kinds of operations
171
+ typedef enum {
172
+ dnnl_graph_op_abs,
173
+ dnnl_graph_op_abs_backward,
174
+ dnnl_graph_op_add,
175
+ dnnl_graph_op_avg_pool,
176
+ dnnl_graph_op_avg_pool_backward,
177
+ dnnl_graph_op_batch_norm_backward,
178
+ dnnl_graph_op_batch_norm_forward_training,
179
+ dnnl_graph_op_batch_norm_inference,
180
+ dnnl_graph_op_bias_add,
181
+ dnnl_graph_op_bias_add_backward,
182
+ dnnl_graph_op_clamp,
183
+ dnnl_graph_op_clamp_backward,
184
+ dnnl_graph_op_concat,
185
+ dnnl_graph_op_convolution,
186
+ dnnl_graph_op_convolution_backward_data,
187
+ dnnl_graph_op_convolution_backward_weights,
188
+ dnnl_graph_op_conv_transpose,
189
+ dnnl_graph_op_conv_transpose_backward_data,
190
+ dnnl_graph_op_conv_transpose_backward_weights,
191
+ dnnl_graph_op_dequantize,
192
+ dnnl_graph_op_divide,
193
+ dnnl_graph_op_dynamic_dequantize,
194
+ dnnl_graph_op_dynamic_quantize,
195
+ dnnl_graph_op_elu,
196
+ dnnl_graph_op_elu_backward,
197
+ dnnl_graph_op_end,
198
+ dnnl_graph_op_exp,
199
+ dnnl_graph_op_gelu,
200
+ dnnl_graph_op_gelu_backward,
201
+ dnnl_graph_op_hard_swish,
202
+ dnnl_graph_op_hard_swish_backward,
203
+ dnnl_graph_op_interpolate,
204
+ dnnl_graph_op_interpolate_backward,
205
+ dnnl_graph_op_layer_norm,
206
+ dnnl_graph_op_layer_norm_backward,
207
+ dnnl_graph_op_leaky_relu,
208
+ dnnl_graph_op_log,
209
+ dnnl_graph_op_log_softmax,
210
+ dnnl_graph_op_log_softmax_backward,
211
+ dnnl_graph_op_matmul,
212
+ dnnl_graph_op_maximum,
213
+ dnnl_graph_op_max_pool,
214
+ dnnl_graph_op_max_pool_backward,
215
+ dnnl_graph_op_minimum,
216
+ dnnl_graph_op_mish,
217
+ dnnl_graph_op_mish_backward,
218
+ dnnl_graph_op_multiply,
219
+ dnnl_graph_op_prelu,
220
+ dnnl_graph_op_prelu_backward,
221
+ dnnl_graph_op_quantize,
222
+ dnnl_graph_op_reciprocal,
223
+ dnnl_graph_op_reduce_l1,
224
+ dnnl_graph_op_reduce_l2,
225
+ dnnl_graph_op_reduce_max,
226
+ dnnl_graph_op_reduce_mean,
227
+ dnnl_graph_op_reduce_min,
228
+ dnnl_graph_op_reduce_prod,
229
+ dnnl_graph_op_reduce_sum,
230
+ dnnl_graph_op_relu,
231
+ dnnl_graph_op_relu_backward,
232
+ dnnl_graph_op_reorder,
233
+ dnnl_graph_op_round,
234
+ dnnl_graph_op_sigmoid,
235
+ dnnl_graph_op_sigmoid_backward,
236
+ dnnl_graph_op_softmax,
237
+ dnnl_graph_op_softmax_backward,
238
+ dnnl_graph_op_softplus,
239
+ dnnl_graph_op_softplus_backward,
240
+ dnnl_graph_op_sqrt,
241
+ dnnl_graph_op_sqrt_backward,
242
+ dnnl_graph_op_square,
243
+ dnnl_graph_op_squared_difference,
244
+ dnnl_graph_op_static_reshape,
245
+ dnnl_graph_op_static_transpose,
246
+ dnnl_graph_op_subtract,
247
+ dnnl_graph_op_tanh,
248
+ dnnl_graph_op_tanh_backward,
249
+ dnnl_graph_op_type_cast,
250
+ dnnl_graph_op_wildcard,
251
+ dnnl_graph_op_hard_sigmoid,
252
+ dnnl_graph_op_hard_sigmoid_backward,
253
+ dnnl_graph_op_select,
254
+ dnnl_graph_op_pow,
255
+ dnnl_graph_op_last_symbol,
256
+ } dnnl_graph_op_kind_t;
257
+
258
+ /// Attributes of operations
259
+ typedef enum {
260
+ /// Undefined op attribute.
261
+ dnnl_graph_op_attr_undef = 0,
262
+
263
+ // float32 attributes. The value of these attributes can be any single
264
+ // float32 number.
265
+
266
+ /// Specifies an alpha attribute to an op.
267
+ dnnl_graph_op_attr_alpha = 0x1,
268
+ /// Specifies an beta attribute to an op.
269
+ dnnl_graph_op_attr_beta,
270
+ /// Specifies an epsilon attribute to an op.
271
+ dnnl_graph_op_attr_epsilon,
272
+ /// Specifies a max attribute to an op.
273
+ dnnl_graph_op_attr_max,
274
+ ///Specifies a min attribute to an op.
275
+ dnnl_graph_op_attr_min,
276
+ /// Specifies a momentum attribute to an op.
277
+ dnnl_graph_op_attr_momentum,
278
+
279
+ // float32 vector attributes. The value of these attributes can be a vector
280
+ // of float32 numbers.
281
+
282
+ /// Specifies a scales attribute to an op.
283
+ dnnl_graph_op_attr_scales = 0x20,
284
+
285
+ // int64_t attributes. The value of these attributes can be any single int64
286
+ // number.
287
+
288
+ /// Specifies an axis attribute to an op.
289
+ dnnl_graph_op_attr_axis = 0x30,
290
+ /// Specifies a begin_norm_axis attribute to an op.
291
+ dnnl_graph_op_attr_begin_norm_axis,
292
+ /// Specifies a groups attribute to an op.
293
+ dnnl_graph_op_attr_groups,
294
+
295
+ // int64_t vector attributes. The value of these attributes can be a vector
296
+ // of int64 numbers.
297
+
298
+ /// Specifies an axes attribute to an op.
299
+ dnnl_graph_op_attr_axes = 0x40,
300
+ /// Specifies a dilations attribute to an op.
301
+ dnnl_graph_op_attr_dilations,
302
+ /// Specifies an dst_shape attribute to an op.
303
+ dnnl_graph_op_attr_dst_shape,
304
+ /// Specifies a kernel attribute to an op.
305
+ dnnl_graph_op_attr_kernel,
306
+ /// Specifies an order attribute to an op.
307
+ dnnl_graph_op_attr_order,
308
+ /// Specifies an output_padding attribute to an op.
309
+ dnnl_graph_op_attr_output_padding,
310
+ /// Specifies a pads_begin attribute to an op.
311
+ dnnl_graph_op_attr_pads_begin,
312
+ /// Specifies a pads_end attribute to an op.
313
+ dnnl_graph_op_attr_pads_end,
314
+ /// Specifies a shape attribute to an op.
315
+ dnnl_graph_op_attr_shape,
316
+ /// Specifies a sizes attribute to an op.
317
+ dnnl_graph_op_attr_sizes,
318
+ /// Specifies a input_shape attribute to an op.
319
+ dnnl_graph_op_attr_src_shape,
320
+ /// Specifies a strides attribute to an op.
321
+ dnnl_graph_op_attr_strides,
322
+ /// Specifies a weight_shape attribute to an op.
323
+ dnnl_graph_op_attr_weights_shape,
324
+ /// Specifies a zps attribute to an op.
325
+ dnnl_graph_op_attr_zps,
326
+
327
+ // bool attributes. The value of these attributes can be any single bool
328
+ // value.
329
+
330
+ /// Specifies an exclude_pad attribute to an op.
331
+ dnnl_graph_op_attr_exclude_pad = 0x60,
332
+ /// Specifies a keep_dims attribute to an op.
333
+ dnnl_graph_op_attr_keep_dims,
334
+ /// Specifies a keep_stats attribute to an op.
335
+ dnnl_graph_op_attr_keep_stats,
336
+ /// Specifies a per_channel_broadcast attribute to an op.
337
+ dnnl_graph_op_attr_per_channel_broadcast,
338
+ /// Specifies a special_zero attribute to an op.
339
+ dnnl_graph_op_attr_special_zero,
340
+ /// Specifies a transpose_a attribute to an op.
341
+ dnnl_graph_op_attr_transpose_a,
342
+ /// Specifies a transpose_b attribute to an op.
343
+ dnnl_graph_op_attr_transpose_b,
344
+ /// Specifies an use_affine attribute to an op.
345
+ dnnl_graph_op_attr_use_affine,
346
+ /// Specifies an use_dst attribute to an op.
347
+ dnnl_graph_op_attr_use_dst,
348
+
349
+ // string attributes. The value of these attributes can be a string.
350
+
351
+ /// Specifies an auto_broadcast attribute to an op. The value can be "none"
352
+ /// or "numpy".
353
+ dnnl_graph_op_attr_auto_broadcast = 0x80,
354
+ /// Specifies an auto_pad attribute to an op. The value can be "none",
355
+ /// "same_upper", "same_lower", or "valid".
356
+ dnnl_graph_op_attr_auto_pad,
357
+ /// Specifies an coordinate_transformation_mode attribute to an op. The
358
+ /// value can be "half_pixel" or "align_corners". The attribute is defined
359
+ /// for Interpolate operations.
360
+ dnnl_graph_op_attr_coordinate_transformation_mode,
361
+ /// Specifies a data_format of an op. The value can be "NCX" or "NXC".
362
+ dnnl_graph_op_attr_data_format,
363
+ /// Specifies a mode attribute of an op. The value can be "nearest",
364
+ /// "linear", "bilinear", or "trilinear". The attribute is defined for
365
+ /// Interpolate operations.
366
+ dnnl_graph_op_attr_mode,
367
+ /// Specifies a qtype attribute to an op. The value can be "per_channel" or
368
+ /// "per_tensor". The attribute is defined for quantization operations.
369
+ dnnl_graph_op_attr_qtype,
370
+ /// Specifies a rounding_type attribute to an op. The value can be "ceil" or
371
+ /// "floor".
372
+ dnnl_graph_op_attr_rounding_type,
373
+ /// Specifies a weights_format of an op. The value can be "OIX", "XIO",
374
+ /// "IOX", or "XOI". Different operations may support different values.
375
+ dnnl_graph_op_attr_weights_format,
376
+
377
+ /// Specifies the end of all above exteral attributes for check.
378
+ dnnl_graph_op_attr_end = 0xFF,
379
+ } dnnl_graph_op_attr_t;
380
+
381
+ /// An opaque structure to describe an operation.
382
+ struct dnnl_graph_op;
383
+
384
+ /// An operation handle.
385
+ typedef struct dnnl_graph_op *dnnl_graph_op_t;
386
+
387
+ /// A constant operation handle.
388
+ typedef const struct dnnl_graph_op *const_dnnl_graph_op_t;
389
+
390
+ /// @} dnnl_graph_api_op
391
+
392
+ /// @addtogroup dnnl_graph_api_allocator
393
+ /// @{
394
+
395
+ /// Allocation call-back function interface for host. For SYCL allocator, see
396
+ /// #dnnl_graph_sycl_allocate_f.
397
+ typedef void *(*dnnl_graph_host_allocate_f)(size_t size, size_t alignment);
398
+
399
+ /// Deallocation call-back function interface for host. For SYCL allocator, see
400
+ /// #dnnl_graph_sycl_deallocate_f.
401
+ typedef void (*dnnl_graph_host_deallocate_f)(void *);
402
+
403
+ /// An opaque structure to describe an allocator.
404
+ struct dnnl_graph_allocator;
405
+
406
+ /// An allocator handle.
407
+ typedef struct dnnl_graph_allocator *dnnl_graph_allocator_t;
408
+
409
+ /// A constant allocator handle.
410
+ typedef const struct dnnl_graph_allocator *const_dnnl_graph_allocator_t;
411
+
412
+ /// @} dnnl_graph_api_allocator
413
+
414
+ /// @addtogroup dnnl_graph_api_compiled_partition
415
+ /// @{
416
+
417
+ /// In-place pair definition. It can queried from a compiled partition
418
+ /// indicating that an input and an output of the partition can share the same
419
+ /// memory buffer for computation. In-place computation helps to reduce the
420
+ /// memory footprint and improves cache locality. But since the library may not
421
+ /// have a global view of user's application, it's possible that the tensor with
422
+ /// `input_id` is used at other places in user's computation graph. In this
423
+ /// case, the user should take the in-place pair as a hint and pass a different
424
+ /// memory buffer for output tensor to avoid overwriting the input memory buffer
425
+ /// which will probably cause unexpected incorrect results.
426
+ typedef struct {
427
+ /// The id of input tensor
428
+ size_t input_id;
429
+
430
+ /// The id of output tensor
431
+ size_t output_id;
432
+ } dnnl_graph_inplace_pair_t;
433
+
434
+ /// An opaque structure to describe a compiled partition.
435
+ struct dnnl_graph_compiled_partition;
436
+
437
+ /// A compiled partition handle.
438
+ typedef struct dnnl_graph_compiled_partition *dnnl_graph_compiled_partition_t;
439
+
440
+ /// A constant compiled partition handle.
441
+ typedef const struct dnnl_graph_compiled_partition
442
+ *const_dnnl_graph_compiled_partition_t;
443
+
444
+ /// @} dnnl_graph_api_compiled_partition
445
+
446
+ /// @addtogroup dnnl_graph_api_tensor
447
+ /// @{
448
+
449
+ /// An opaque structure to describe a tensor.
450
+ struct dnnl_graph_tensor;
451
+
452
+ /// A tensor handle.
453
+ typedef struct dnnl_graph_tensor *dnnl_graph_tensor_t;
454
+
455
+ /// A constant tensor handle.
456
+ typedef const struct dnnl_graph_tensor *const_dnnl_graph_tensor_t;
457
+
458
+ /// @} dnnl_graph_api_tensor
459
+
460
+ /// @} dnnl_graph_api
461
+
462
+ #ifdef __cplusplus
463
+ }
464
+ #endif
465
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_ocl.h ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2024 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_OCL_H
18
+ #define ONEAPI_DNNL_DNNL_OCL_H
19
+
20
+ #include "oneapi/dnnl/dnnl.h"
21
+
22
+ #include "oneapi/dnnl/dnnl_ocl_types.h"
23
+
24
+ /// @cond DO_NOT_DOCUMENT_THIS
25
+ // Set target version for OpenCL explicitly to suppress a compiler warning.
26
+ #ifndef CL_TARGET_OPENCL_VERSION
27
+ #define CL_TARGET_OPENCL_VERSION 120
28
+ #endif
29
+
30
+ #include <CL/cl.h>
31
+ /// @endcond
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /// @addtogroup dnnl_api
38
+ /// @{
39
+
40
+ /// @addtogroup dnnl_api_interop
41
+ /// @{
42
+
43
+ /// @addtogroup dnnl_api_ocl_interop
44
+ /// @{
45
+
46
+ /// Creates a memory object.
47
+ ///
48
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
49
+ /// constructed memory object will have the underlying buffer set. In this
50
+ /// case, the buffer will be initialized as if:
51
+ /// - dnnl_memory_set_data_handle() has been called, if @p memory_kind is equal
52
+ /// to dnnl_ocl_interop_usm, or
53
+ /// - dnnl_ocl_interop_memory_set_mem_object() has been called, if @p memory_kind
54
+ /// is equal to dnnl_ocl_interop_buffer.
55
+ ///
56
+ /// @param memory Output memory object.
57
+ /// @param memory_desc Memory descriptor.
58
+ /// @param engine Engine to use.
59
+ /// @param memory_kind Memory allocation kind to specify the type of handle.
60
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
61
+ /// - A USM pointer to the user-allocated buffer. In this case the library
62
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
63
+ /// dnnl_ocl_interop_usm.
64
+ /// - An OpenCL buffer. In this case the library doesn't own the buffer.
65
+ /// Requires @p memory_kind be equal to be equal to dnnl_ocl_interop_buffer.
66
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
67
+ /// allocate the buffer that corresponds to the memory allocation kind
68
+ /// @p memory_kind for the memory object. In this case the library
69
+ /// owns the buffer.
70
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
71
+ /// create memory object without an underlying buffer.
72
+ /// @returns #dnnl_success on success and a status describing the error
73
+ /// otherwise.
74
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_create(dnnl_memory_t *memory,
75
+ const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
76
+ dnnl_ocl_interop_memory_kind_t memory_kind, void *handle);
77
+
78
+ /// Returns the memory allocation kind associated with a memory object.
79
+ ///
80
+ /// @param memory Memory to query.
81
+ /// @param memory_kind Output underlying memory allocation kind of the memory
82
+ /// object.
83
+ /// @returns #dnnl_success on success and a status describing the error
84
+ /// otherwise.
85
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_get_memory_kind(
86
+ const_dnnl_memory_t memory,
87
+ dnnl_ocl_interop_memory_kind_t *memory_kind);
88
+
89
+ /// Returns an OpenCL memory object associated with a memory object.
90
+ ///
91
+ /// @param memory Memory object.
92
+ /// @param mem_object Output OpenCL memory object.
93
+ /// @returns #dnnl_success on success and a status describing the error
94
+ /// otherwise.
95
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_get_mem_object(
96
+ const_dnnl_memory_t memory, cl_mem *mem_object);
97
+
98
+ /// Sets OpenCL memory object associated with a memory object.
99
+ ///
100
+ /// For behavioral details, see dnnl_memory_set_data_handle().
101
+ ///
102
+ /// @param memory Memory object.
103
+ /// @param mem_object OpenCL memory object.
104
+ /// @returns #dnnl_success on success and a status describing the error
105
+ /// otherwise.
106
+ dnnl_status_t DNNL_API dnnl_ocl_interop_memory_set_mem_object(
107
+ dnnl_memory_t memory, cl_mem mem_object);
108
+
109
+ /// Retrieves a cache blob ID for the OpenCL device.
110
+ ///
111
+ /// @warning
112
+ /// This API is intended to be used with
113
+ /// #dnnl_ocl_interop_engine_get_cache_blob() and
114
+ /// #dnnl_ocl_interop_engine_create_from_cache_blob(). The returned cache
115
+ /// blob ID can only be used as an ID of the cache blob returned by
116
+ /// #dnnl_ocl_interop_engine_get_cache_blob().
117
+ ///
118
+ /// @note The cache blob ID can be empty (@p size will be 0 and
119
+ /// @p cache_blob_id will be nullptr) if oneDNN doesn't have anything to
120
+ /// put in the cache blob. (#dnnl_ocl_interop_engine_get_cache_blob will
121
+ /// return an empty cache blob).
122
+ ///
123
+ /// @param device An OpenCL device.
124
+ /// @param size Size of the cache blob ID in bytes.
125
+ /// @param cache_blob_id Cache blob id of size @p size. If
126
+ /// the @p cache_blob_id is nullptr then the size of the cache blob ID is
127
+ /// returned in @p size.
128
+ /// @returns #dnnl_success on success and a status describing the error
129
+ /// otherwise.
130
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_cache_blob_id(
131
+ cl_device_id device, size_t *size, uint8_t *cache_blob_id);
132
+
133
+ /// Retrieves a cache blob associated with the given engine.
134
+ ///
135
+ /// @note The cache blob can be empty (@p size will be 0 and @p cache_blob
136
+ /// will be nullptr) if oneDNN doesn't have anything to put in the cache
137
+ /// blob. It's the user's responsibility to check whether it's empty
138
+ /// prior to passing it to
139
+ /// #dnnl_ocl_interop_engine_create_from_cache_blob().
140
+ ///
141
+ /// @param engine Engine to query for the cache blob.
142
+ /// @param size Size of the cache blob in bytes.
143
+ /// @param cache_blob Cache blob of size @p size. If the @p cache_blob is
144
+ /// nullptr then the size of the cache blob is returned in @p size.
145
+ /// @returns #dnnl_success on success and a status describing the error
146
+ /// otherwise.
147
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_cache_blob(
148
+ dnnl_engine_t engine, size_t *size, uint8_t *cache_blob);
149
+
150
+ /// Creates an engine from the given cache blob.
151
+ ///
152
+ /// @param engine Output engine.
153
+ /// @param device The OpenCL device that this engine will encapsulate.
154
+ /// @param context The OpenCL context (containing the device) that this
155
+ /// engine will use for all operations.
156
+ /// @param size Size of the cache blob in bytes.
157
+ /// @param cache_blob Cache blob of size @p size.
158
+ /// @returns #dnnl_success on success and a status describing the error
159
+ /// otherwise.
160
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create_from_cache_blob(
161
+ dnnl_engine_t *engine, cl_device_id device, cl_context context,
162
+ size_t size, const uint8_t *cache_blob);
163
+
164
+ /// Creates an engine associated with an OpenCL device and an OpenCL context.
165
+ ///
166
+ /// @param engine Output engine.
167
+ /// @param device Underlying OpenCL device to use for the engine.
168
+ /// @param context Underlying OpenCL context to use for the engine.
169
+ /// @returns #dnnl_success on success and a status describing the error
170
+ /// otherwise.
171
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_create(
172
+ dnnl_engine_t *engine, cl_device_id device, cl_context context);
173
+
174
+ /// Returns the OpenCL context associated with an engine.
175
+ ///
176
+ /// @param engine Engine to query.
177
+ /// @param context Output underlying OpenCL context of the engine.
178
+ /// @returns #dnnl_success on success and a status describing the error
179
+ /// otherwise.
180
+ dnnl_status_t DNNL_API dnnl_ocl_interop_engine_get_context(
181
+ dnnl_engine_t engine, cl_context *context);
182
+
183
+ /// Returns the OpenCL device associated with an engine.
184
+ ///
185
+ /// @param engine Engine to query.
186
+ /// @param device Output underlying OpenCL device of the engine.
187
+ /// @returns #dnnl_success on success and a status describing the error
188
+ /// otherwise.
189
+ dnnl_status_t DNNL_API dnnl_ocl_interop_get_device(
190
+ dnnl_engine_t engine, cl_device_id *device);
191
+
192
+ /// Creates an execution stream for a given engine associated with
193
+ /// an OpenCL command queue.
194
+ ///
195
+ /// @param stream Output execution stream.
196
+ /// @param engine Engine to create the execution stream on.
197
+ /// @param queue OpenCL command queue to use.
198
+ /// @returns #dnnl_success on success and a status describing the error
199
+ /// otherwise.
200
+ dnnl_status_t DNNL_API dnnl_ocl_interop_stream_create(
201
+ dnnl_stream_t *stream, dnnl_engine_t engine, cl_command_queue queue);
202
+
203
+ /// Returns the OpenCL command queue associated with an execution stream.
204
+ ///
205
+ /// @param stream Execution stream to query.
206
+ /// @param queue Output OpenCL command queue.
207
+ /// @returns #dnnl_success on success and a status describing the error
208
+ /// otherwise.
209
+ dnnl_status_t DNNL_API dnnl_ocl_interop_stream_get_command_queue(
210
+ dnnl_stream_t stream, cl_command_queue *queue);
211
+
212
+ /// Executes computations specified by the primitive in a specified stream and
213
+ /// returns an OpenCL event.
214
+ ///
215
+ /// @param primitive Primitive to execute.
216
+ /// @param stream Stream to use.
217
+ /// @param nargs Number of arguments.
218
+ /// @param args Array of arguments. Each argument is an
219
+ /// <index, #dnnl_memory_t> pair. The index is one of the `DNNL_ARG_*`
220
+ /// values such as `DNNL_ARG_SRC`. Unless runtime shapes are used (see
221
+ /// #DNNL_RUNTIME_DIM_VAL), the memory object must have the same memory
222
+ /// descriptor as that returned by
223
+ /// #dnnl_primitive_desc_query_md(#dnnl_query_exec_arg_md, index).
224
+ /// @param deps A pointer to a vector of size @p ndeps that contains
225
+ /// dependencies.
226
+ /// @param ndeps Number of dependencies.
227
+ /// @param return_event Output event. It's the user's responsibility to
228
+ /// manage lifetime of the event. Can be NULL. When @p stream is in-order
229
+ /// NULL will be returned.
230
+ /// @returns #dnnl_success on success and a status describing the error
231
+ /// otherwise.
232
+ dnnl_status_t DNNL_API dnnl_ocl_interop_primitive_execute(
233
+ const_dnnl_primitive_t primitive, dnnl_stream_t stream, int nargs,
234
+ const dnnl_exec_arg_t *args, const cl_event *deps, int ndeps,
235
+ cl_event *return_event);
236
+
237
+ /// @} dnnl_api_ocl_interop
238
+
239
+ /// @} dnnl_api_interop
240
+
241
+ /// @} dnnl_api
242
+
243
+ #ifdef __cplusplus
244
+ }
245
+ #endif
246
+
247
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_ocl.hpp ADDED
@@ -0,0 +1,338 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2022 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_OCL_HPP
18
+ #define ONEAPI_DNNL_DNNL_OCL_HPP
19
+
20
+ #include "oneapi/dnnl/dnnl.hpp"
21
+
22
+ /// @cond DO_NOT_DOCUMENT_THIS
23
+ #include <algorithm>
24
+ #include <cstdlib>
25
+ #include <iterator>
26
+ #include <memory>
27
+ #include <string>
28
+ #include <vector>
29
+ #include <unordered_map>
30
+
31
+ #include "oneapi/dnnl/dnnl_ocl.h"
32
+
33
+ #include <CL/cl.h>
34
+ /// @endcond
35
+
36
+ /// @addtogroup dnnl_api
37
+ /// @{
38
+
39
+ namespace dnnl {
40
+
41
+ /// @addtogroup dnnl_api_interop Runtime interoperability API
42
+ /// API extensions to interact with the underlying run-time.
43
+ /// @{
44
+
45
+ /// @addtogroup dnnl_api_ocl_interop OpenCL interoperability API
46
+ /// API extensions to interact with the underlying OpenCL run-time.
47
+ ///
48
+ /// @sa @ref dev_guide_opencl_interoperability in developer guide
49
+ /// @{
50
+
51
+ /// OpenCL interoperability namespace
52
+ namespace ocl_interop {
53
+
54
+ /// Memory allocation kind.
55
+ enum class memory_kind {
56
+ /// USM (device, shared, host, or unknown) memory allocation kind.
57
+ usm = dnnl_ocl_interop_usm,
58
+ /// Buffer memory allocation kind - default.
59
+ buffer = dnnl_ocl_interop_buffer,
60
+ };
61
+
62
+ /// Converts a memory allocation kind enum value from C++ API to C API type.
63
+ ///
64
+ /// @param akind C++ API memory allocation kind enum value.
65
+ /// @returns Corresponding C API memory allocation kind enum value.
66
+ inline dnnl_ocl_interop_memory_kind_t convert_to_c(memory_kind akind) {
67
+ return static_cast<dnnl_ocl_interop_memory_kind_t>(akind);
68
+ }
69
+
70
+ /// Returns the cache blob ID of the OpenCL device.
71
+ ///
72
+ /// @warning
73
+ /// This API is intended to be used with
74
+ /// #dnnl::ocl_interop::get_engine_cache_blob() and
75
+ /// #dnnl::ocl_interop::make_engine(cl_device_id, cl_context, const std::vector<uint8_t> &).
76
+ /// The returned cache blob ID can only be used as an ID of the cache blob
77
+ /// returned by #dnnl::ocl_interop::get_engine_cache_blob().
78
+ ///
79
+ /// @note The cache blob ID can be empty (@p size will be 0 and
80
+ /// @p cache_blob_id will be nullptr) if oneDNN doesn't have anything to
81
+ /// put in the cache blob. (#dnnl_ocl_interop_engine_get_cache_blob will
82
+ /// return an empty cache blob).
83
+ ///
84
+ /// @param device An OpenCL device.
85
+ /// @returns A vector containing the cache blob ID.
86
+ inline std::vector<uint8_t> get_engine_cache_blob_id(cl_device_id device) {
87
+ size_t size = 0;
88
+ error::wrap_c_api(
89
+ dnnl_ocl_interop_engine_get_cache_blob_id(device, &size, nullptr),
90
+ "could not get an engine cache blob id size");
91
+
92
+ std::vector<uint8_t> cache_blob_id(size);
93
+ error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob_id(
94
+ device, &size, cache_blob_id.data()),
95
+ "could not get an engine cache blob id");
96
+ return cache_blob_id;
97
+ }
98
+
99
+ /// Returns a cache blob for the engine.
100
+ ///
101
+ /// @note The cache blob vector can be empty if oneDNN doesn't have anything
102
+ /// to put in the cache blob. It's the user's responsibility to check
103
+ /// whether it's empty prior to passing it to
104
+ /// #dnnl::ocl_interop::make_engine(cl_device_id, cl_context, const std::vector<uint8_t> &)
105
+ ///
106
+ /// @param aengine Engine to query for the cache blob.
107
+ /// @returns Vector containing the cache blob.
108
+ inline std::vector<uint8_t> get_engine_cache_blob(const engine &aengine) {
109
+ size_t size = 0;
110
+ error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob(
111
+ aengine.get(), &size, nullptr),
112
+ "could not get an engine cache blob size");
113
+
114
+ std::vector<uint8_t> cache_blob(size);
115
+ error::wrap_c_api(dnnl_ocl_interop_engine_get_cache_blob(
116
+ aengine.get(), &size, cache_blob.data()),
117
+ "could not get an engine cache blob");
118
+ return cache_blob;
119
+ }
120
+
121
+ /// Constructs an engine from the given cache blob.
122
+ ///
123
+ /// @param device The OpenCL device that this engine will encapsulate.
124
+ /// @param context The OpenCL context (containing the device) that this
125
+ /// engine will use for all operations.
126
+ /// @param cache_blob Cache blob.
127
+ /// @returns An engine.
128
+ inline engine make_engine(cl_device_id device, cl_context context,
129
+ const std::vector<uint8_t> &cache_blob) {
130
+ dnnl_engine_t c_engine;
131
+ error::wrap_c_api(
132
+ dnnl_ocl_interop_engine_create_from_cache_blob(&c_engine, device,
133
+ context, cache_blob.size(), cache_blob.data()),
134
+ "could not create an engine from cache blob");
135
+ return engine(c_engine);
136
+ }
137
+
138
+ /// Constructs an engine from OpenCL device and context objects.
139
+ ///
140
+ /// @param device The OpenCL device that this engine will encapsulate.
141
+ /// @param context The OpenCL context (containing the device) that this
142
+ /// engine will use for all operations.
143
+ /// @returns An engine.
144
+ inline engine make_engine(cl_device_id device, cl_context context) {
145
+ dnnl_engine_t c_engine;
146
+ error::wrap_c_api(
147
+ dnnl_ocl_interop_engine_create(&c_engine, device, context),
148
+ "could not create an engine");
149
+ return engine(c_engine);
150
+ }
151
+
152
+ /// Returns OpenCL context associated with the engine.
153
+ ///
154
+ /// @param aengine An engine.
155
+ /// @returns Underlying OpenCL context.
156
+ inline cl_context get_context(const engine &aengine) {
157
+ cl_context context = nullptr;
158
+ error::wrap_c_api(
159
+ dnnl_ocl_interop_engine_get_context(aengine.get(), &context),
160
+ "could not get an OpenCL context from an engine");
161
+ return context;
162
+ }
163
+
164
+ /// Returns OpenCL device associated with the engine.
165
+ ///
166
+ /// @param aengine An engine.
167
+ /// @returns Underlying OpenCL device.
168
+ inline cl_device_id get_device(const engine &aengine) {
169
+ cl_device_id device = nullptr;
170
+ error::wrap_c_api(dnnl_ocl_interop_get_device(aengine.get(), &device),
171
+ "could not get an OpenCL device from an engine");
172
+ return device;
173
+ }
174
+
175
+ /// Constructs an execution stream for the specified engine and OpenCL queue.
176
+ ///
177
+ /// @param aengine Engine to create the stream on.
178
+ /// @param queue OpenCL queue to use for the stream.
179
+ /// @returns An execution stream.
180
+ inline stream make_stream(const engine &aengine, cl_command_queue queue) {
181
+ dnnl_stream_t c_stream;
182
+ error::wrap_c_api(
183
+ dnnl_ocl_interop_stream_create(&c_stream, aengine.get(), queue),
184
+ "could not create a stream");
185
+ return stream(c_stream);
186
+ }
187
+
188
+ /// Returns OpenCL queue object associated with the execution stream.
189
+ ///
190
+ /// @param astream An execution stream.
191
+ /// @returns Underlying OpenCL queue.
192
+ inline cl_command_queue get_command_queue(const stream &astream) {
193
+ cl_command_queue queue = nullptr;
194
+ error::wrap_c_api(
195
+ dnnl_ocl_interop_stream_get_command_queue(astream.get(), &queue),
196
+ "could not get an OpenCL command queue from a stream");
197
+ return queue;
198
+ }
199
+
200
+ /// Returns the OpenCL memory object associated with the memory object.
201
+ ///
202
+ /// @param amemory A memory object.
203
+ /// @returns Underlying OpenCL memory object.
204
+ inline cl_mem get_mem_object(const memory &amemory) {
205
+ cl_mem mem_object;
206
+ error::wrap_c_api(
207
+ dnnl_ocl_interop_memory_get_mem_object(amemory.get(), &mem_object),
208
+ "could not get OpenCL buffer object from a memory object");
209
+ return mem_object;
210
+ }
211
+
212
+ /// Sets the OpenCL memory object associated with the memory object.
213
+ ///
214
+ /// For behavioral details see memory::set_data_handle().
215
+ ///
216
+ /// @param amemory A memory object.
217
+ /// @param mem_object OpenCL cl_mem object to use as the underlying
218
+ /// storage. It must have at least get_desc().get_size() bytes
219
+ /// allocated.
220
+ inline void set_mem_object(memory &amemory, cl_mem mem_object) {
221
+ error::wrap_c_api(
222
+ dnnl_ocl_interop_memory_set_mem_object(amemory.get(), mem_object),
223
+ "could not set OpenCL buffer object from a memory object");
224
+ }
225
+
226
+ /// Returns the memory allocation kind associated with a memory object.
227
+ ///
228
+ /// @param amemory A memory object.
229
+ ///
230
+ /// @returns The underlying memory allocation kind of the memory object.
231
+ inline memory_kind get_memory_kind(const memory &amemory) {
232
+ dnnl_ocl_interop_memory_kind_t ckind;
233
+ error::wrap_c_api(
234
+ dnnl_ocl_interop_memory_get_memory_kind(amemory.get(), &ckind),
235
+ "could not get memory kind");
236
+ return static_cast<memory_kind>(ckind);
237
+ }
238
+
239
+ /// Creates a memory object.
240
+ ///
241
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
242
+ /// constructed memory object will have the underlying buffer set. In this
243
+ /// case, the buffer will be initialized as if:
244
+ /// - dnnl::memory::set_data_handle() had been called, if @p memory_kind is
245
+ /// equal to dnnl::ocl_interop::memory_kind::usm, or
246
+ /// - dnnl::ocl_interop::set_mem_object() has been called, if @p memory_kind is
247
+ /// equal to dnnl::ocl_interop::memory_kind::buffer.
248
+ ///
249
+ /// @param memory_desc Memory descriptor.
250
+ /// @param aengine Engine to use.
251
+ /// @param kind Memory allocation kind to specify the type of handle.
252
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
253
+ /// - A USM pointer to the user-allocated buffer. In this case the library
254
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
255
+ /// dnnl::ocl_interop::memory_kind::usm.
256
+ /// - An OpenCL buffer. In this case the library doesn't own the buffer.
257
+ /// Requires @p memory_kind be equal to be equal to
258
+ /// dnnl::ocl_interop::memory_kind::buffer.
259
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
260
+ /// allocate the buffer that corresponds to the memory allocation kind
261
+ /// @p memory_kind for the memory object. In this case the library
262
+ /// owns the buffer.
263
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
264
+ /// create memory object without an underlying buffer.
265
+ ///
266
+ /// @returns Created memory object.
267
+ inline memory make_memory(const memory::desc &memory_desc,
268
+ const engine &aengine, memory_kind kind,
269
+ void *handle = DNNL_MEMORY_ALLOCATE) {
270
+ dnnl_memory_t c_memory;
271
+ error::wrap_c_api(
272
+ dnnl_ocl_interop_memory_create(&c_memory, memory_desc.get(),
273
+ aengine.get(), convert_to_c(kind), handle),
274
+ "could not create a memory");
275
+ return memory(c_memory);
276
+ }
277
+
278
+ /// Constructs a memory object from an OpenCL buffer.
279
+ ///
280
+ /// @param memory_desc Memory descriptor.
281
+ /// @param aengine Engine to use.
282
+ /// @param mem_object An OpenCL buffer to use.
283
+ ///
284
+ /// @returns Created memory object.
285
+ inline memory make_memory(const memory::desc &memory_desc,
286
+ const engine &aengine, cl_mem mem_object) {
287
+ memory amemory(memory_desc, aengine, DNNL_MEMORY_NONE);
288
+ set_mem_object(amemory, mem_object);
289
+ return amemory;
290
+ }
291
+
292
+ /// Executes computations specified by the primitive in a specified stream and
293
+ /// returns a SYCL event.
294
+ ///
295
+ /// Arguments are passed via an arguments map containing
296
+ /// <index, memory object> pairs. The index must be one of the `DNNL_ARG_*`
297
+ /// values such as `DNNL_ARG_SRC`, and the memory must have a memory descriptor
298
+ /// matching the one returned by
299
+ /// #dnnl::primitive_desc::query_md(#query::exec_arg_md, index) unless using
300
+ /// dynamic shapes (see #DNNL_RUNTIME_DIM_VAL).
301
+ ///
302
+ /// @param aprimitive Primitive to execute.
303
+ /// @param astream Stream object. The stream must belong to the same engine
304
+ /// as the primitive.
305
+ /// @param args Arguments map.
306
+ /// @param deps Optional vector with `cl_event` dependencies.
307
+ ///
308
+ /// @returns Output event. It's the user's responsibility to manage lifetime
309
+ /// of the event.
310
+ inline cl_event execute(const dnnl::primitive &aprimitive,
311
+ const stream &astream, const std::unordered_map<int, memory> &args,
312
+ const std::vector<cl_event> &deps = {}) {
313
+ std::vector<dnnl_exec_arg_t> c_args;
314
+ c_args.reserve(args.size());
315
+ for (const auto &a : args)
316
+ c_args.push_back({a.first, a.second.get()});
317
+
318
+ const cl_event *c_deps = deps.empty() ? nullptr : deps.data();
319
+
320
+ cl_event return_event;
321
+ error::wrap_c_api(dnnl_ocl_interop_primitive_execute(aprimitive.get(),
322
+ astream.get(), (int)c_args.size(), c_args.data(),
323
+ c_deps, (int)deps.size(), &return_event),
324
+ "could not execute a primitive");
325
+ return return_event;
326
+ }
327
+
328
+ } // namespace ocl_interop
329
+
330
+ /// @} dnnl_api_ocl_interop
331
+
332
+ /// @} dnnl_api_interop
333
+
334
+ } // namespace dnnl
335
+
336
+ /// @} dnnl_api
337
+
338
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_ocl_types.h ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2021 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_OCL_TYPES_H
18
+ #define ONEAPI_DNNL_DNNL_OCL_TYPES_H
19
+
20
+ #ifdef __cplusplus
21
+ extern "C" {
22
+ #endif
23
+
24
+ /// @addtogroup dnnl_api
25
+ /// @{
26
+
27
+ /// @addtogroup dnnl_api_interop
28
+ /// @{
29
+
30
+ /// @addtogroup dnnl_api_ocl_interop
31
+ /// @{
32
+
33
+ /// Memory allocation kind.
34
+ typedef enum {
35
+ /// USM (device, shared, host, or unknown) memory allocation kind.
36
+ dnnl_ocl_interop_usm,
37
+ /// Buffer memory allocation kind - default.
38
+ dnnl_ocl_interop_buffer,
39
+ } dnnl_ocl_interop_memory_kind_t;
40
+
41
+ /// @} dnnl_api_ocl_interop
42
+
43
+ /// @} dnnl_api_interop
44
+
45
+ /// @} dnnl_api
46
+
47
+ #ifdef __cplusplus
48
+ }
49
+ #endif
50
+
51
+ #endif
deps/exla/cache/xla_extension/include/include/oneapi/dnnl/dnnl_sycl.h ADDED
@@ -0,0 +1,169 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*******************************************************************************
2
+ * Copyright 2020-2022 Intel Corporation
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ *******************************************************************************/
16
+
17
+ #ifndef ONEAPI_DNNL_DNNL_SYCL_H
18
+ #define ONEAPI_DNNL_DNNL_SYCL_H
19
+
20
+ #include "oneapi/dnnl/dnnl.h"
21
+
22
+ #include "oneapi/dnnl/dnnl_sycl_types.h"
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ /// @addtogroup dnnl_api
29
+ /// @{
30
+
31
+ /// @addtogroup dnnl_api_interop
32
+ /// @{
33
+
34
+ /// @addtogroup dnnl_api_sycl_interop
35
+ /// @{
36
+
37
+ /// Creates an engine associated with a SYCL device and a SYCL context.
38
+ ///
39
+ /// @param engine Output engine.
40
+ /// @param device Pointer to the SYCL device to use for the engine.
41
+ /// @param context Pointer to the SYCL context to use for the engine.
42
+ /// @returns #dnnl_success on success and a status describing the error
43
+ /// otherwise.
44
+ dnnl_status_t DNNL_API dnnl_sycl_interop_engine_create(
45
+ dnnl_engine_t *engine, const void *device, const void *context);
46
+
47
+ /// Returns the SYCL context associated with an engine.
48
+ ///
49
+ /// @param engine Engine to query.
50
+ /// @param context Pointer to the underlying SYCL context of the engine.
51
+ /// @returns #dnnl_success on success and a status describing the error
52
+ /// otherwise.
53
+ dnnl_status_t DNNL_API dnnl_sycl_interop_engine_get_context(
54
+ dnnl_engine_t engine, void **context);
55
+
56
+ /// Returns the SYCL device associated with an engine.
57
+ ///
58
+ /// @param engine Engine to query.
59
+ /// @param device Pointer to the underlying SYCL device of the engine.
60
+ /// @returns #dnnl_success on success and a status describing the error
61
+ /// otherwise.
62
+ dnnl_status_t DNNL_API dnnl_sycl_interop_engine_get_device(
63
+ dnnl_engine_t engine, void **device);
64
+
65
+ /// Creates a memory object.
66
+ ///
67
+ /// Unless @p handle is equal to DNNL_MEMORY_NONE or DNNL_MEMORY_ALLOCATE, the
68
+ /// constructed memory object will have the underlying buffer set. In this
69
+ /// case, the buffer will be initialized as if:
70
+ /// - dnnl_memory_set_data_handle() had been called, if @p memory_kind is equal
71
+ /// to dnnl_sycl_interop_usm, or
72
+ /// - dnnl_sycl_interop_memory_set_buffer() has been called, if @p memory_kind
73
+ /// is equal to dnnl_sycl_interop_buffer.
74
+ ///
75
+ /// @param memory Output memory object.
76
+ /// @param memory_desc Memory descriptor.
77
+ /// @param engine Engine to use.
78
+ /// @param memory_kind Memory allocation kind to specify the type of handle.
79
+ /// @param handle Handle of the memory buffer to use as an underlying storage.
80
+ /// - A USM pointer to the user-allocated buffer. In this case the library
81
+ /// doesn't own the buffer. Requires @p memory_kind to be equal to
82
+ /// dnnl_sycl_interop_usm.
83
+ /// - A pointer to SYCL buffer. In this case the library doesn't own the
84
+ /// buffer. Requires @p memory_kind be equal to be equal to
85
+ /// dnnl_sycl_interop_buffer.
86
+ /// - The DNNL_MEMORY_ALLOCATE special value. Instructs the library to
87
+ /// allocate the buffer that corresponds to the memory allocation kind
88
+ /// @p memory_kind for the memory object. In this case the library
89
+ /// owns the buffer.
90
+ /// - The DNNL_MEMORY_NONE specific value. Instructs the library to
91
+ /// create memory object without an underlying buffer.
92
+ /// @returns #dnnl_success on success and a status describing the error
93
+ /// otherwise.
94
+ dnnl_status_t DNNL_API dnnl_sycl_interop_memory_create(dnnl_memory_t *memory,
95
+ const_dnnl_memory_desc_t memory_desc, dnnl_engine_t engine,
96
+ dnnl_sycl_interop_memory_kind_t memory_kind, void *handle);
97
+
98
+ /// Returns the memory allocation kind associated with a memory object.
99
+ ///
100
+ /// @param memory Memory to query.
101
+ /// @param memory_kind Output underlying memory allocation kind of the memory
102
+ /// object.
103
+ /// @returns #dnnl_success on success and a status describing the error
104
+ /// otherwise.
105
+ dnnl_status_t DNNL_API dnnl_sycl_interop_memory_get_memory_kind(
106
+ const_dnnl_memory_t memory,
107
+ dnnl_sycl_interop_memory_kind_t *memory_kind);
108
+
109
+ /// Sets a SYCL buffer for a memory object.
110
+ ///
111
+ /// @param memory Memory object.
112
+ /// @param buffer SYCL buffer to be set in the memory object.
113
+ /// @returns #dnnl_success on success and a status describing the error
114
+ /// otherwise.
115
+ dnnl_status_t DNNL_API dnnl_sycl_interop_memory_set_buffer(
116
+ dnnl_memory_t memory, void *buffer);
117
+
118
+ /// Creates an execution stream for a given engine associated with a SYCL
119
+ /// queue.
120
+ ///
121
+ /// @param stream Output execution stream.
122
+ /// @param engine Engine to create the execution stream on.
123
+ /// @param queue SYCL queue to use.
124
+ /// @returns #dnnl_success on success and a status describing the error
125
+ /// otherwise.
126
+ dnnl_status_t DNNL_API dnnl_sycl_interop_stream_create(
127
+ dnnl_stream_t *stream, dnnl_engine_t engine, void *queue);
128
+
129
+ /// Returns the SYCL queue associated with an execution stream.
130
+ ///
131
+ /// @param stream Execution stream to query.
132
+ /// @param queue Output SYCL command queue.
133
+ /// @returns #dnnl_success on success and a status describing the error
134
+ /// otherwise.
135
+ dnnl_status_t DNNL_API dnnl_sycl_interop_stream_get_queue(
136
+ dnnl_stream_t stream, void **queue);
137
+
138
+ /// Executes computations specified by the primitive in a specified stream and
139
+ /// returns a SYCL event.
140
+ ///
141
+ /// @param primitive Primitive to execute.
142
+ /// @param stream Stream to use.
143
+ /// @param nargs Number of arguments.
144
+ /// @param args Array of arguments. Each argument is an
145
+ /// <index, #dnnl_memory_t> pair. The index is one of the `DNNL_ARG_*`
146
+ /// values such as `DNNL_ARG_SRC`. Unless runtime shapes are used (see
147
+ /// #DNNL_RUNTIME_DIM_VAL), the memory object must have the same memory
148
+ /// descriptor as that returned by
149
+ /// #dnnl_primitive_desc_query_md(#dnnl_query_exec_arg_md, index).
150
+ /// @param deps A pointer to std::vector<sycl::event> that contains
151
+ /// dependencies.
152
+ /// @param return_event Output event.
153
+ /// @returns #dnnl_success on success and a status describing the error
154
+ /// otherwise.
155
+ dnnl_status_t DNNL_API dnnl_sycl_interop_primitive_execute(
156
+ const_dnnl_primitive_t primitive, dnnl_stream_t stream, int nargs,
157
+ const dnnl_exec_arg_t *args, const void *deps, void *return_event);
158
+
159
+ /// @} dnnl_api_sycl_interop
160
+
161
+ /// @} dnnl_api_interop
162
+
163
+ /// @} dnnl_api
164
+
165
+ #ifdef __cplusplus
166
+ }
167
+ #endif
168
+
169
+ #endif