-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add support for vectorized null suppression for block serde #26919
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
Open
SongChujun
wants to merge
3
commits into
trinodb:master
Choose a base branch
from
SongChujun:vectorized-null-suppression
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+735
−54
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
112 changes: 112 additions & 0 deletions
112
core/trino-main/src/main/java/io/trino/simd/BlockEncodingSimdSupport.java
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 |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.simd; | ||
|
|
||
| import com.google.inject.Inject; | ||
| import com.google.inject.Singleton; | ||
| import io.trino.FeaturesConfig; | ||
| import io.trino.util.MachineInfo; | ||
| import jdk.incubator.vector.ByteVector; | ||
| import jdk.incubator.vector.IntVector; | ||
| import jdk.incubator.vector.LongVector; | ||
| import jdk.incubator.vector.ShortVector; | ||
| import oshi.hardware.CentralProcessor.ProcessorIdentifier; | ||
|
|
||
| import java.util.EnumSet; | ||
| import java.util.Set; | ||
|
|
||
| import static io.trino.FeaturesConfig.BlockSerdeVectorizedNullSuppressionStrategy.AUTO; | ||
| import static io.trino.util.MachineInfo.readCpuFlags; | ||
| import static java.util.Locale.ENGLISH; | ||
|
|
||
| @Singleton | ||
| public final class BlockEncodingSimdSupport | ||
| { | ||
| public record SimdSupport( | ||
| boolean expandAndCompressByte, | ||
| boolean expandAndCompressShort, | ||
| boolean expandAndCompressInt, | ||
| boolean expandAndCompressLong) | ||
| { | ||
| public static final SimdSupport NONE = new SimdSupport(false, false, false, false); | ||
| public static final SimdSupport ALL = new SimdSupport(true, true, true, true); | ||
| } | ||
|
|
||
| public static final int MINIMUM_SIMD_LENGTH = 512; | ||
| private final SimdSupport simdSupport; | ||
| private static final SimdSupport AUTO_DETECTED_SUPPORT = detectSimd(); | ||
|
|
||
| public static final BlockEncodingSimdSupport TESTING_BLOCK_ENCODING_SIMD_SUPPORT = new BlockEncodingSimdSupport(true); | ||
|
|
||
| @Inject | ||
| public BlockEncodingSimdSupport( | ||
| FeaturesConfig featuresConfig) | ||
| { | ||
| this(featuresConfig.getBlockSerdeVectorizedNullSuppressionStrategy().equals(AUTO)); | ||
| } | ||
|
|
||
| public BlockEncodingSimdSupport( | ||
| boolean enableAutoDetectedSimdSupport) | ||
| { | ||
| if (enableAutoDetectedSimdSupport) { | ||
| simdSupport = AUTO_DETECTED_SUPPORT; | ||
| } | ||
| else { | ||
| simdSupport = SimdSupport.NONE; | ||
| } | ||
| } | ||
|
|
||
| private static SimdSupport detectSimd() | ||
| { | ||
| ProcessorIdentifier id = MachineInfo.getProcessorInfo(); | ||
|
|
||
| String vendor = id.getVendor().toLowerCase(ENGLISH); | ||
|
|
||
| if (vendor.contains("intel") || vendor.contains("amd")) { | ||
| return detectX86SimdSupport(); | ||
| } | ||
|
|
||
| return SimdSupport.NONE; | ||
| } | ||
|
|
||
| private static SimdSupport detectX86SimdSupport() | ||
| { | ||
| enum X86SimdInstructionSet { | ||
| avx512f, | ||
| avx512vbmi2 | ||
| } | ||
|
|
||
| Set<String> flags = readCpuFlags(); | ||
| EnumSet<X86SimdInstructionSet> x86Flags = EnumSet.noneOf(X86SimdInstructionSet.class); | ||
|
|
||
| if (!flags.isEmpty()) { | ||
| for (X86SimdInstructionSet instructionSet : X86SimdInstructionSet.values()) { | ||
| if (flags.contains(instructionSet.name())) { | ||
| x86Flags.add(instructionSet); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return new SimdSupport( | ||
| (ByteVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && x86Flags.contains(X86SimdInstructionSet.avx512vbmi2), | ||
| (ShortVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && x86Flags.contains(X86SimdInstructionSet.avx512vbmi2), | ||
| (IntVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && x86Flags.contains(X86SimdInstructionSet.avx512f), | ||
| (LongVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && x86Flags.contains(X86SimdInstructionSet.avx512f)); | ||
| } | ||
|
|
||
| public SimdSupport getSimdSupport() | ||
| { | ||
| return simdSupport; | ||
| } | ||
| } |
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
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.