-
Notifications
You must be signed in to change notification settings - Fork 79
Vectorization cleanup #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5be2421
Allocation domain support in cacheFork
zasdfgbnm 2010de6
TensorArgAbstract allocation size
zasdfgbnm f498f3f
registry
zasdfgbnm 5dd9844
Revert "Allocation domain support in cacheFork"
zasdfgbnm 3340235
cleanup vectorize
zasdfgbnm dd83215
Revert "registry"
zasdfgbnm 91bc0c1
Revert "TensorArgAbstract allocation size"
zasdfgbnm 6fcbbbc
format
zasdfgbnm 499777b
Merge branch 'main' of github.com:NVIDIA/Fuser into vectorization-cle…
zasdfgbnm 3b92829
transpose fix
zasdfgbnm b740de2
fix test
zasdfgbnm a4099e5
doc
zasdfgbnm 344ef49
more vectorization
zasdfgbnm 35d31df
Merge branch 'main' into vectorization-cleanup
zasdfgbnm f4e6ade
Merge branch 'main' into vectorization-cleanup
zasdfgbnm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1157,6 +1157,11 @@ int64_t getVectorizationSize( | |
| auto denominator = denominator_optional->as<int64_t>(); | ||
| auto extent = extent_optional->as<int64_t>(); | ||
|
|
||
| // TODO: we should clean this up with expr simplifier | ||
| auto gcd = std::gcd(numerator, denominator); | ||
| numerator = numerator / gcd; | ||
| denominator = denominator / gcd; | ||
|
|
||
| if (denominator != 1) { | ||
| break; | ||
| } | ||
|
|
@@ -1201,52 +1206,61 @@ int64_t getVectorizationSize( | |
| return vectorize_size; | ||
| } | ||
|
|
||
| size_t getExpandedVectorization( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A big portion of |
||
| const std::vector<ContiguousInnerDimensionsMapper>& reference_maps, | ||
| size_t getVectorizationFactor( | ||
| SchedulerRuntimeInfo& runtime_info, | ||
| const std::vector<TensorView*> vectorizable_inputs_outputs, | ||
| TensorView* reference_tv, | ||
| int break_point, | ||
| size_t default_word_size) { | ||
| HeuristicSummary* data_cache, | ||
| int break_point) { | ||
| auto vectorizable_inputs_outputs_entry = | ||
| HeuristicSummaryEntry<HeuristicCompileTime::VectorizableInputsAndOutputs>( | ||
| data_cache, [&reference_tv]() { | ||
| return std::make_unique<std::vector<TensorView*>>( | ||
| scheduler_utils::getInputsOutputsWithInnerDim( | ||
| reference_tv, true, true)); | ||
| }); | ||
|
|
||
| auto& vectorizable_inputs_outputs = vectorizable_inputs_outputs_entry.get(); | ||
|
|
||
| auto vectorize_maps_entry = | ||
| HeuristicSummaryEntry<HeuristicCompileTime::VectorizeMaps>( | ||
| data_cache, [&reference_tv]() { | ||
| return std::make_unique< | ||
| std::vector<vectorize_helper::ContiguousInnerDimensionsMapper>>( | ||
| vectorize_helper::getAllVectorizedMapsOf(reference_tv)); | ||
| }); | ||
|
|
||
| if (vectorizable_inputs_outputs.empty()) { | ||
| return 1; | ||
| } | ||
|
|
||
| size_t max_expand_size = SchedulerRuntimeInfo::max_alignment_size_in_byte; | ||
| size_t max_vec_size = SchedulerRuntimeInfo::max_alignment_size_in_byte; | ||
| size_t common_alignment_size = | ||
| SchedulerRuntimeInfo::max_alignment_size_in_byte; | ||
|
|
||
| for (auto inp_or_out : vectorizable_inputs_outputs) { | ||
| auto dtype_size = | ||
| dataTypeSize(inp_or_out->dtype(), runtime_info.getIndexType()); | ||
|
|
||
| max_expand_size = std::min( | ||
| max_expand_size, | ||
| max_vec_size = std::min( | ||
| max_vec_size, | ||
| SchedulerRuntimeInfo::max_alignment_size_in_byte / dtype_size); | ||
| max_expand_size = std::min( | ||
| max_expand_size, runtime_info.getMaxVectorizableWidth(inp_or_out)); | ||
| max_vec_size = std::min( | ||
| max_vec_size, runtime_info.getMaxVectorizableWidth(inp_or_out)); | ||
| common_alignment_size = std::min( | ||
| common_alignment_size, runtime_info.getAlignmentSize(inp_or_out)); | ||
| } | ||
|
|
||
| // If there's no possibility to increase vector size of provided tensors, | ||
| // then don't bother doing a more complex analysis to try and do so, just | ||
| // return early. | ||
| if (max_expand_size == default_word_size) { | ||
| return default_word_size; | ||
| } | ||
|
|
||
| auto reference_map = reference_maps[break_point]; | ||
| auto reference_map = vectorize_maps_entry.get().at(break_point); | ||
| // Initialize to max the tensors could support. | ||
| size_t max_supported_vector_size = max_expand_size; | ||
| size_t max_supported_vector_size = max_vec_size; | ||
| for (auto inp_or_out : vectorizable_inputs_outputs) { | ||
| size_t contig_dim_size = getVectorizationSize( | ||
| getContigVectorSizesOf(inp_or_out, reference_map), | ||
| runtime_info.expressionEvaluator()); | ||
| size_t local_max_vec_size = 1; | ||
|
|
||
| while (contig_dim_size > 1 && contig_dim_size % 2 == 0 && | ||
| local_max_vec_size < max_expand_size) { | ||
| local_max_vec_size < max_vec_size) { | ||
| contig_dim_size /= 2; | ||
| local_max_vec_size *= 2; | ||
| } | ||
|
|
@@ -1257,51 +1271,5 @@ size_t getExpandedVectorization( | |
| return max_supported_vector_size; | ||
| } | ||
|
|
||
| size_t getVectorizationFactor( | ||
| SchedulerRuntimeInfo& runtime_info, | ||
| TensorView* reference_tv, | ||
| HeuristicSummary* data_cache, | ||
| int break_point) { | ||
| auto vectorizable_inputs_outputs_entry = | ||
| HeuristicSummaryEntry<HeuristicCompileTime::VectorizableInputsAndOutputs>( | ||
| data_cache, [&reference_tv]() { | ||
| return std::make_unique<std::vector<TensorView*>>( | ||
| scheduler_utils::getInputsOutputsWithInnerDim( | ||
| reference_tv, true, true)); | ||
| }); | ||
|
|
||
| auto& vectorizable_inputs_outputs = vectorizable_inputs_outputs_entry.get(); | ||
|
|
||
| size_t vectorize_factor = std::numeric_limits<size_t>::max(); | ||
|
|
||
| for (auto tv : vectorizable_inputs_outputs) { | ||
| const auto tv_vectorize_factor = | ||
| runtime_info.getInnerDimVectorizableWidth(tv); | ||
| vectorize_factor = std::min(vectorize_factor, tv_vectorize_factor); | ||
| } | ||
|
|
||
| if (vectorize_factor == std::numeric_limits<size_t>::max()) { | ||
| vectorize_factor = 1; | ||
| } | ||
|
|
||
| auto vectorize_maps_entry = | ||
| HeuristicSummaryEntry<HeuristicCompileTime::VectorizeMaps>( | ||
| data_cache, [&reference_tv]() { | ||
| return std::make_unique< | ||
| std::vector<vectorize_helper::ContiguousInnerDimensionsMapper>>( | ||
| vectorize_helper::getAllVectorizedMapsOf(reference_tv)); | ||
| }); | ||
|
|
||
| vectorize_factor = vectorize_helper::getExpandedVectorization( | ||
| vectorize_maps_entry.get(), | ||
| runtime_info, | ||
| vectorizable_inputs_outputs, | ||
| reference_tv, | ||
| break_point, | ||
| vectorize_factor); | ||
|
|
||
| return vectorize_factor; | ||
| } | ||
|
|
||
| } // namespace vectorize_helper | ||
| } // namespace nvfuser | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.