Skip to content

Commit

Permalink
Add --relax-float-ops and --convert-relaxed-to-half
Browse files Browse the repository at this point in the history
The first pass applies the RelaxedPrecision decoration to all executable
instructions with float32 based type results. The second pass converts
all executable instructions with RelaxedPrecision result to the equivalent
float16 type, inserting converts where necessary.
  • Loading branch information
greg-lunarg committed Aug 22, 2019
1 parent aef8f92 commit 3a56610
Show file tree
Hide file tree
Showing 15 changed files with 1,381 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/composite.cpp \
source/opt/const_folding_rules.cpp \
source/opt/constants.cpp \
source/opt/convert_to_half_pass.cpp \
source/opt/copy_prop_arrays.cpp \
source/opt/dead_branch_elim_pass.cpp \
source/opt/dead_insert_elim_pass.cpp \
Expand Down Expand Up @@ -152,6 +153,7 @@ SPVTOOLS_OPT_SRC_FILES := \
source/opt/reduce_load_size.cpp \
source/opt/redundancy_elimination.cpp \
source/opt/register_pressure.cpp \
source/opt/relax_float_ops_pass.cpp \
source/opt/remove_duplicates_pass.cpp \
source/opt/replace_invalid_opc.cpp \
source/opt/scalar_analysis.cpp \
Expand Down
4 changes: 4 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,8 @@ static_library("spvtools_opt") {
"source/opt/const_folding_rules.h",
"source/opt/constants.cpp",
"source/opt/constants.h",
"source/opt/convert_to_half_pass.cpp",
"source/opt/convert_to_half_pass.h",
"source/opt/copy_prop_arrays.cpp",
"source/opt/copy_prop_arrays.h",
"source/opt/dead_branch_elim_pass.cpp",
Expand Down Expand Up @@ -609,6 +611,8 @@ static_library("spvtools_opt") {
"source/opt/reflect.h",
"source/opt/register_pressure.cpp",
"source/opt/register_pressure.h",
"source/opt/relax_float_ops_pass.cpp",
"source/opt/relax_float_ops_pass.h",
"source/opt/remove_duplicates_pass.cpp",
"source/opt/remove_duplicates_pass.h",
"source/opt/replace_invalid_opc.cpp",
Expand Down
16 changes: 16 additions & 0 deletions include/spirv-tools/optimizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,22 @@ Optimizer::PassToken CreateLoopUnrollPass(bool fully_unroll, int factor = 0);
// processed (see IsSSATargetVar for details).
Optimizer::PassToken CreateSSARewritePass();

// Create pass to convert relaxed precision instructions to half precision.
// This pass converts as many relaxed float32 arithmetic operations to half as
// possible. It converts any float32 operands to half if needed. It converts
// any resulting half precision values back to float32 as needed. No variables
// are changed. No image operations are changed.
//
// Best if run late since some optimizations may not handle half precision.
// Best if followed by instruction simplification, redundancy elimination and
// DCE.
Optimizer::PassToken CreateConvertRelaxedToHalfPass();

// Create relax float ops pass.
// This pass decorates all float32 result instructions with RelaxedPrecision
// if not already so decorated.
Optimizer::PassToken CreateRelaxFloatOpsPass();

// Create copy propagate arrays pass.
// This pass looks to copy propagate memory references for arrays. It looks
// for specific code patterns to recognize array copies.
Expand Down
4 changes: 4 additions & 0 deletions source/opt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
composite.h
const_folding_rules.h
constants.h
convert_to_half_pass.h
copy_prop_arrays.h
dead_branch_elim_pass.h
dead_insert_elim_pass.h
Expand Down Expand Up @@ -92,6 +93,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
redundancy_elimination.h
reflect.h
register_pressure.h
relax_float_ops_pass.h
remove_duplicates_pass.h
replace_invalid_opc.h
scalar_analysis.h
Expand Down Expand Up @@ -130,6 +132,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
composite.cpp
const_folding_rules.cpp
constants.cpp
convert_to_half_pass.cpp
copy_prop_arrays.cpp
dead_branch_elim_pass.cpp
dead_insert_elim_pass.cpp
Expand Down Expand Up @@ -194,6 +197,7 @@ set(SPIRV_TOOLS_OPT_SOURCES
reduce_load_size.cpp
redundancy_elimination.cpp
register_pressure.cpp
relax_float_ops_pass.cpp
remove_duplicates_pass.cpp
replace_invalid_opc.cpp
scalar_analysis.cpp
Expand Down
Loading

0 comments on commit 3a56610

Please sign in to comment.