Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Source/Api/Configuration/KernelConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(pair.GetValue()))
{
result += " " + pair.GetName() + "=" + pair.GetValueString();
}
else if (std::holds_alternative<bool>(pair.GetValue()) && std::get<bool>(pair.GetValue()))
{
result += " " + pair.GetName();
}
}

return result;
Expand Down
7 changes: 7 additions & 0 deletions Source/Api/Configuration/KernelConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...".
Expand Down
20 changes: 18 additions & 2 deletions Source/Api/Configuration/ParameterPair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ ParameterPair::ParameterPair() :
m_Value(static_cast<uint64_t>(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)
Expand Down Expand Up @@ -46,6 +47,10 @@ std::string ParameterPair::GetValueString() const
return std::get<bool>(m_Value) ? "true" : "false";
case ParameterValueType::String:
return std::get<std::string>(m_Value);
case ParameterValueType::CompilerParameter:
if (std::holds_alternative<std::string>(m_Value))
return std::get<std::string>(m_Value);
return std::get<bool>(m_Value) ? "set" : "notSet";
default:
KttError("Unhandled parameter value type");
return "";
Expand All @@ -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())
Expand All @@ -91,6 +105,8 @@ bool ParameterPair::HasSameValue(const ParameterPair& other) const
return std::get<bool>(m_Value) == std::get<bool>(other.GetValue());
case ParameterValueType::String:
return GetValueString() == other.GetValueString();
case ParameterValueType::CompilerParameter:
return GetValueString() == other.GetValueString();
default:
KttError("Unhandled parameter value type");
return false;
Expand Down
12 changes: 10 additions & 2 deletions Source/Api/Configuration/ParameterPair.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -110,6 +117,7 @@ class KTT_API ParameterPair
private:
std::string m_Name;
ParameterValue m_Value;
bool m_IsCompilerParameter;
};

} // namespace ktt
Expand Down
4 changes: 3 additions & 1 deletion Source/ComputeEngine/Cuda/CudaEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ ComputeActionId CudaEngine::RunKernelAsync(const KernelComputeData& data, const
ExceptionReason::DeviceLimitsExceeded);
}

m_Configuration.SetTuningCompilerOptions(data.GetCompilerOptions());

Timer timer;
timer.Start();

Expand Down Expand Up @@ -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();
}

Expand Down
13 changes: 9 additions & 4 deletions Source/ComputeEngine/EngineConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Source/ComputeEngine/EngineConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ 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;

bool IsProfilingActive() const;
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;
Expand Down
8 changes: 7 additions & 1 deletion Source/ComputeEngine/KernelComputeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -156,4 +157,9 @@ const std::vector<KernelArgument*>& KernelComputeData::GetArguments() const
return m_Arguments;
}

const std::string& KernelComputeData::GetCompilerOptions() const
{
return m_CompilerOptions;
}

} // namespace ktt
2 changes: 2 additions & 0 deletions Source/ComputeEngine/KernelComputeData.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class KernelComputeData
const KernelConfiguration& GetConfiguration() const;
size_t GetArgumentIndex(const ArgumentId& id) const;
const std::vector<KernelArgument*>& GetArguments() const;
const std::string& GetCompilerOptions() const;

private:
std::string m_Name;
Expand All @@ -47,6 +48,7 @@ class KernelComputeData
DimensionVector m_LocalSize;
const KernelConfiguration* m_Configuration;
std::vector<KernelArgument*> m_Arguments;
std::string m_CompilerOptions;
};

} // namespace ktt
7 changes: 6 additions & 1 deletion Source/ComputeEngine/OpenCl/OpenClEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ ComputeActionId OpenClEngine::RunKernelAsync(const KernelComputeData& data, cons
ExceptionReason::DeviceLimitsExceeded);
}

m_Configuration.SetTuningCompilerOptions(data.GetCompilerOptions());

Timer timer;
timer.Start();

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -687,6 +689,9 @@ std::shared_ptr<OpenClKernel> OpenClEngine::LoadKernel(const KernelComputeData&
}

auto program = std::make_unique<OpenClProgram>(*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<OpenClKernel>(std::move(program), data.GetName(), m_ComputeIdGenerator, m_Configuration);

Expand Down
4 changes: 3 additions & 1 deletion Source/ComputeEngine/Vulkan/VulkanEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ ComputeActionId VulkanEngine::RunKernelAsync(const KernelComputeData& data, cons
ExceptionReason::DeviceLimitsExceeded);
}

m_Configuration.SetTuningCompilerOptions(data.GetCompilerOptions());

Timer timer;
timer.Start();

Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions Source/Kernel/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions Source/Kernel/KernelManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,18 @@ void KernelManager::RemoveKernel(const KernelId id)
}
}

void KernelManager::AddParameter(const KernelId id, const std::string& name, const std::vector<ParameterValue>& values, const std::string& group)
void KernelManager::AddParameter(const KernelId id, const std::string& name, const std::vector<ParameterValue>& 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<std::string>& parameters, ConstraintFunction function)
Expand Down
5 changes: 3 additions & 2 deletions Source/Kernel/KernelManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ class KernelManager

KernelId CreateKernel(const std::string& name, const std::vector<KernelDefinitionId>& definitionIds);
void RemoveKernel(const KernelId id);
void AddParameter(const KernelId id, const std::string& name, const std::vector<ParameterValue>& values, const std::string& group);
void AddParameter(const KernelId id, const std::string& name, const std::vector<ParameterValue>& 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<std::string>& parameters, ConstraintFunction function);
void AddGenericConstraint(const KernelId id, const std::vector<std::string>& parameters, GenericConstraintFunction function);
void AddScriptConstraint(const KernelId id, const std::vector<std::string>& parameters, const std::string& script);
Expand Down
Loading