-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathcompiler_options_parser.cpp
More file actions
85 lines (69 loc) · 3.13 KB
/
compiler_options_parser.cpp
File metadata and controls
85 lines (69 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/compiler_options_parser.h"
#include "shared/source/compiler_interface/compiler_options.h"
#include "shared/source/compiler_interface/oclc_extensions.h"
#include "shared/source/helpers/compiler_product_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/release_helper/release_helper.h"
#include <cstdint>
#include <sstream>
namespace NEO {
const std::string clStdOptionName = "-cl-std=CL";
uint32_t getMajorVersion(const std::string &compileOptions) {
auto clStdValuePosition = compileOptions.find(clStdOptionName);
if (clStdValuePosition == std::string::npos) {
return 0;
}
uint32_t majorVersion;
const std::string_view opt(compileOptions.c_str() + clStdValuePosition + clStdOptionName.size());
if (opt.find("CLC++") == 0 || opt.find("CLC++1.0") == 0) {
majorVersion = 2;
} else if (opt.find("CLC++2021") == 0) {
majorVersion = 3;
} else {
std::stringstream ss{compileOptions.c_str() + clStdValuePosition + clStdOptionName.size()};
ss >> majorVersion;
}
return majorVersion;
}
bool requiresOpenClCFeatures(const std::string &compileOptions) {
return (getMajorVersion(compileOptions) >= 3);
}
bool requiresAdditionalExtensions(const std::string &compileOptions) {
return (getMajorVersion(compileOptions) == 2);
}
void appendAdditionalExtensions(std::string &extensions, const std::string &compileOptions, const std::string &internalOptions) {
if (requiresAdditionalExtensions(compileOptions)) {
extensions.erase(extensions.length() - 1);
extensions += ",+cl_khr_3d_image_writes ";
}
if (std::string::npos != internalOptions.find("-cl-fp64-gen-emu")) {
extensions.erase(extensions.length() - 1);
extensions += ",+__opencl_c_fp64,+cl_khr_fp64 ";
}
}
void appendExtensionsToInternalOptions(const HardwareInfo &hwInfo, const std::string &options, std::string &internalOptions) {
auto compilerProductHelper = CompilerProductHelper::create(hwInfo.platform.eProductFamily);
UNRECOVERABLE_IF(!compilerProductHelper);
auto releaseHelper = ReleaseHelper::create(hwInfo.ipVersion);
std::string extensionsList = compilerProductHelper->getDeviceExtensions(hwInfo, releaseHelper.get());
if (requiresAdditionalExtensions(options)) {
extensionsList += "cl_khr_3d_image_writes ";
}
OpenClCFeaturesContainer openclCFeatures;
if (requiresOpenClCFeatures(options)) {
getOpenclCFeaturesList(hwInfo, openclCFeatures, *compilerProductHelper.get(), releaseHelper.get());
}
auto compilerExtensions = convertEnabledExtensionsToCompilerInternalOptions(extensionsList.c_str(), openclCFeatures);
auto oclVersion = getOclVersionCompilerInternalOption(hwInfo.capabilityTable.clVersionSupport);
internalOptions = CompilerOptions::concatenate(oclVersion, compilerExtensions, internalOptions);
if (hwInfo.capabilityTable.supportsImages) {
CompilerOptions::concatenateAppend(internalOptions, CompilerOptions::enableImageSupport);
}
}
} // namespace NEO