Skip to content

Commit 029a977

Browse files
authored
Merge pull request #1536 from ldrumm/unified-clang-format
Unified clang format
2 parents 222e4b1 + 041179a commit 029a977

File tree

465 files changed

+108279
-105705
lines changed

Some content is hidden

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

465 files changed

+108279
-105705
lines changed

.clang-format

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
---
22
Language: Cpp
33
BasedOnStyle: LLVM
4-
IndentWidth: 4
5-
InsertBraces: true
6-
ReflowComments: false
74
...

.editorconfig

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
[*]
22
indent_style = space
3+
indent_size = 2
4+
5+
[*.py]
36
indent_size = 4
47

5-
[.github/workflows/*.yml]
6-
indent_size = 2
8+
[scripts/core/*]
9+
indent_size = 4
10+
11+
[CMakeLists.txt]
12+
indent_size = 4
13+
14+
[*.cmake]
15+
indent_size = 4

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ endif()
236236

237237
# Check if clang-format (in correct version) is available for Cpp code formatting.
238238
if(UR_FORMAT_CPP_STYLE)
239-
find_program(CLANG_FORMAT NAMES clang-format-15 clang-format-15.0 clang-format)
239+
find_program(CLANG_FORMAT NAMES clang-format-18 clang-format-18.1 clang-format)
240240

241241
if(CLANG_FORMAT)
242242
get_program_version_major_minor(${CLANG_FORMAT} CLANG_FORMAT_VERSION)
243243
message(STATUS "Found clang-format: ${CLANG_FORMAT} (version: ${CLANG_FORMAT_VERSION})")
244244

245-
set(CLANG_FORMAT_REQUIRED "15.0")
245+
set(CLANG_FORMAT_REQUIRED "18.1")
246246
if(NOT (CLANG_FORMAT_VERSION VERSION_EQUAL CLANG_FORMAT_REQUIRED))
247247
message(FATAL_ERROR "required clang-format version is ${CLANG_FORMAT_REQUIRED}")
248248
endif()

REQUIREMENTS.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
## API and Library Requirements
44

55
### API Namespace
6-
* API’s will clearly define the functionality
7-
* API’s will use a consistent style within the library
8-
* APIs will not allow namespace collision when multiple libraries are linked in the same user application
6+
* APIs will clearly define the functionality
7+
* APIs will use a consistent style within the library
8+
* APIs will not allow namespace collision when multiple libraries are linked in the same user application
99
* API will be consistent across libraries included in the product
1010
* Will not allow namespace collision when multiple libraries are linked in the same user application
1111
* Exceptions:

examples/codegen/codegen.cpp

+130-128
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22
*
33
* Copyright (C) 2023 Intel Corporation
44
*
5-
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
6-
* See LICENSE.TXT
5+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
6+
* Exceptions. See LICENSE.TXT
7+
*
78
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
89
*
910
* @file codegen.cpp
1011
*
11-
* @brief UR code generation and execution example for use with the Level Zero adapter.
12+
* @brief UR code generation and execution example for use with the Level Zero
13+
* adapter.
1214
*
1315
* The codegen example demonstrates a complete flow for generating LLVM IR,
14-
* translating it to SPIR-V, and submitting the kernel to Level Zero Runtime via UR API.
16+
* translating it to SPIR-V, and submitting the kernel to Level Zero Runtime via
17+
* UR API.
1518
*/
1619

1720
#include <iostream>
@@ -23,154 +26,153 @@
2326
constexpr unsigned PAGE_SIZE = 4096;
2427

2528
void ur_check(const ur_result_t r) {
26-
if (r != UR_RESULT_SUCCESS) {
27-
urLoaderTearDown();
28-
throw std::runtime_error("Unified runtime error: " + std::to_string(r));
29-
}
29+
if (r != UR_RESULT_SUCCESS) {
30+
urLoaderTearDown();
31+
throw std::runtime_error("Unified runtime error: " + std::to_string(r));
32+
}
3033
}
3134

3235
std::vector<ur_adapter_handle_t> get_adapters() {
33-
uint32_t adapterCount = 0;
34-
ur_check(urAdapterGet(0, nullptr, &adapterCount));
36+
uint32_t adapterCount = 0;
37+
ur_check(urAdapterGet(0, nullptr, &adapterCount));
3538

36-
if (!adapterCount) {
37-
throw std::runtime_error("No adapters available.");
38-
}
39+
if (!adapterCount) {
40+
throw std::runtime_error("No adapters available.");
41+
}
3942

40-
std::vector<ur_adapter_handle_t> adapters(adapterCount);
41-
ur_check(urAdapterGet(adapterCount, adapters.data(), nullptr));
42-
return adapters;
43+
std::vector<ur_adapter_handle_t> adapters(adapterCount);
44+
ur_check(urAdapterGet(adapterCount, adapters.data(), nullptr));
45+
return adapters;
4346
}
4447

4548
std::vector<ur_adapter_handle_t>
4649
get_supported_adapters(std::vector<ur_adapter_handle_t> &adapters) {
47-
std::vector<ur_adapter_handle_t> supported_adapters;
48-
for (auto adapter : adapters) {
49-
ur_adapter_backend_t backend;
50-
ur_check(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
51-
sizeof(ur_adapter_backend_t), &backend,
52-
nullptr));
53-
54-
if (backend == UR_ADAPTER_BACKEND_LEVEL_ZERO) {
55-
supported_adapters.push_back(adapter);
56-
}
50+
std::vector<ur_adapter_handle_t> supported_adapters;
51+
for (auto adapter : adapters) {
52+
ur_adapter_backend_t backend;
53+
ur_check(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
54+
sizeof(ur_adapter_backend_t), &backend, nullptr));
55+
56+
if (backend == UR_ADAPTER_BACKEND_LEVEL_ZERO) {
57+
supported_adapters.push_back(adapter);
5758
}
59+
}
5860

59-
return supported_adapters;
61+
return supported_adapters;
6062
}
6163

6264
std::vector<ur_platform_handle_t>
6365
get_platforms(std::vector<ur_adapter_handle_t> &adapters) {
64-
uint32_t platformCount = 0;
65-
ur_check(urPlatformGet(adapters.data(), adapters.size(), 1, nullptr,
66-
&platformCount));
67-
68-
if (!platformCount) {
69-
throw std::runtime_error("No platforms available.");
70-
}
71-
72-
std::vector<ur_platform_handle_t> platforms(platformCount);
73-
ur_check(urPlatformGet(adapters.data(), adapters.size(), platformCount,
74-
platforms.data(), nullptr));
75-
return platforms;
66+
uint32_t platformCount = 0;
67+
ur_check(urPlatformGet(adapters.data(), adapters.size(), 1, nullptr,
68+
&platformCount));
69+
70+
if (!platformCount) {
71+
throw std::runtime_error("No platforms available.");
72+
}
73+
74+
std::vector<ur_platform_handle_t> platforms(platformCount);
75+
ur_check(urPlatformGet(adapters.data(), adapters.size(), platformCount,
76+
platforms.data(), nullptr));
77+
return platforms;
7678
}
7779

7880
std::vector<ur_device_handle_t> get_gpus(ur_platform_handle_t p) {
79-
uint32_t deviceCount = 0;
80-
ur_check(urDeviceGet(p, UR_DEVICE_TYPE_GPU, 0, nullptr, &deviceCount));
81+
uint32_t deviceCount = 0;
82+
ur_check(urDeviceGet(p, UR_DEVICE_TYPE_GPU, 0, nullptr, &deviceCount));
8183

82-
if (!deviceCount) {
83-
throw std::runtime_error("No GPUs available.");
84-
}
84+
if (!deviceCount) {
85+
throw std::runtime_error("No GPUs available.");
86+
}
8587

86-
std::vector<ur_device_handle_t> devices(deviceCount);
87-
ur_check(urDeviceGet(p, UR_DEVICE_TYPE_GPU, deviceCount, devices.data(),
88-
nullptr));
89-
return devices;
88+
std::vector<ur_device_handle_t> devices(deviceCount);
89+
ur_check(
90+
urDeviceGet(p, UR_DEVICE_TYPE_GPU, deviceCount, devices.data(), nullptr));
91+
return devices;
9092
}
9193

9294
template <typename T, size_t N> struct alignas(PAGE_SIZE) AlignedArray {
93-
T data[N];
95+
T data[N];
9496
};
9597

9698
int main() {
97-
ur_loader_config_handle_t loader_config = nullptr;
98-
ur_check(urLoaderInit(UR_DEVICE_INIT_FLAG_GPU, loader_config));
99-
100-
auto adapters = get_adapters();
101-
auto supported_adapters = get_supported_adapters(adapters);
102-
auto platforms = get_platforms(supported_adapters);
103-
auto gpus = get_gpus(platforms.front());
104-
auto spv = generate_plus_one_spv();
105-
106-
constexpr int a_size = 32;
107-
AlignedArray<int, a_size> a, b;
108-
for (auto i = 0; i < a_size; ++i) {
109-
a.data[i] = a_size - i;
110-
b.data[i] = i;
111-
}
112-
113-
auto current_device = gpus.front();
114-
115-
ur_context_handle_t hContext;
116-
ur_check(urContextCreate(1, &current_device, nullptr, &hContext));
117-
118-
ur_program_handle_t hProgram;
119-
ur_check(urProgramCreateWithIL(hContext, spv.data(), spv.size(), nullptr,
120-
&hProgram));
121-
ur_check(urProgramBuild(hContext, hProgram, nullptr));
122-
123-
ur_mem_handle_t dA, dB;
124-
ur_check(urMemBufferCreate(hContext, UR_MEM_FLAG_READ_WRITE,
125-
a_size * sizeof(int), nullptr, &dA));
126-
ur_check(urMemBufferCreate(hContext, UR_MEM_FLAG_READ_WRITE,
127-
a_size * sizeof(int), nullptr, &dB));
128-
129-
ur_kernel_handle_t hKernel;
130-
ur_check(urKernelCreate(hProgram, "plus1", &hKernel));
131-
ur_check(urKernelSetArgMemObj(hKernel, 0, nullptr, dA));
132-
ur_check(urKernelSetArgMemObj(hKernel, 1, nullptr, dB));
133-
134-
ur_queue_handle_t queue;
135-
ur_check(urQueueCreate(hContext, current_device, nullptr, &queue));
136-
137-
ur_check(urEnqueueMemBufferWrite(queue, dA, true, 0, a_size * sizeof(int),
138-
a.data, 0, nullptr, nullptr));
139-
ur_check(urEnqueueMemBufferWrite(queue, dB, true, 0, a_size * sizeof(int),
140-
b.data, 0, nullptr, nullptr));
141-
142-
const size_t gWorkOffset[] = {0, 0, 0};
143-
const size_t gWorkSize[] = {128, 1, 1};
144-
const size_t lWorkSize[] = {1, 1, 1};
145-
ur_event_handle_t event;
146-
ur_check(urEnqueueKernelLaunch(queue, hKernel, 3, gWorkOffset, gWorkSize,
147-
lWorkSize, 0, nullptr, &event));
148-
149-
ur_check(urEnqueueMemBufferRead(queue, dB, true, 0, a_size * sizeof(int),
150-
b.data, 1, &event, nullptr));
151-
152-
ur_check(urQueueFinish(queue));
153-
154-
std::cout << "Input Array: ";
155-
for (int i = 0; i < a_size; ++i) {
156-
std::cout << a.data[i] << " ";
157-
}
158-
std::cout << std::endl;
159-
160-
bool expectedResult = false;
161-
162-
std::cout << "Output Array: ";
163-
for (int i = 0; i < a_size; ++i) {
164-
std::cout << b.data[i] << " ";
165-
expectedResult |= (b.data[i] == a.data[i] + 1);
166-
}
167-
std::cout << std::endl;
168-
169-
if (expectedResult) {
170-
std::cout << "Results are correct." << std::endl;
171-
} else {
172-
std::cout << "Results are incorrect." << std::endl;
173-
}
174-
175-
return urLoaderTearDown() == UR_RESULT_SUCCESS && expectedResult ? 0 : 1;
99+
ur_loader_config_handle_t loader_config = nullptr;
100+
ur_check(urLoaderInit(UR_DEVICE_INIT_FLAG_GPU, loader_config));
101+
102+
auto adapters = get_adapters();
103+
auto supported_adapters = get_supported_adapters(adapters);
104+
auto platforms = get_platforms(supported_adapters);
105+
auto gpus = get_gpus(platforms.front());
106+
auto spv = generate_plus_one_spv();
107+
108+
constexpr int a_size = 32;
109+
AlignedArray<int, a_size> a, b;
110+
for (auto i = 0; i < a_size; ++i) {
111+
a.data[i] = a_size - i;
112+
b.data[i] = i;
113+
}
114+
115+
auto current_device = gpus.front();
116+
117+
ur_context_handle_t hContext;
118+
ur_check(urContextCreate(1, &current_device, nullptr, &hContext));
119+
120+
ur_program_handle_t hProgram;
121+
ur_check(urProgramCreateWithIL(hContext, spv.data(), spv.size(), nullptr,
122+
&hProgram));
123+
ur_check(urProgramBuild(hContext, hProgram, nullptr));
124+
125+
ur_mem_handle_t dA, dB;
126+
ur_check(urMemBufferCreate(hContext, UR_MEM_FLAG_READ_WRITE,
127+
a_size * sizeof(int), nullptr, &dA));
128+
ur_check(urMemBufferCreate(hContext, UR_MEM_FLAG_READ_WRITE,
129+
a_size * sizeof(int), nullptr, &dB));
130+
131+
ur_kernel_handle_t hKernel;
132+
ur_check(urKernelCreate(hProgram, "plus1", &hKernel));
133+
ur_check(urKernelSetArgMemObj(hKernel, 0, nullptr, dA));
134+
ur_check(urKernelSetArgMemObj(hKernel, 1, nullptr, dB));
135+
136+
ur_queue_handle_t queue;
137+
ur_check(urQueueCreate(hContext, current_device, nullptr, &queue));
138+
139+
ur_check(urEnqueueMemBufferWrite(queue, dA, true, 0, a_size * sizeof(int),
140+
a.data, 0, nullptr, nullptr));
141+
ur_check(urEnqueueMemBufferWrite(queue, dB, true, 0, a_size * sizeof(int),
142+
b.data, 0, nullptr, nullptr));
143+
144+
const size_t gWorkOffset[] = {0, 0, 0};
145+
const size_t gWorkSize[] = {128, 1, 1};
146+
const size_t lWorkSize[] = {1, 1, 1};
147+
ur_event_handle_t event;
148+
ur_check(urEnqueueKernelLaunch(queue, hKernel, 3, gWorkOffset, gWorkSize,
149+
lWorkSize, 0, nullptr, &event));
150+
151+
ur_check(urEnqueueMemBufferRead(queue, dB, true, 0, a_size * sizeof(int),
152+
b.data, 1, &event, nullptr));
153+
154+
ur_check(urQueueFinish(queue));
155+
156+
std::cout << "Input Array: ";
157+
for (int i = 0; i < a_size; ++i) {
158+
std::cout << a.data[i] << " ";
159+
}
160+
std::cout << std::endl;
161+
162+
bool expectedResult = false;
163+
164+
std::cout << "Output Array: ";
165+
for (int i = 0; i < a_size; ++i) {
166+
std::cout << b.data[i] << " ";
167+
expectedResult |= (b.data[i] == a.data[i] + 1);
168+
}
169+
std::cout << std::endl;
170+
171+
if (expectedResult) {
172+
std::cout << "Results are correct." << std::endl;
173+
} else {
174+
std::cout << "Results are incorrect." << std::endl;
175+
}
176+
177+
return urLoaderTearDown() == UR_RESULT_SUCCESS && expectedResult ? 0 : 1;
176178
}

0 commit comments

Comments
 (0)