d09ca72f74
SWDEV-79445 - OCL generic changes and code clean-up 1. This change replaces the use of std::map with std::unordered_map to improve lookup/insert time. 2. Replace the use of std::make_pair and std::pair constructor with uniform initialization for cleaner code. 3. Replace the use of std::Container::iterator type with the auto keyword for cleaner code. 4. Use range based for loops where needed. ReviewBoardURL = http://ocltc.amd.com/reviews/r/14517/diff/ Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#4 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#58 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10.cpp#16 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp#9 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11.cpp#24 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp#13 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9.cpp#34 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp#17 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_gl.cpp#57 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_pipe.cpp#7 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_program.cpp#46 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_svm.cpp#23 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/appprofile.hpp#14 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuprogram.cpp#72 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuvirtual.cpp#27 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#216 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#297 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuappprofile.cpp#13 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpubinary.cpp#59 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpucompiler.cpp#158 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#587 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.cpp#322 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprintf.cpp#46 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#237 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#70 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#242 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#415 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.hpp#143 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palappprofile.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#22 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#79 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprintf.cpp#9 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#59 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#60 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#84 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.hpp#46 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/CMakeLists.txt#11 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/pro/prodevice.cpp#4 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/pro/prodevice.hpp#5 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocbinary.hpp#6 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#42 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccounters.cpp#3 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprintf.cpp#10 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#81 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#81 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#89 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/commandqueue.cpp#24 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#49 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/context.hpp#29 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#129 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#102 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/perfctr.hpp#7 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#91 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/program.hpp#43 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/sampler.hpp#9 edit ... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.cpp#17 edit
180 lines
3.8 KiB
C++
180 lines
3.8 KiB
C++
//
|
|
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
|
|
#include "top.hpp"
|
|
#include "utils/flags.hpp"
|
|
|
|
#include <unordered_map>
|
|
#include <string>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
#include <tchar.h>
|
|
#else
|
|
#include <unistd.h>
|
|
#endif // !_WIN32
|
|
|
|
namespace {
|
|
|
|
const char* removeQuotes(const char* Value) {
|
|
const char *b, *e, *p;
|
|
if (Value == NULL) {
|
|
return Value;
|
|
}
|
|
|
|
// skip the leading blank
|
|
for (p = Value; *p == ' '; ++p)
|
|
;
|
|
if (*p != '"') {
|
|
return Value;
|
|
}
|
|
b = p;
|
|
e = NULL;
|
|
for (++p; *p != '\0'; ++p) {
|
|
if (*p == '"') {
|
|
// e points to the last '"'
|
|
e = p;
|
|
} else if ((e != NULL) && (*p != ' ')) {
|
|
// e isn't last '"' if there is any non-blank following e
|
|
e = NULL;
|
|
}
|
|
}
|
|
|
|
if (e == NULL) {
|
|
return Value;
|
|
}
|
|
// Found a valid quoted string "<str>" with b=1st '"' and e=the last '"'
|
|
size_t len = (e - b - 1) > 0 ? (e - b - 1) : 0;
|
|
#ifdef _WIN32
|
|
char* p1 = _strdup(b + 1);
|
|
p1[len] = '\0';
|
|
p = p1;
|
|
#else
|
|
p = strndup(b + 1, len);
|
|
#endif
|
|
return p;
|
|
}
|
|
}
|
|
|
|
namespace amd {
|
|
|
|
#ifdef __APPLE__
|
|
#include <crt_externs.h>
|
|
#endif // __APPLE__
|
|
|
|
// static
|
|
char* Flag::envstr_;
|
|
|
|
void Flag::tearDown() {
|
|
#ifdef _WIN32
|
|
FreeEnvironmentStringsA(envstr_);
|
|
#endif
|
|
}
|
|
|
|
bool Flag::init() {
|
|
typedef std::unordered_map<std::string, const char*> vars_type;
|
|
vars_type vars;
|
|
|
|
#ifdef _WIN32
|
|
char* str = GetEnvironmentStringsA();
|
|
envstr_ = str;
|
|
|
|
for (; *str != '\0'; str += strlen(str) + 1) {
|
|
// For all environment variables:
|
|
std::string var = str;
|
|
size_t pos = var.find('=');
|
|
if ((pos == std::string::npos) || ((pos + 1) >= var.size())) {
|
|
continue;
|
|
}
|
|
|
|
std::string name = var.substr(0, pos);
|
|
vars.insert(std::make_pair(name, &str[pos + 1]));
|
|
}
|
|
#else // !_WIN32
|
|
#ifdef __APPLE__
|
|
char** environ = *_NSGetEnviron();
|
|
if (environ == NULL) {
|
|
return false;
|
|
}
|
|
#endif // __APPLE__
|
|
|
|
for (const char** p = const_cast<const char**>(environ); *p != NULL; ++p) {
|
|
std::string var = *p;
|
|
size_t pos = var.find('=');
|
|
if ((pos == std::string::npos) || ((pos + 1) >= var.size())) {
|
|
continue;
|
|
}
|
|
|
|
std::string name = var.substr(0, pos);
|
|
vars.insert(std::make_pair(name, &(*p)[pos + 1]));
|
|
}
|
|
#endif // !_WIN32
|
|
|
|
for (size_t i = 0; i < numFlags_; ++i) {
|
|
Flag& flag = flags_[i];
|
|
|
|
const auto it = vars.find(flag.name_);
|
|
if (it != vars.cend()) {
|
|
flag.setValue(it->second);
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool Flag::setValue(const char* value) {
|
|
if (value_ == NULL) {
|
|
return false; // flag is constant.
|
|
}
|
|
|
|
isDefault_ = false;
|
|
|
|
switch (type_) {
|
|
case Tbool:
|
|
*(bool*)value_ = (strcmp(value, "true") == 0 || atoi(value) != 0) ? true : false;
|
|
return true;
|
|
|
|
case Tint:
|
|
case Tuint:
|
|
*(int*)value_ = atoi(value);
|
|
return true;
|
|
|
|
case Tsize_t:
|
|
*(size_t*)value_ = atol(value);
|
|
return true;
|
|
|
|
case Tcstring:
|
|
*(const char**)value_ = removeQuotes(value);
|
|
return true;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
ShouldNotReachHere();
|
|
return false;
|
|
}
|
|
|
|
#define DEFINE_RELEASE_FLAG_STRUCT(type, name, value, help) {#name, &name, T##type, true},
|
|
#define DEFINE_DEBUG_FLAG_STRUCT(type, name, value, help) \
|
|
{#name, RELEASE_ONLY(NULL) DEBUG_ONLY(&name), T##type, true},
|
|
|
|
Flag Flag::flags_[] = {
|
|
RUNTIME_FLAGS(DEFINE_DEBUG_FLAG_STRUCT, DEFINE_RELEASE_FLAG_STRUCT, DEFINE_DEBUG_FLAG_STRUCT)
|
|
{NULL, NULL, Tinvalid, true}};
|
|
|
|
#undef DEFINE_DEBUG_FLAG_STRUCT
|
|
#undef DEFINE_RELEASE_FLAG_STRUCT
|
|
|
|
} // namespace amd
|
|
|
|
#define DEFINE_RELEASE_FLAG_VALUE(type, name, value, help) type name = value;
|
|
#define DEFINE_DEBUG_FLAG_VALUE(type, name, value, help) DEBUG_ONLY(type name = value);
|
|
|
|
RUNTIME_FLAGS(DEFINE_DEBUG_FLAG_VALUE, DEFINE_RELEASE_FLAG_VALUE, DEFINE_DEBUG_FLAG_VALUE);
|
|
|
|
#undef DEFINE_DEBUG_FLAG_VALUE
|
|
#undef DEFINE_RELEASE_FLAG_VALUE
|