Skip to content

Commit

Permalink
Adds support for OpenCL standard compiler options
Browse files Browse the repository at this point in the history
  • Loading branch information
doe300 committed Jul 23, 2018
1 parent e4242d4 commit c2d387a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
20 changes: 16 additions & 4 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@

namespace vc4c
{
/*
* Bitfield containing the enabled math optimizations
*/
enum class MathType
{
FAST = 0,
EXACT = 1,
STRICT = 2
// no assumptions performing math operations
EXACT = 0x0,
// enable mad for a * b + c to allow for less accurate results
MAD_ENABLED = 0x1,
// treat +0.0 and -0.0 as same
NO_SIGNED_ZEROES = 0x2,
// assume all arguments and results to be valid, includes MAD_ENABLE and NO_SIGNED_ZEROES
UNSAFE_MATH = 0x7,
// assume neither arguments nor results can be NaN /+-Inf
FINITE_MATH = 0x8,
// enable __FAST_RELAXED_MATH__macro in program, includes UNSAFE_MATH and FINITE_MATH
FAST_RELAXED_MATH = 0x1F
};

/*
Expand Down Expand Up @@ -155,7 +167,7 @@ namespace vc4c
*/
struct Configuration
{
MathType mathType = MathType::FAST;
MathType mathType = MathType::EXACT;
/*
* The output-mode to write the generated code in
*/
Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ int main(int argc, char** argv)
i += 2;
break;
}
else if(!vc4c::tools::parseConfigurationParameter(config, argv[i]))
else if(!vc4c::tools::parseConfigurationParameter(config, argv[i]) || strstr(argv[i], "-cl") == argv[i])
// pass every not understood option to the pre-compiler, as well as every OpenCL compiler option
options.append(argv[i]).append(" ");
}

Expand Down
2 changes: 1 addition & 1 deletion src/optimization/Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static void runOptimizationPasses(const Module& module, Method& method, const Co
}
}
index = startIndex + repeatingPasses.size() * 100;
if(iterationsLeft == 0)
if(iterationsLeft == 0 && config.additionalOptions.maxOptimizationIterations > 0)
logging::warn()
<< "Stopped optimizing, because the iteration limit was reached."
<< " This indicates either an error in the optimizations or that there is more optimizations to be done!"
Expand Down
46 changes: 34 additions & 12 deletions src/tools/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "tools.h"

#include "../helper.h"
#include "../optimization/Optimizer.h"
#include "log.h"

Expand All @@ -20,34 +21,55 @@ static auto availableOptimizations = vc4c::optimizations::Optimizer::getPasses(O

bool tools::parseConfigurationParameter(Configuration& config, const std::string& arg)
{
if(arg == "--hex")
if(arg == "-cl-opt-disable")
{
config.outputMode = OutputMode::HEX;
config.optimizationLevel = OptimizationLevel::NONE;
return true;
}
if(arg == "--bin")
if(arg == "-cl-mad-enable")
{
config.outputMode = OutputMode::BINARY;
config.mathType = add_flag(config.mathType, MathType::MAD_ENABLED);
return true;
}
if(arg == "--asm")
if(arg == "-cl-no-signed-zeros")
{
config.outputMode = OutputMode::ASSEMBLER;
config.mathType = add_flag(config.mathType, MathType::NO_SIGNED_ZEROES);
return true;
}
if(arg == "-cl-unsafe-math-optimizations")
{
config.mathType = add_flag(config.mathType, MathType::UNSAFE_MATH);
return true;
}
if(arg == "-cl-finite-math-only")
{
config.mathType = add_flag(config.mathType, MathType::FINITE_MATH);
return true;
}
if(arg == "-cl-fast-relaxed-math")
{
config.mathType = add_flag(config.mathType, MathType::FAST_RELAXED_MATH);
return true;
}
if(arg == "--fast-math")
if(arg.find("-cl-std=") == 0)
{
if(arg.find("2.") != std::string::npos)
throw CompilationError(
CompilationStep::GENERAL, "Setting OpenCL standard to a value higher than 1.2 is not supported", arg);
}
if(arg == "--hex")
{
config.mathType = MathType::FAST;
config.outputMode = OutputMode::HEX;
return true;
}
if(arg == "--exact-math")
if(arg == "--bin")
{
config.mathType = MathType::EXACT;
config.outputMode = OutputMode::BINARY;
return true;
}
if(arg == "--strict-math")
if(arg == "--asm")
{
config.mathType = MathType::STRICT;
config.outputMode = OutputMode::ASSEMBLER;
return true;
}
if(arg == "--kernel-info")
Expand Down

0 comments on commit c2d387a

Please sign in to comment.