Skip to content

Commit

Permalink
use a heuristic to decide when to hash in batched
Browse files Browse the repository at this point in the history
  • Loading branch information
Sasha Demin committed Apr 17, 2024
1 parent 14cd655 commit 362097c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
16 changes: 10 additions & 6 deletions src/f4/f4.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ end
# Call the linear algebra backend
linalg_main!(matrix, basis, params)
# Extract nonzero rows from the matrix into the basis
matrix_convert_rows_to_basis_elements!(matrix, basis, ht, symbol_ht, params; batched_ht_insert=true)
matrix_convert_rows_to_basis_elements!(
matrix,
basis,
ht,
symbol_ht,
params;
batched_ht_insert=true
)
end

@timeit function f4_update!(
Expand Down Expand Up @@ -355,11 +362,8 @@ function f4_find_multiplied_reducer!(

# Mark the current monomial as a pivot since a reducer has been found.
@inbounds monom_hashval = symbol_ht.hashdata[monomid]
@inbounds symbol_ht.hashdata[monomid] = Hashvalue(
PIVOT_COLUMN,
monom_hashval.hash,
monom_hashval.divmask,
)
@inbounds symbol_ht.hashdata[monomid] =
Hashvalue(PIVOT_COLUMN, monom_hashval.hash, monom_hashval.divmask)
matrix.nrows_filled_upper += 1

nothing
Expand Down
3 changes: 1 addition & 2 deletions src/f4/hashtable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,7 @@ function hashtable_insert_polynomial_multiple!(
symbol_ht.ndivbits,
symbol_ht.compress_divmask
)
symbol_ht.hashdata[vidx] =
Hashvalue(NON_PIVOT_COLUMN, newhash, divmask)
symbol_ht.hashdata[vidx] = Hashvalue(NON_PIVOT_COLUMN, newhash, divmask)

row[j] = vidx
symbol_ht.load += 1
Expand Down
12 changes: 9 additions & 3 deletions src/f4/learn_apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ function reduction_learn!(
)
matrix_fill_column_to_monom_map!(matrix, symbol_ht)
linalg_main!(matrix, basis, params, trace, linalg=LinearAlgebra(:learn, :sparse))
matrix_convert_rows_to_basis_elements!(matrix, basis, hashtable, symbol_ht, params)
matrix_convert_rows_to_basis_elements!(
matrix,
basis,
hashtable,
symbol_ht,
params;
batched_ht_insert=true
)
pivot_indices =
map(i -> Int32(basis.monoms[basis.nprocessed + i][1]), 1:(matrix.npivots))
push!(trace.matrix_pivot_indices, pivot_indices)
Expand Down Expand Up @@ -465,8 +472,7 @@ function f4_symbolic_preprocessing!(
@inbounds while i <= symbol_ht.load
if symbol_ht.hashdata[i].idx == NON_PIVOT_COLUMN
hv = symbol_ht.hashdata[i]
symbol_ht.hashdata[i] =
Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask)
symbol_ht.hashdata[i] = Hashvalue(UNKNOWN_PIVOT_COLUMN, hv.hash, hv.divmask)
end
i += MonomId(1)
end
Expand Down
15 changes: 8 additions & 7 deletions src/f4/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -338,14 +338,15 @@ function matrix_convert_rows_to_basis_elements!(
crs = basis.nprocessed

_, _, nl, nr = matrix_block_sizes(matrix)
support_size = sum(length, rows; init=0)
@log :debug """
After F4 reduction, in the right part of the matrix,
# columns: $nr
# rows: $(matrix.npivots)
# monoms (total): $(sum(length, rows; init=0))
# columns: $nr
# pivots: $(matrix.npivots)
# support: $support_size
"""

if batched_ht_insert
if batched_ht_insert && matrix.npivots > 1 && support_size > 4 * nr
@log :debug "Using batched insert."
column_to_basis_monom = zeros(MonomId, nr)
@inbounds for i in 1:(matrix.npivots)
Expand All @@ -354,9 +355,9 @@ function matrix_convert_rows_to_basis_elements!(
end
end
matrix_insert_in_basis_hashtable_pivots_masked!(
column_to_basis_monom,
ht,
symbol_ht,
column_to_basis_monom,
ht,
symbol_ht,
matrix.column_to_monom,
nl
)
Expand Down

0 comments on commit 362097c

Please sign in to comment.