Skip to content

Commit c5eaac9

Browse files
author
EC2 Default User
committed
Add vectorized null suppression for block serde
1 parent 7211304 commit c5eaac9

File tree

17 files changed

+1089
-141
lines changed

17 files changed

+1089
-141
lines changed

core/trino-main/src/main/java/io/trino/FeaturesConfig.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public class FeaturesConfig
9494
* default value is overwritten for fault tolerant execution in {@link #applyFaultTolerantExecutionDefaults()}}
9595
*/
9696
private CompressionCodec exchangeCompressionCodec = NONE;
97+
private BlockSerdeVectorizedNullSuppressionStrategy blockSerdeVectorizedNullSuppressionStrategy = BlockSerdeVectorizedNullSuppressionStrategy.AUTO;
9798
private boolean pagesIndexEagerCompactionEnabled;
9899
private boolean omitDateTimeTypePrecision;
99100
private int maxRecursionDepth = 10;
@@ -133,6 +134,12 @@ public enum DataIntegrityVerification
133134
/**/;
134135
}
135136

137+
public enum BlockSerdeVectorizedNullSuppressionStrategy
138+
{
139+
AUTO,
140+
NONE,
141+
}
142+
136143
public boolean isOmitDateTimeTypePrecision()
137144
{
138145
return omitDateTimeTypePrecision;
@@ -366,6 +373,19 @@ public FeaturesConfig setExchangeCompressionCodec(CompressionCodec exchangeCompr
366373
return this;
367374
}
368375

376+
@Config("experimental.blockserde-vectorized-null-suppression-strategy")
377+
@ConfigDescription("Strategy used for vectorized null suppression in block serde")
378+
public FeaturesConfig setBlockSerdeVectorizedNullSuppressionStrategy(BlockSerdeVectorizedNullSuppressionStrategy blockSerdeVectorizedNullSuppressionStrategy)
379+
{
380+
this.blockSerdeVectorizedNullSuppressionStrategy = blockSerdeVectorizedNullSuppressionStrategy;
381+
return this;
382+
}
383+
384+
public BlockSerdeVectorizedNullSuppressionStrategy getBlockSerdeVectorizedNullSuppressionStrategy()
385+
{
386+
return blockSerdeVectorizedNullSuppressionStrategy;
387+
}
388+
369389
public DataIntegrityVerification getExchangeDataIntegrityVerification()
370390
{
371391
return exchangeDataIntegrityVerification;

core/trino-main/src/main/java/io/trino/server/ServerMainModule.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
import io.trino.server.protocol.PreparedStatementEncoder;
101101
import io.trino.server.protocol.spooling.SpoolingServerModule;
102102
import io.trino.server.remotetask.HttpLocationFactory;
103+
import io.trino.simd.SimdSupportManager;
103104
import io.trino.spi.PageIndexerFactory;
104105
import io.trino.spi.PageSorter;
105106
import io.trino.spi.VersionEmbedder;
@@ -432,6 +433,9 @@ protected void setup(Binder binder)
432433
jsonBinder(binder).addDeserializerBinding(Block.class).to(BlockJsonSerde.Deserializer.class);
433434
binder.bind(BlockEncodingSerde.class).to(InternalBlockEncodingSerde.class).in(Scopes.SINGLETON);
434435

436+
// SIMD support: detect and install provider eagerly at startup
437+
binder.bind(SimdSupportManager.class).asEagerSingleton();
438+
435439
// thread visualizer
436440
jaxrsBinder(binder).bind(ThreadResource.class);
437441

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.simd;
15+
16+
import io.trino.FeaturesConfig;
17+
import io.trino.spi.SimdSupport;
18+
import jdk.incubator.vector.ByteVector;
19+
import jdk.incubator.vector.IntVector;
20+
import jdk.incubator.vector.LongVector;
21+
import jdk.incubator.vector.ShortVector;
22+
23+
import java.util.Set;
24+
25+
import static io.trino.simd.SimdSupportManager.MINIMUM_SIMD_LENGTH;
26+
import static io.trino.util.MachineInfo.normalizeFlag;
27+
import static io.trino.util.MachineInfo.readCpuFlags;
28+
29+
public final class AmdSimdSupport
30+
implements SimdSupport
31+
{
32+
private enum Isa {
33+
AVX2,
34+
AVX512F,
35+
AVX512VBMI2
36+
}
37+
38+
FeaturesConfig featuresConfig;
39+
private final boolean[] has = new boolean[Isa.values().length];
40+
41+
public AmdSimdSupport(FeaturesConfig featuresConfig)
42+
{
43+
this.featuresConfig = featuresConfig;
44+
Set<String> flags = readCpuFlags(false);
45+
if (!flags.isEmpty()) {
46+
for (Isa isa : Isa.values()) {
47+
String token = normalizeFlag(isa.name(), false);
48+
setIf(flags, token, isa);
49+
}
50+
}
51+
}
52+
53+
private void setIf(Set<String> flags, String flag, Isa isa)
54+
{
55+
if (flags.contains(flag)) {
56+
has[isa.ordinal()] = true;
57+
}
58+
}
59+
60+
@Override
61+
public boolean enableBlockSerdeVectorizedNullSuppression()
62+
{
63+
return featuresConfig.getBlockSerdeVectorizedNullSuppressionStrategy().equals(FeaturesConfig.BlockSerdeVectorizedNullSuppressionStrategy.AUTO);
64+
}
65+
66+
@Override
67+
public boolean supportByteGeneric()
68+
{
69+
return (ByteVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && has[Isa.AVX512F.ordinal()];
70+
}
71+
72+
@Override
73+
public boolean supportShortGeneric()
74+
{
75+
return (ShortVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && has[Isa.AVX512F.ordinal()];
76+
}
77+
78+
@Override
79+
public boolean supportIntegerGeneric()
80+
{
81+
return (IntVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && has[Isa.AVX512F.ordinal()];
82+
}
83+
84+
@Override
85+
public boolean supportLongGeneric()
86+
{
87+
return (LongVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && has[Isa.AVX512F.ordinal()];
88+
}
89+
90+
@Override
91+
public boolean supportByteCompress()
92+
{
93+
return has[Isa.AVX512VBMI2.ordinal()];
94+
}
95+
96+
@Override
97+
public boolean supportShortCompress()
98+
{
99+
return has[Isa.AVX512VBMI2.ordinal()];
100+
}
101+
102+
@Override
103+
public boolean supportIntegerCompress()
104+
{
105+
return has[Isa.AVX512F.ordinal()];
106+
}
107+
108+
@Override
109+
public boolean supportLongCompress()
110+
{
111+
return has[Isa.AVX512F.ordinal()];
112+
}
113+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.simd;
15+
16+
import io.trino.FeaturesConfig;
17+
import io.trino.spi.SimdSupport;
18+
19+
import java.util.Set;
20+
21+
import static io.trino.util.MachineInfo.normalizeFlag;
22+
import static io.trino.util.MachineInfo.readCpuFlags;
23+
24+
public final class GravitonSimdSupport
25+
implements SimdSupport
26+
{
27+
private enum Isa {
28+
NEON,
29+
SVE,
30+
SVE2
31+
}
32+
33+
FeaturesConfig featuresConfig;
34+
private final boolean[] has = new boolean[Isa.values().length];
35+
36+
public GravitonSimdSupport(FeaturesConfig featuresConfig)
37+
{
38+
Set<String> flags = readCpuFlags(true);
39+
if (!flags.isEmpty()) {
40+
for (Isa isa : Isa.values()) {
41+
String token = normalizeFlag(isa.name(), true);
42+
setIf(flags, token, isa);
43+
}
44+
}
45+
}
46+
47+
private void setIf(Set<String> flags, String flag, Isa isa)
48+
{
49+
if (flags.contains(flag)) {
50+
has[isa.ordinal()] = true;
51+
}
52+
}
53+
54+
@Override
55+
public boolean enableBlockSerdeVectorizedNullSuppression()
56+
{
57+
return featuresConfig.getBlockSerdeVectorizedNullSuppressionStrategy().equals(FeaturesConfig.BlockSerdeVectorizedNullSuppressionStrategy.AUTO);
58+
}
59+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.simd;
15+
16+
import io.trino.FeaturesConfig;
17+
import io.trino.FeaturesConfig.BlockSerdeVectorizedNullSuppressionStrategy;
18+
import io.trino.spi.SimdSupport;
19+
import jdk.incubator.vector.ByteVector;
20+
import jdk.incubator.vector.IntVector;
21+
import jdk.incubator.vector.LongVector;
22+
import jdk.incubator.vector.ShortVector;
23+
24+
import java.util.Set;
25+
26+
import static io.trino.simd.SimdSupportManager.MINIMUM_SIMD_LENGTH;
27+
import static io.trino.util.MachineInfo.normalizeFlag;
28+
import static io.trino.util.MachineInfo.readCpuFlags;
29+
30+
public final class IntelSimdSupport
31+
implements SimdSupport
32+
{
33+
private enum Isa {
34+
AVX2,
35+
AVX512F,
36+
AVX512VBMI2
37+
}
38+
39+
FeaturesConfig featuresConfig;
40+
private final boolean[] has = new boolean[Isa.values().length];
41+
42+
public IntelSimdSupport(FeaturesConfig featuresConfig)
43+
{
44+
this.featuresConfig = featuresConfig;
45+
Set<String> flags = readCpuFlags(false);
46+
if (!flags.isEmpty()) {
47+
for (Isa isa : Isa.values()) {
48+
String token = normalizeFlag(isa.name(), false);
49+
setIf(flags, token, isa);
50+
}
51+
}
52+
}
53+
54+
private void setIf(Set<String> flags, String flag, Isa isa)
55+
{
56+
if (flags.contains(flag)) {
57+
has[isa.ordinal()] = true;
58+
}
59+
}
60+
61+
@Override
62+
public boolean enableBlockSerdeVectorizedNullSuppression()
63+
{
64+
return featuresConfig.getBlockSerdeVectorizedNullSuppressionStrategy().equals(BlockSerdeVectorizedNullSuppressionStrategy.AUTO);
65+
}
66+
67+
@Override
68+
public boolean supportByteGeneric()
69+
{
70+
return (ByteVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && has[Isa.AVX512F.ordinal()];
71+
}
72+
73+
@Override
74+
public boolean supportShortGeneric()
75+
{
76+
return (ShortVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && has[Isa.AVX512F.ordinal()];
77+
}
78+
79+
@Override
80+
public boolean supportIntegerGeneric()
81+
{
82+
return (IntVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && has[Isa.AVX512F.ordinal()];
83+
}
84+
85+
@Override
86+
public boolean supportLongGeneric()
87+
{
88+
return (LongVector.SPECIES_PREFERRED.vectorBitSize() >= MINIMUM_SIMD_LENGTH) && has[Isa.AVX512F.ordinal()];
89+
}
90+
91+
@Override
92+
public boolean supportByteCompress()
93+
{
94+
return has[Isa.AVX512VBMI2.ordinal()];
95+
}
96+
97+
@Override
98+
public boolean supportShortCompress()
99+
{
100+
return has[Isa.AVX512VBMI2.ordinal()];
101+
}
102+
103+
@Override
104+
public boolean supportIntegerCompress()
105+
{
106+
return has[Isa.AVX512F.ordinal()];
107+
}
108+
109+
@Override
110+
public boolean supportLongCompress()
111+
{
112+
return has[Isa.AVX512F.ordinal()];
113+
}
114+
}

0 commit comments

Comments
 (0)