diff --git a/Source/Api/Configuration/KernelConfiguration.cpp b/Source/Api/Configuration/KernelConfiguration.cpp index 11d22660..401c7e13 100644 --- a/Source/Api/Configuration/KernelConfiguration.cpp +++ b/Source/Api/Configuration/KernelConfiguration.cpp @@ -28,7 +28,34 @@ std::string KernelConfiguration::GeneratePrefix() const for (const auto& pair : m_Pairs) { - result += std::string("#define ") + pair.GetString() + std::string("\n"); + if (!pair.IsCompilerParameter()) + { + result += std::string("#define ") + pair.GetString() + std::string("\n"); + } + } + + return result; +} + +std::string KernelConfiguration::GetCompilerOptions() const +{ + std::string result; + + for (const auto& pair : m_Pairs) + { + if (!pair.IsCompilerParameter()) + { + continue; + } + + if (std::holds_alternative(pair.GetValue())) + { + result += " " + pair.GetName() + "=" + pair.GetValueString(); + } + else if (std::holds_alternative(pair.GetValue()) && std::get(pair.GetValue())) + { + result += " " + pair.GetName(); + } } return result; diff --git a/Source/Api/Configuration/KernelConfiguration.h b/Source/Api/Configuration/KernelConfiguration.h index 901e69ea..26db7ae6 100644 --- a/Source/Api/Configuration/KernelConfiguration.h +++ b/Source/Api/Configuration/KernelConfiguration.h @@ -43,10 +43,17 @@ class KTT_API KernelConfiguration /** @fn std::string GeneratePrefix() const * Generates kernel source preprocessor definitions from configuration. + * Parameters where IsCompilerParameter() is true are excluded. * @return Kernel source preprocessor definitions. */ std::string GeneratePrefix() const; + /** @fn std::string GetCompilerOptions() const + * Returns compiler options for parameters where IsCompilerParameter() is true. + * @return Compiler options for current configuration. + */ + std::string GetCompilerOptions() const; + /** @fn std::string GetString() const * Converts configuration to string. * @return String in format "parameter1String, parameter2String, ...". diff --git a/Source/Api/Configuration/ParameterPair.cpp b/Source/Api/Configuration/ParameterPair.cpp index 672015ee..dd3fa821 100644 --- a/Source/Api/Configuration/ParameterPair.cpp +++ b/Source/Api/Configuration/ParameterPair.cpp @@ -11,9 +11,10 @@ ParameterPair::ParameterPair() : m_Value(static_cast(0)) {} -ParameterPair::ParameterPair(const std::string& name, const ParameterValue& value) : +ParameterPair::ParameterPair(const std::string& name, const ParameterValue& value, const bool isCompilerParameter) : m_Name(name), - m_Value(value) + m_Value(value), + m_IsCompilerParameter(isCompilerParameter) {} void ParameterPair::SetValue(const ParameterValue& value) @@ -46,6 +47,10 @@ std::string ParameterPair::GetValueString() const return std::get(m_Value) ? "true" : "false"; case ParameterValueType::String: return std::get(m_Value); + case ParameterValueType::CompilerParameter: + if (std::holds_alternative(m_Value)) + return std::get(m_Value); + return std::get(m_Value) ? "set" : "notSet"; default: KttError("Unhandled parameter value type"); return ""; @@ -69,9 +74,18 @@ uint64_t ParameterPair::GetValueUint() const ParameterValueType ParameterPair::GetValueType() const { + if (this->IsCompilerParameter()) + { + return ParameterValueType::CompilerParameter; + } return GetTypeFromValue(m_Value); } +bool ParameterPair::IsCompilerParameter() const +{ + return m_IsCompilerParameter; +} + bool ParameterPair::HasSameValue(const ParameterPair& other) const { if (GetValueType() != other.GetValueType()) @@ -91,6 +105,8 @@ bool ParameterPair::HasSameValue(const ParameterPair& other) const return std::get(m_Value) == std::get(other.GetValue()); case ParameterValueType::String: return GetValueString() == other.GetValueString(); + case ParameterValueType::CompilerParameter: + return GetValueString() == other.GetValueString(); default: KttError("Unhandled parameter value type"); return false; diff --git a/Source/Api/Configuration/ParameterPair.h b/Source/Api/Configuration/ParameterPair.h index da46b708..328fd79c 100644 --- a/Source/Api/Configuration/ParameterPair.h +++ b/Source/Api/Configuration/ParameterPair.h @@ -26,12 +26,13 @@ class KTT_API ParameterPair */ ParameterPair(); - /** @fn explicit ParameterPair(const std::string& name, const ParameterValue& value) + /** @fn explicit ParameterPair(const std::string& name, const ParameterValue& value, const bool isCompilerParameter = false) * Constructor which creates a parameter pair with the specified value. * @param name Name of a kernel parameter tied to the pair. * @param value Value of a parameter. + * @param isCompilerParameter If true, this paramater is a compiler option rather than in the program prefix. */ - explicit ParameterPair(const std::string& name, const ParameterValue& value); + explicit ParameterPair(const std::string& name, const ParameterValue& value, const bool isCompilerParameter = false); /** @fn void SetValue(const ParameterValue& value) * Setter for parameter value. @@ -75,6 +76,12 @@ class KTT_API ParameterPair */ ParameterValueType GetValueType() const; + /** @fn bool IsCompilerParameter() const + * Returns whether this parameter is a compiler parameter + * @return True if parameter is a compiler parameter, false otherwise. + */ + bool IsCompilerParameter() const; + /** @fn bool HasSameValue(const ParameterPair& other) const * Checks if parameter value is same as other parameter value. * @param other Source for other value. @@ -110,6 +117,7 @@ class KTT_API ParameterPair private: std::string m_Name; ParameterValue m_Value; + bool m_IsCompilerParameter; }; } // namespace ktt diff --git a/Source/ComputeEngine/Cuda/CudaEngine.cpp b/Source/ComputeEngine/Cuda/CudaEngine.cpp index 6253be3b..d4c4090e 100644 --- a/Source/ComputeEngine/Cuda/CudaEngine.cpp +++ b/Source/ComputeEngine/Cuda/CudaEngine.cpp @@ -122,6 +122,8 @@ ComputeActionId CudaEngine::RunKernelAsync(const KernelComputeData& data, const ExceptionReason::DeviceLimitsExceeded); } + m_Configuration.SetTuningCompilerOptions(data.GetCompilerOptions()); + Timer timer; timer.Start(); @@ -790,7 +792,7 @@ void CudaEngine::SetCompilerOptions(const std::string& options, const bool overr finalOptions += GetDefaultCompilerOptions(); } - m_Configuration.SetCompilerOptions(finalOptions); + m_Configuration.SetStaticCompilerOptions(finalOptions); ClearKernelCache(); } diff --git a/Source/ComputeEngine/EngineConfiguration.cpp b/Source/ComputeEngine/EngineConfiguration.cpp index c103b095..16505c06 100644 --- a/Source/ComputeEngine/EngineConfiguration.cpp +++ b/Source/ComputeEngine/EngineConfiguration.cpp @@ -13,9 +13,14 @@ EngineConfiguration::EngineConfiguration(const GlobalSizeType sizeType) : m_ProfilingFlag(false) {} -void EngineConfiguration::SetCompilerOptions(const std::string& options) +void EngineConfiguration::SetStaticCompilerOptions(const std::string& options) { - m_CompilerOptions = options; + m_StaticCompilerOptions = options; +} + +void EngineConfiguration::SetTuningCompilerOptions(const std::string& options) +{ + m_TuningCompilerOptions = options; } void EngineConfiguration::SetGlobalSizeType(const GlobalSizeType sizeType) @@ -28,9 +33,9 @@ void EngineConfiguration::SetGlobalSizeCorrection(const bool sizeCorrection) m_GlobalSizeCorrection = sizeCorrection; } -const std::string& EngineConfiguration::GetCompilerOptions() const +std::string EngineConfiguration::GetCompilerOptions() const { - return m_CompilerOptions; + return m_StaticCompilerOptions + m_TuningCompilerOptions; } GlobalSizeType EngineConfiguration::GetGlobalSizeType() const diff --git a/Source/ComputeEngine/EngineConfiguration.h b/Source/ComputeEngine/EngineConfiguration.h index 4b6e352a..842a171a 100644 --- a/Source/ComputeEngine/EngineConfiguration.h +++ b/Source/ComputeEngine/EngineConfiguration.h @@ -13,11 +13,12 @@ class EngineConfiguration EngineConfiguration(); explicit EngineConfiguration(const GlobalSizeType sizeType); - void SetCompilerOptions(const std::string& options); + void SetStaticCompilerOptions(const std::string& options); + void SetTuningCompilerOptions(const std::string& options); void SetGlobalSizeType(const GlobalSizeType sizeType); void SetGlobalSizeCorrection(const bool sizeCorrection); - const std::string& GetCompilerOptions() const; + std::string GetCompilerOptions() const; GlobalSizeType GetGlobalSizeType() const; bool GetGlobalSizeCorrection() const; @@ -25,7 +26,8 @@ class EngineConfiguration void SetProfiling(const bool profiling); private: - std::string m_CompilerOptions; + std::string m_StaticCompilerOptions; + std::string m_TuningCompilerOptions; GlobalSizeType m_GlobalSizeType; bool m_GlobalSizeCorrection; bool m_ProfilingFlag; diff --git a/Source/ComputeEngine/KernelComputeData.cpp b/Source/ComputeEngine/KernelComputeData.cpp index 66bd91e9..b21d5184 100644 --- a/Source/ComputeEngine/KernelComputeData.cpp +++ b/Source/ComputeEngine/KernelComputeData.cpp @@ -19,7 +19,8 @@ KernelComputeData::KernelComputeData(const Kernel& kernel, const KernelDefinitio m_ConfigurationPrefix(configuration.GeneratePrefix()), m_TemplatedName(definition.GetTemplatedName()), m_Configuration(&configuration), - m_Arguments(definition.GetArguments()) + m_Arguments(definition.GetArguments()), + m_CompilerOptions(configuration.GetCompilerOptions()) { const auto id = definition.GetId(); const auto& pairs = configuration.GetPairs(); @@ -156,4 +157,9 @@ const std::vector& KernelComputeData::GetArguments() const return m_Arguments; } +const std::string& KernelComputeData::GetCompilerOptions() const +{ + return m_CompilerOptions; +} + } // namespace ktt diff --git a/Source/ComputeEngine/KernelComputeData.h b/Source/ComputeEngine/KernelComputeData.h index 66b11f7c..b09af15d 100644 --- a/Source/ComputeEngine/KernelComputeData.h +++ b/Source/ComputeEngine/KernelComputeData.h @@ -37,6 +37,7 @@ class KernelComputeData const KernelConfiguration& GetConfiguration() const; size_t GetArgumentIndex(const ArgumentId& id) const; const std::vector& GetArguments() const; + const std::string& GetCompilerOptions() const; private: std::string m_Name; @@ -47,6 +48,7 @@ class KernelComputeData DimensionVector m_LocalSize; const KernelConfiguration* m_Configuration; std::vector m_Arguments; + std::string m_CompilerOptions; }; } // namespace ktt diff --git a/Source/ComputeEngine/OpenCl/OpenClEngine.cpp b/Source/ComputeEngine/OpenCl/OpenClEngine.cpp index 947fb101..99bdc7c2 100644 --- a/Source/ComputeEngine/OpenCl/OpenClEngine.cpp +++ b/Source/ComputeEngine/OpenCl/OpenClEngine.cpp @@ -120,6 +120,8 @@ ComputeActionId OpenClEngine::RunKernelAsync(const KernelComputeData& data, cons ExceptionReason::DeviceLimitsExceeded); } + m_Configuration.SetTuningCompilerOptions(data.GetCompilerOptions()); + Timer timer; timer.Start(); @@ -650,7 +652,7 @@ GlobalSizeType OpenClEngine::GetGlobalSizeType() const void OpenClEngine::SetCompilerOptions(const std::string& options, [[maybe_unused]] const bool overrideDefault) { - m_Configuration.SetCompilerOptions(options); + m_Configuration.SetStaticCompilerOptions(options); ClearKernelCache(); } @@ -687,6 +689,9 @@ std::shared_ptr OpenClEngine::LoadKernel(const KernelComputeData& } auto program = std::make_unique(*m_Context, data.GetSource()); + // TODO remove + Logger::LogInfo( "|" + data.GetCompilerOptions() + "|" ); + Logger::LogInfo( "|" + m_Configuration.GetCompilerOptions() + "|" ); program->Build(m_Configuration.GetCompilerOptions()); auto kernel = std::make_shared(std::move(program), data.GetName(), m_ComputeIdGenerator, m_Configuration); diff --git a/Source/ComputeEngine/Vulkan/VulkanEngine.cpp b/Source/ComputeEngine/Vulkan/VulkanEngine.cpp index 77e687d1..ce1a65dc 100644 --- a/Source/ComputeEngine/Vulkan/VulkanEngine.cpp +++ b/Source/ComputeEngine/Vulkan/VulkanEngine.cpp @@ -67,6 +67,8 @@ ComputeActionId VulkanEngine::RunKernelAsync(const KernelComputeData& data, cons ExceptionReason::DeviceLimitsExceeded); } + m_Configuration.SetTuningCompilerOptions(data.GetCompilerOptions()); + Timer timer; timer.Start(); @@ -417,7 +419,7 @@ GlobalSizeType VulkanEngine::GetGlobalSizeType() const void VulkanEngine::SetCompilerOptions(const std::string& options, [[maybe_unused]] const bool overrideDefault) { - m_Configuration.SetCompilerOptions(options); + m_Configuration.SetStaticCompilerOptions(options); ClearKernelCache(); } diff --git a/Source/Kernel/Kernel.cpp b/Source/Kernel/Kernel.cpp index 27a6188f..1d1cf0ed 100644 --- a/Source/Kernel/Kernel.cpp +++ b/Source/Kernel/Kernel.cpp @@ -211,12 +211,12 @@ KernelConfiguration Kernel::CreateConfiguration(const ParameterInput& parameters { const auto& parameter = GetParamater(pair.first); - if (parameter.GetValueType() != ParameterPair::GetTypeFromValue(pair.second)) + if (ParameterPair::GetTypeFromValue(parameter.GetValues()[0]) != ParameterPair::GetTypeFromValue(pair.second)) { throw KttException("Value type mismatch for parameter with name " + pair.first); } - pairs.emplace_back(parameter.GetName(), pair.second); + pairs.emplace_back(parameter.GetName(), pair.second, parameter.IsCompilerParameter()); } for (const auto& parameter : m_Parameters) diff --git a/Source/Kernel/KernelManager.cpp b/Source/Kernel/KernelManager.cpp index 970ab2fc..47f3c9f6 100644 --- a/Source/Kernel/KernelManager.cpp +++ b/Source/Kernel/KernelManager.cpp @@ -93,17 +93,18 @@ void KernelManager::RemoveKernel(const KernelId id) } } -void KernelManager::AddParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group) +void KernelManager::AddParameter(const KernelId id, const std::string& name, const std::vector& values, + const std::string& group, const bool isCompilerParameter) { auto& kernel = GetKernel(id); - kernel.AddParameter(KernelParameter(name, values, group)); + kernel.AddParameter(KernelParameter(name, values, group, isCompilerParameter)); } void KernelManager::AddScriptParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, const std::string& valueScript, - const std::string& group) + const std::string& group, const bool isCompilerParameter) { auto& kernel = GetKernel(id); - kernel.AddParameter(KernelParameter(name, valueType, valueScript, group)); + kernel.AddParameter(KernelParameter(name, valueType, valueScript, group, isCompilerParameter)); } void KernelManager::AddConstraint(const KernelId id, const std::vector& parameters, ConstraintFunction function) diff --git a/Source/Kernel/KernelManager.h b/Source/Kernel/KernelManager.h index 4ee72bc2..835a5d77 100644 --- a/Source/Kernel/KernelManager.h +++ b/Source/Kernel/KernelManager.h @@ -28,9 +28,10 @@ class KernelManager KernelId CreateKernel(const std::string& name, const std::vector& definitionIds); void RemoveKernel(const KernelId id); - void AddParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group); + void AddParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group, + const bool isCompilerParameter); void AddScriptParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, const std::string& valueScript, - const std::string& group); + const std::string& group, const bool isCompilerParameter); void AddConstraint(const KernelId id, const std::vector& parameters, ConstraintFunction function); void AddGenericConstraint(const KernelId id, const std::vector& parameters, GenericConstraintFunction function); void AddScriptConstraint(const KernelId id, const std::vector& parameters, const std::string& script); diff --git a/Source/Kernel/KernelParameter.cpp b/Source/Kernel/KernelParameter.cpp index 706180dd..089f4f71 100644 --- a/Source/Kernel/KernelParameter.cpp +++ b/Source/Kernel/KernelParameter.cpp @@ -13,10 +13,12 @@ namespace ktt static const std::string DefaultGroup = "KTTDefaultGroup"; -KernelParameter::KernelParameter(const std::string& name, const std::vector& values, const std::string& group) : +KernelParameter::KernelParameter(const std::string& name, const std::vector& values, const std::string& group, + const bool isCompilerParameter) : m_Name(name), m_Group(group), - m_Values(values) + m_Values(values), + m_IsCompilerParameter(isCompilerParameter) { if (values.empty()) { @@ -30,8 +32,8 @@ KernelParameter::KernelParameter(const std::string& name, const std::vector& KernelParameter::GetValues() const ParameterValueType KernelParameter::GetValueType() const { + if (this->IsCompilerParameter()) + { + return ParameterValueType::CompilerParameter; + } return ParameterPair::GetTypeFromValue(m_Values[0]); } @@ -66,7 +72,7 @@ ParameterPair KernelParameter::GeneratePair(const size_t valueIndex) const throw KttException("Parameter value index is out of range"); } - return ParameterPair(m_Name, m_Values[valueIndex]); + return ParameterPair(m_Name, m_Values[valueIndex], m_IsCompilerParameter); } std::vector KernelParameter::GeneratePairs() const @@ -81,6 +87,11 @@ std::vector KernelParameter::GeneratePairs() const return result; } +bool KernelParameter::IsCompilerParameter() const +{ + return m_IsCompilerParameter; +} + bool KernelParameter::operator==(const KernelParameter& other) const { return m_Name == other.m_Name; diff --git a/Source/Kernel/KernelParameter.h b/Source/Kernel/KernelParameter.h index 49d6e54c..c33284fe 100644 --- a/Source/Kernel/KernelParameter.h +++ b/Source/Kernel/KernelParameter.h @@ -14,9 +14,10 @@ namespace ktt class KernelParameter { public: - explicit KernelParameter(const std::string& name, const std::vector& values, const std::string& group); + explicit KernelParameter(const std::string& name, const std::vector& values, const std::string& group, + const bool isCompilerParameter); explicit KernelParameter(const std::string& name, const ParameterValueType valueType, const std::string& valueScript, - const std::string& group); + const std::string& group, const bool isCompilerParameter); const std::string& GetName() const; const std::string& GetGroup() const; @@ -25,6 +26,7 @@ class KernelParameter ParameterValueType GetValueType() const; ParameterPair GeneratePair(const size_t valueIndex) const; std::vector GeneratePairs() const; + bool IsCompilerParameter() const; bool operator==(const KernelParameter& other) const; bool operator!=(const KernelParameter& other) const; @@ -34,6 +36,7 @@ class KernelParameter std::string m_Name; std::string m_Group; std::vector m_Values; + bool m_IsCompilerParameter; static std::vector GetValuesFromScript(const ParameterValueType valueType, const std::string& valueScript); }; diff --git a/Source/Kernel/ParameterValueType.h b/Source/Kernel/ParameterValueType.h index 80e95f35..b1f46528 100644 --- a/Source/Kernel/ParameterValueType.h +++ b/Source/Kernel/ParameterValueType.h @@ -33,7 +33,11 @@ enum class ParameterValueType /** Parameter has string type. */ - String + String, + + /** Parameter is a compiler parameter. + */ + CompilerParameter }; } // namespace ktt diff --git a/Source/Output/JsonConverters.cpp b/Source/Output/JsonConverters.cpp index d04cec1f..c11a68a9 100644 --- a/Source/Output/JsonConverters.cpp +++ b/Source/Output/JsonConverters.cpp @@ -72,6 +72,9 @@ void to_json(json& j, const ParameterPair& pair) case ParameterValueType::String: j["Value"] = pair.GetValueString(); break; + case ParameterValueType::CompilerParameter: + j["Value"] = pair.GetValueString(); + break; default: KttError("Unhandled parameter value type"); } @@ -122,6 +125,21 @@ void from_json(const json& j, ParameterPair& pair) pair = ParameterPair(name, valueString); break; } + case ParameterValueType::CompilerParameter: + { + bool isCompilerParameter = true; + std::string valueString; + j.at("Value").get_to(valueString); + if (valueString == "set" || valueString == "notSet") + { + pair = ParameterPair(name, valueString == "set", isCompilerParameter); + } + else + { + pair = ParameterPair(name, valueString, isCompilerParameter); + } + break; + } default: KttError("Unhandled parameter value type"); } diff --git a/Source/Output/JsonConverters.h b/Source/Output/JsonConverters.h index 816b140a..4b481fbf 100644 --- a/Source/Output/JsonConverters.h +++ b/Source/Output/JsonConverters.h @@ -50,7 +50,8 @@ NLOHMANN_JSON_SERIALIZE_ENUM(ParameterValueType, {ParameterValueType::Double, "Double"}, {ParameterValueType::Float, "Float"}, {ParameterValueType::Bool, "Bool"}, - {ParameterValueType::String, "String"} + {ParameterValueType::String, "String"}, + {ParameterValueType::CompilerParameter, "CompilerParameter"} }); NLOHMANN_JSON_SERIALIZE_ENUM(ProfilingCounterType, diff --git a/Source/Tuner.cpp b/Source/Tuner.cpp index 1ca8be92..03e3a10e 100644 --- a/Source/Tuner.cpp +++ b/Source/Tuner.cpp @@ -170,7 +170,22 @@ void Tuner::AddScriptParameter(const KernelId id, const std::string& name, const { try { - m_Tuner->AddScriptParameter(id, name, valueType, valueScript, group); + bool isCompilerParameter = false; + m_Tuner->AddScriptParameter(id, name, valueType, valueScript, group, isCompilerParameter); + } + catch (const KttException& exception) + { + TunerCore::Log(LoggingLevel::Error, exception.what()); + } +} + +void Tuner::AddScriptCompilerParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, + const std::string& valueScript, const std::string& group) +{ + try + { + bool isCompilerParameter = true; + m_Tuner->AddScriptParameter(id, name, valueType, valueScript, group, isCompilerParameter); } catch (const KttException& exception) { @@ -1024,12 +1039,32 @@ ArgumentId Tuner::AddUserArgument(ComputeBuffer buffer, const size_t elementSize } } -void Tuner::AddParameterInternal(const KernelId id, const std::string& name, const std::vector& values, +void Tuner::AddCompilerParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group) +{ + std::vector parameterValues; + + for (const auto& value : values) + { + parameterValues.push_back(value); + } + + if (parameterValues.empty()) + { + parameterValues.push_back(true); + parameterValues.push_back(false); + } + + bool isCompilerParameter = true; + AddParameterInternal(id, name, parameterValues, group, isCompilerParameter); +} + +void Tuner::AddParameterInternal(const KernelId id, const std::string& name, const std::vector& values, + const std::string& group, const bool isCompilerParameter) { try { - m_Tuner->AddParameter(id, name, values, group); + m_Tuner->AddParameter(id, name, values, group, isCompilerParameter); } catch (const KttException& exception) { diff --git a/Source/Tuner.h b/Source/Tuner.h index 84e2c0b2..902fae9e 100644 --- a/Source/Tuner.h +++ b/Source/Tuner.h @@ -230,6 +230,23 @@ class KTT_API Tuner template void AddParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group = ""); + /** @fn void AddCompilerParameter(const KernelId id, const std::string& name, const std::vector& values = {}, + * const std::string& group = "") + * Works exactly as AddParameter(), but for compiler parameters. + * Adds new compiler parameter for the specified kernel, providing parameter name and optionally list of allowed values. + * Parameters will be added to the compiler as compiler options. + * During the tuning process, tuner will generate configurations for combinations of kernel parameters and their values. + * @param id Id of kernel for which the parameter will be added. + * @param name Name of a parameter. Parameter names for a single kernel must be unique. + * @param values Optional allowed values for the parameter. Value type is a string. If left empty, parameter with be either + * included without any value or completely excluded. + * @param group Optional group inside which the parameter will be added. Tuning configurations are generated separately for each + * group. This is useful when kernels contain groups of parameters that can be tuned independently. In this way, the total number + * of generated configurations can be significantly reduced. + */ + void AddCompilerParameter(const KernelId id, const std::string& name, const std::vector& values = {}, + const std::string& group = ""); + /** @fn void AddScriptParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, * const std::string& valueScript, const std::string& group = "") * Adds new parameter for the specified kernel, providing parameter name, value type and a script which generates list of allowed @@ -247,6 +264,24 @@ class KTT_API Tuner void AddScriptParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, const std::string& valueScript, const std::string& group = ""); + /** @fn void AddScriptCompilerParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, + * const std::string& valueScript, const std::string& group = "") + * Works exactly as AddScriptParameter(), but for compiler parameters. + * Adds new compiler parameter for the specified kernel, providing parameter name, value type and a script which generates list of allowed + * values. Compiler parameters will be added as a compiler option. During the tuning process, tuner will + * generate configurations for combinations of kernel parameters and their values. + * @param id Id of kernel for which the parameter will be added. + * @param name Name of a parameter. Parameter names for a single kernel must be unique. + * @param valueType Type of parameter values. + * @param valueScript Python script which will be executed to generate a list of parameter values. The values of the tuning parameters + * can be utilized by the script. The default thread size can be accessed from script through variable named "defaultSize". + * @param group Optional group inside which the parameter will be added. Tuning configurations are generated separately for each + * group. This is useful when kernels contain groups of parameters that can be tuned independently. In this way, the total number + * of generated configurations can be significantly reduced. + */ + void AddScriptCompilerParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, const std::string& valueScript, + const std::string& group = ""); + /** @fn void AddThreadModifier(const KernelId id, const std::vector& definitionIds, const ModifierType type, * const ModifierDimension dimension, const std::vector& parameters, ModifierFunction function) * Adds thread modifier function for the specified kernel. The function receives thread size in the specified dimension and @@ -1006,7 +1041,7 @@ class KTT_API Tuner const ArgumentMemoryLocation memoryLocation, const ArgumentAccessType accessType, const size_t dataSize, const ArgumentId& customId = ""); KTT_VIRTUAL_API void AddParameterInternal(const KernelId id, const std::string& name, const std::vector& values, - const std::string& group); + const std::string& group, const bool isCompilerParameter); template ArgumentDataType DeriveArgumentDataType() const; diff --git a/Source/Tuner.inl b/Source/Tuner.inl index 40d54afb..c92f843b 100644 --- a/Source/Tuner.inl +++ b/Source/Tuner.inl @@ -20,7 +20,8 @@ void Tuner::AddParameter(const KernelId id, const std::string& name, const std:: parameterValues.emplace_back(value); } - AddParameterInternal(id, name, parameterValues, group); + bool isCompilerParameter = false; + AddParameterInternal(id, name, parameterValues, group, isCompilerParameter); } template diff --git a/Source/TunerCore.cpp b/Source/TunerCore.cpp index 99c89836..fb039d3a 100644 --- a/Source/TunerCore.cpp +++ b/Source/TunerCore.cpp @@ -89,15 +89,16 @@ void TunerCore::SetLauncher(const KernelId id, KernelLauncher launcher) m_KernelManager->SetLauncher(id, launcher); } -void TunerCore::AddParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group) +void TunerCore::AddParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group, + const bool isCompilerParameter) { - m_KernelManager->AddParameter(id, name, values, group); + m_KernelManager->AddParameter(id, name, values, group, isCompilerParameter); } void TunerCore::AddScriptParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, const std::string& valueScript, - const std::string& group) + const std::string& group, const bool isCompilerParameter) { - m_KernelManager->AddScriptParameter(id, name, valueType, valueScript, group); + m_KernelManager->AddScriptParameter(id, name, valueType, valueScript, group, isCompilerParameter); } void TunerCore::AddConstraint(const KernelId id, const std::vector& parameters, ConstraintFunction function) diff --git a/Source/TunerCore.h b/Source/TunerCore.h index 6947cc87..37d24c91 100644 --- a/Source/TunerCore.h +++ b/Source/TunerCore.h @@ -38,9 +38,10 @@ class TunerCore KernelId CreateKernel(const std::string& name, const std::vector& definitionIds, KernelLauncher launcher); void RemoveKernel(const KernelId id); void SetLauncher(const KernelId id, KernelLauncher launcher); - void AddParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group); + void AddParameter(const KernelId id, const std::string& name, const std::vector& values, const std::string& group, + const bool isCompilerParameter); void AddScriptParameter(const KernelId id, const std::string& name, const ParameterValueType valueType, const std::string& valueScript, - const std::string& group); + const std::string& group, const bool isCompilerParameter); void AddConstraint(const KernelId id, const std::vector& parameters, ConstraintFunction function); void AddGenericConstraint(const KernelId id, const std::vector& parameters, GenericConstraintFunction function); void AddScriptConstraint(const KernelId id, const std::vector& parameters, const std::string& script);