Skip to content
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

Enable JIT compilation for more expressions #70598

Merged
merged 46 commits into from
Nov 28, 2024
Merged

Conversation

taiyang-li
Copy link
Contributor

@taiyang-li taiyang-li commented Oct 12, 2024

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Enable JIT compilation for more expressions: abs/bitCount/sign/modulo/pmod/isNull/isNotNull/assumeNotNull/to(U)Int*/toFloat*, comparison functions(=, <, >, >=, <=), logical functions(and, or).

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

CI Settings (Only check the boxes if you know what you are doing):

  • Allow: All Required Checks
  • Allow: Stateless tests
  • Allow: Stateful tests
  • Allow: Integration Tests
  • Allow: Performance tests
  • Allow: All Builds
  • Allow: batch 1, 2 for multi-batch jobs
  • Allow: batch 3, 4, 5, 6 for multi-batch jobs

  • Exclude: Style check
  • Exclude: Fast test
  • Exclude: All with ASAN
  • Exclude: All with TSAN, MSAN, UBSAN, Coverage
  • Exclude: All with aarch64, release, debug

  • Run only fuzzers related jobs (libFuzzer fuzzers, AST fuzzers, etc.)
  • Exclude: AST fuzzers

  • Do not test
  • Woolen Wolfdog
  • Upload binaries for special builds
  • Disable merge-commit
  • Disable CI cache

@taiyang-li taiyang-li marked this pull request as draft October 12, 2024 10:04
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-feature Pull request with new product feature label Oct 12, 2024
@taiyang-li
Copy link
Contributor Author

taiyang-li commented Oct 12, 2024

First prepare data

CREATE TABLE jit_test (
a UInt64,
b UInt64,
c UInt64,
d UInt64,
e UInt64,
f UInt64,
g UInt64,
h UInt64,
i UInt64,
j UInt64
) Engine = Memory

INSERT INTO jit_test
SELECT
number,
number,
number,
number,
number,
number,
number,
number,
number,
number
FROM
system.numbers
LIMIT 100000000

For abs

SELECT abs(-a) / abs(b) + abs(c) / abs(d) + abs(-e) / abs(f) + abs(g) / abs(h) + abs(-i) / abs(j) FROM jit_test SETTINGS compile_expressions = 0 format Null; 
0 rows in set. Elapsed: 0.607 sec. Processed 100.00 million rows, 8.00 GB (164.87 million rows/s., 13.19 GB/s.)

SELECT abs(-a) / abs(b) + abs(c) / abs(d) + abs(-e) / abs(f) + abs(g) / abs(h) + abs(-i) / abs(j) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null; 
0 rows in set. Elapsed: 0.159 sec. Processed 100.00 million rows, 8.00 GB (628.62 million rows/s., 50.29 GB/s.)  

For bitcount

SELECT bitCount(a) + bitCount(b) + bitCount(c) + bitCount(d) + bitCount(e) + bitCount(f) + bitCount(g)+ bitCount(h)+ bitCount(i) + bitCount(j) FROM jit_test SETTINGS compile_expressions = 0 format Null; 
0 rows in set. Elapsed: 0.281 sec. Processed 100.00 million rows, 8.00 GB (355.82 million rows/s., 28.47 GB/s.)

SELECT bitCount(a) + bitCount(b) + bitCount(c) + bitCount(d) + bitCount(e) + bitCount(f) + bitCount(g)+ bitCount(h)+ bitCount(i) + bitCount(j)  FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null; 
0 rows in set. Elapsed: 0.137 sec. Processed 100.00 million rows, 8.00 GB (728.95 million rows/s., 58.32 GB/s.)  

@robot-ch-test-poll2
Copy link
Contributor

robot-ch-test-poll2 commented Oct 12, 2024

This is an automated comment for commit 0e82fb8 with description of existing statuses. It's updated for the latest CI running

✅ Click here to open a full report in a separate page

Successful checks
Check nameDescriptionStatus
AST fuzzerRuns randomly generated queries to catch program errors. The build type is optionally given in parenthesis. If it fails, ask a maintainer for help✅ success
BuildsThere's no description for the check yet, please add it to tests/ci/ci_config.py:CHECK_DESCRIPTIONS✅ success
ClickBenchRuns [ClickBench](https://github.com/ClickHouse/ClickBench/) with instant-attach table✅ success
Compatibility checkChecks that clickhouse binary runs on distributions with old libc versions. If it fails, ask a maintainer for help✅ success
Docker keeper imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docker server imageThe check to build and optionally push the mentioned image to docker hub✅ success
Docs checkBuilds and tests the documentation✅ success
Fast testNormally this is the first check that is ran for a PR. It builds ClickHouse and runs most of stateless functional tests, omitting some. If it fails, further checks are not started until it is fixed. Look at the report to see which tests fail, then reproduce the failure locally as described here✅ success
Flaky testsChecks if new added or modified tests are flaky by running them repeatedly, in parallel, with more randomization. Functional tests are run 100 times with address sanitizer, and additional randomization of thread scheduling. Integration tests are run up to 10 times. If at least once a new test has failed, or was too long, this check will be red. We don't allow flaky tests, read the doc✅ success
Install packagesChecks that the built packages are installable in a clear environment✅ success
Integration testsThe integration tests report. In parenthesis the package type is given, and in square brackets are the optional part/total tests✅ success
Performance ComparisonMeasure changes in query performance. The performance test report is described in detail here. In square brackets are the optional part/total tests✅ success
Stateful testsRuns stateful functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stateless testsRuns stateless functional tests for ClickHouse binaries built in various configurations -- release, debug, with sanitizers, etc✅ success
Stress testRuns stateless functional tests concurrently from several clients to detect concurrency-related errors✅ success
Style checkRuns a set of checks to keep the code style clean. If some of tests failed, see the related log from the report✅ success
Unit testsRuns the unit tests for different release types✅ success
Upgrade checkRuns stress tests on server version from last release and then tries to upgrade it to the version from the PR. It checks if the new server can successfully startup without any errors, crashes or sanitizer asserts✅ success

@taiyang-li
Copy link
Contributor Author

taiyang-li commented Oct 12, 2024

For sign

 
without compilation: SELECT sign(a) + sign(b) + sign(c) + sign(d) + sign(e) + sign(f) + sign(g) + sign(h) + sign(i) + sign(j) FROM jit_test SETTINGS compile_expressions = 0 format Null; 

localhost:9001, queries: 20, QPS: 3.522, RPS: 352227623.681, MiB/s: 26872.835, result RPS: 0.000, result MiB/s: 0.000


with compilation: SELECT sign(a) + sign(b) + sign(c) + sign(d) + sign(e) + sign(f) + sign(g) + sign(h) + sign(i) + sign(j) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null; 

localhost:9001, queries: 20, QPS: 7.372, RPS: 737213493.089, MiB/s: 56244.926, result RPS: 0.000, result MiB/s: 0.000.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 13, 2024
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-performance Pull request with some performance improvements and removed pr-feature Pull request with new product feature labels Oct 13, 2024
@taiyang-li taiyang-li marked this pull request as ready for review October 14, 2024 03:17
@taiyang-li
Copy link
Contributor Author

taiyang-li commented Oct 14, 2024

For comparison functions, execution with JIT is slightly slower.

SELECT equals(a, b/g) + less(c, d/g) + greater(e/g, f) FROM jit_test SETTINGS compile_expressions = 0 format Null; 
localhost:9001, queries: 20, QPS: 4.426, RPS: 442635961.679, MiB/s: 23639.311, result RPS: 0.000, result MiB/s: 0.000.


SELECT equals(a, b/g) + less(c, d/g) + greater(e/g, f) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
localhost:9001, queries: 20, QPS: 4.387, RPS: 438709117.961, MiB/s: 23429.595, result RPS: 0.000, result MiB/s: 0.000.

For isNotNull:

SELECT isNotNull(a::Nullable(UInt64)) + isNotNull(b::Nullable(UInt64)) + isNotNull(c::Nullable(UInt64)) + isNotNull(d::Nullable(UInt64)) + isNotNull(e::Nullable(UInt64)) + isNotNull(f::Nullable(UInt64)) + isNotNull(g::Nullable(UInt64)) FROM jit_test SETTINGS compile_expressions = 0 format Null;
0 rows in set. Elapsed: 0.120 sec. Processed 100.00 million rows, 5.60 GB (836.18 million rows/s., 46.83 GB/s.)

SELECT isNotNull(a::Nullable(UInt64)) + isNotNull(b::Nullable(UInt64)) + isNotNull(c::Nullable(UInt64)) + isNotNull(d::Nullable(UInt64)) + isNotNull(e::Nullable(UInt64)) + isNotNull(f::Nullable(UInt64)) + isNotNull(g::Nullable(UInt64)) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
0 rows in set. Elapsed: 0.064 sec. Processed 100.00 million rows, 5.60 GB (1.55 billion rows/s., 87.00 GB/s.)

For assumeNotNull

SELECT assumeNotNull(a::Nullable(UInt64)) + assumeNotNull(b::Nullable(UInt64)) + assumeNotNull(c::Nullable(UInt64)) + assumeNotNull(d::Nullable(UInt64)) + assumeNotNull(e::Nullable(UInt64)) + assumeNotNull(f::Nullable(UInt64)) + assumeNotNull(g::Nullable(UInt64)) FROM jit_test SETTINGS compile_expressions = 0 format Null;
0 rows in set. Elapsed: 0.166 sec. Processed 100.00 million rows, 5.60 GB (602.55 million rows/s., 33.74 GB/s.) 

SELECT assumeNotNull(a::Nullable(UInt64)) + assumeNotNull(b::Nullable(UInt64)) + assumeNotNull(c::Nullable(UInt64)) + assumeNotNull(d::Nullable(UInt64)) + assumeNotNull(e::Nullable(UInt64)) + assumeNotNull(f::Nullable(UInt64)) + assumeNotNull(g::Nullable(UInt64)) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
0 rows in set. Elapsed: 0.066 sec. Processed 100.00 million rows, 5.60 GB (1.51 billion rows/s., 84.78 GB/s.) 

For and

SELECT and(a::Nullable(UInt64), b::Nullable(UInt64)) + and(c::Nullable(UInt64), d::Nullable(UInt64)) + and(e::Nullable(UInt64), f::Nullable(UInt64)) + g::Nullable(UInt64) FROM jit_test SETTINGS compile_expressions = 0 format Null;
localhost:9001, queries: 20, QPS: 4.661, RPS: 466084590.184, MiB/s: 24891.603, result RPS: 0.000, result MiB/s: 0.000.

SELECT and(a::Nullable(UInt64), b::Nullable(UInt64)) + and(c::Nullable(UInt64), d::Nullable(UInt64)) + and(e::Nullable(UInt64), f::Nullable(UInt64)) + g::Nullable(UInt64) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
localhost:9001, queries: 20, QPS: 5.143, RPS: 514327996.044, MiB/s: 27468.078, result RPS: 0.000, result MiB/s: 0.000.

For or

SELECT or(a::Nullable(UInt64), b::Nullable(UInt64)) + or(c::Nullable(UInt64), d::Nullable(UInt64)) + or(e::Nullable(UInt64), f::Nullable(UInt64)) + g::Nullable(UInt64) FROM jit_test SETTINGS compile_expressions = 0 format Null;
localhost:9001, queries: 20, QPS: 6.569, RPS: 656907149.117, MiB/s: 35082.627, result RPS: 0.000, result MiB/s: 0.000.

SELECT or(a::Nullable(UInt64), b::Nullable(UInt64)) + or(c::Nullable(UInt64), d::Nullable(UInt64)) + or(e::Nullable(UInt64), f::Nullable(UInt64)) + g::Nullable(UInt64) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
localhost:9001, queries: 20, QPS: 7.087, RPS: 708686555.439, MiB/s: 37847.945, result RPS: 0.000, result MiB/s: 0.000.

For xor

SELECT xor(a::Nullable(UInt64), b::Nullable(UInt64)) + xor(c::Nullable(UInt64), d::Nullable(UInt64)) + xor(e::Nullable(UInt64), f::Nullable(UInt64)) + g::Nullable(UInt64) FROM jit_test SETTINGS compile_expressions = 0 format Null;
localhost:9001, queries: 20, QPS: 8.167, RPS: 816676282.063, MiB/s: 43615.219, result RPS: 0.000, result MiB/s: 0.000.

SELECT xor(a::Nullable(UInt64), b::Nullable(UInt64)) + xor(c::Nullable(UInt64), d::Nullable(UInt64)) + xor(e::Nullable(UInt64), f::Nullable(UInt64)) + g::Nullable(UInt64) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null
localhost:9001, queries: 20, QPS: 12.297, RPS: 1229676512.222, MiB/s: 65671.811, result RPS: 0.000, result MiB/s: 0.000.

@nickitat nickitat self-assigned this Oct 14, 2024
@taiyang-li
Copy link
Contributor Author

taiyang-li commented Oct 14, 2024

For isNull:

SELECT isNull(a::Nullable(UInt64)) + isNull(b::Nullable(UInt64)) + isNull(c::Nullable(UInt64)) + isNull(d::Nullable(UInt64)) + isNull(e::Nullable(UInt64)) + isNull(f::Nullable(UInt64)) + isNull(g::Nullable(UInt64)) FROM jit_test SETTINGS compile_expressions = 0 format Null;
0 rows in set. Elapsed: 0.118 sec. Processed 100.00 million rows, 5.60 GB (849.83 million rows/s., 47.59 GB/s.)
SELECT isNull(a::Nullable(UInt64)) + isNull(b::Nullable(UInt64)) + isNull(c::Nullable(UInt64)) + isNull(d::Nullable(UInt64)) + isNull(e::Nullable(UInt64)) + isNull(f::Nullable(UInt64)) + isNull(g::Nullable(UInt64)) FROM jit_test SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
0 rows in set. Elapsed: 0.063 sec. Processed 100.00 million rows, 5.60 GB (1.60 billion rows/s., 89.57 GB/s.) 

For modulo

SELECT modulo(a::Nullable(UInt64), b::Nullable(UInt64)) + modulo(c::Nullable(UInt64), d::Nullable(UInt64)) + modulo(e::Nullable(UInt64), f::Nullable(UInt64)) FROM jit_test where a != 0 SETTINGS compile_expressions = 0 format Null
0 rows in set. Elapsed: 0.501 sec. Processed 200.00 million rows, 9.60 GB (399.09 million rows/s., 19.16 GB/s.)
SELECT modulo(a::Nullable(UInt64), b::Nullable(UInt64)) + modulo(c::Nullable(UInt64), d::Nullable(UInt64)) + modulo(e::Nullable(UInt64), f::Nullable(UInt64)) FROM jit_test where a != 0 SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
0 rows in set. Elapsed: 0.198 sec. Processed 200.00 million rows, 9.60 GB (1.01 billion rows/s., 48.55 GB/s.)

For pmod

SELECT pmod(a::Nullable(UInt64), b::Nullable(UInt64)) + pmod(c::Nullable(UInt64), d::Nullable(UInt64)) + pmod(e::Nullable(UInt64), f::Nullable(UInt64)) FROM jit_test where a != 0 SETTINGS compile_expressions = 0 format Null
0 rows in set. Elapsed: 0.594 sec. Processed 200.00 million rows, 9.60 GB (336.52 million rows/s., 16.15 GB/s.)
SELECT pmod(a::Nullable(UInt64), b::Nullable(UInt64)) + pmod(c::Nullable(UInt64), d::Nullable(UInt64)) + pmod(e::Nullable(UInt64), f::Nullable(UInt64)) FROM jit_test where a != 0 SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
0 rows in set. Elapsed: 0.279 sec. Processed 200.00 million rows, 9.60 GB (717.50 million rows/s., 34.44 GB/s.) 

For to(U)Int8|16|32|64 and toFloat32|64

SELECT modulo(toInt64(a), toInt64(b)) + modulo(toInt64(c), toInt64(d)) + modulo(toInt64(e), toInt64(f)) FROM jit_test where a != 0 SETTINGS compile_expressions = 0 format Null;
0 rows in set. Elapsed: 0.365 sec. Processed 100.00 million rows, 4.80 GB (273.62 million rows/s., 13.13 GB/s.)

SELECT modulo(toInt64(a), toInt64(b)) + modulo(toInt64(c), toInt64(d)) + modulo(toInt64(e), toInt64(f)) FROM jit_test where a != 0 SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
0 rows in set. Elapsed: 0.138 sec. Processed 100.00 million rows, 4.80 GB (723.66 million rows/s., 34.74 GB/s.) 

For identity

SELECT plus(identity(cast(a as Nullable(Int64))), identity(cast(b as Nullable(Int64)))) + plus(identity(cast(c as Nullable(Int64))), identity(cast(d as Nullable(Int64)))) + plus(identity(cast(e as Nullable(Int64))), identity(cast(f as Nullable(Int64)))) FROM jit_test where a != 0 SETTINGS compile_expressions = 0 format Null;
0 rows in set. Elapsed: 0.373 sec. Processed 100.00 million rows, 4.80 GB (268.40 million rows/s., 12.88 GB/s.)
SELECT plus(identity(cast(a as Nullable(Int64))), identity(cast(b as Nullable(Int64)))) + plus(identity(cast(c as Nullable(Int64))), identity(cast(d as Nullable(Int64)))) + plus(identity(cast(e as Nullable(Int64))), identity(cast(f as Nullable(Int64)))) FROM jit_test where a != 0 SETTINGS compile_expressions = 1, min_count_to_compile_expression = 0 format Null;
0 rows in set. Elapsed: 0.287 sec. Processed 100.00 million rows, 4.80 GB (348.48 million rows/s., 16.73 GB/s.)

@geldot
Copy link
Contributor

geldot commented Nov 15, 2024

Yes, I remember - when we enabled it on AArch64, LLVM crashed. That's why we cannot enable this setting by default.

The LLVM library in our repository is old and has to be updated.

For reference, initial attempt to bump LLVM from 15 to 16 is at #69654 (which focuses on updating libcxx, so unclear if JIT still works with patch). Latest LLVM stable release appears to be 19. Unknown if these resolve the AArch64 issue.

@Algunenano
Copy link
Member

I still don't see any link to llvm issue, so assuming an update to LLVM fixes anything is a long stretch. It might be a problem in our code

@nickitat
Copy link
Member

@taiyang-li could you pls update this branch. i cannot push into it. loongarch build should be fixed then.

@alexey-milovidov
Copy link
Member

LLVM JIT has a long track record of bugs; it is generally not safe. I'd bet (but not much) that it could be fixed in the recent versions.

@taiyang-li
Copy link
Contributor Author

taiyang-li commented Nov 19, 2024

@nickitat I didn't mean to urge, just curious when can this PR ready to be merged?

@nickitat
Copy link
Member

@taiyang-li could you pls update this branch. i cannot push into it. loongarch build should be fixed then.

i meant it was already fixed in master by Alexey. this commit is not needed. pls remove it

@taiyang-li
Copy link
Contributor Author

@taiyang-li could you pls update this branch. i cannot push into it. loongarch build should be fixed then.

i meant it was already fixed in master by Alexey. this commit is not needed. pls remove it

done.

@taiyang-li
Copy link
Contributor Author

taiyang-li commented Nov 28, 2024

@nickitat @geldot all the test had been passed, the pr is ready for review now, thanks!

@nickitat nickitat enabled auto-merge November 28, 2024 15:29
@nickitat nickitat added this pull request to the merge queue Nov 28, 2024
Merged via the queue into ClickHouse:master with commit f3f41d8 Nov 28, 2024
225 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 28, 2024
baibaichen added a commit to Kyligence/gluten that referenced this pull request Nov 29, 2024
baibaichen added a commit to apache/incubator-gluten that referenced this pull request Nov 30, 2024
* [GLUTEN-1632][CH]Daily Update Clickhouse Version (20241129)

* Fix Build AND UT Due to [Added cache for primary index](ClickHouse/ClickHouse#72102)

* Fix Build and UT due to [no auto write buffer finalization in destructors](ClickHouse/ClickHouse#68800)

- Make LocalPartitionWriter::evictPartitions called, e.g. set(GlutenConfig.COLUMNAR_CH_SHUFFLE_SPILL_THRESHOLD.key, (1024*1024).toString)

* Fix Build due to [Save several minutes of build time](ClickHouse/ClickHouse#72046)

* Fix Benchmark Build due to [Scatter blocks in hash join without copying](ClickHouse/ClickHouse#67782)

(cherry picked from commit 8d566d6a8b8785e4072ffd6f774eb83b07ac3d8d)

* Fix Benchmark Build

* Fix endless loop due to ClickHouse/ClickHouse#70598

* [Refactor #8100] using CHConf.setCHConfig()

* fix style

---------

Co-authored-by: kyligence-git <gluten@kyligence.io>
Co-authored-by: Chang Chen <baibaichen@gmail.com>
@Algunenano
Copy link
Member

Crashes have been found: #72936

SELECT 1023, (((id % -9223372036854775807) = NULL) OR ((id % NULL) = 100)) = ((id % inf) = toUInt128(9223372036854775806)), (id % NULL) = NULL, (id % materialize(toNullable(3.4028234663852886e38)))

@taiyang-li
Copy link
Contributor Author

@Algunenano I'll try to fix it.

@taiyang-li
Copy link
Contributor Author

Crashes have been found: #72936

SELECT 1023, (((id % -9223372036854775807) = NULL) OR ((id % NULL) = 100)) = ((id % inf) = toUInt128(9223372036854775806)), (id % NULL) = NULL, (id % materialize(toNullable(3.4028234663852886e38)))

It is fixed in #73509 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants