Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LightMotif
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Larralde
LightMotif
Commits
46297c96
Commit
46297c96
authored
1 year ago
by
Martin Larralde
Browse files
Options
Downloads
Patches
Plain Diff
Use AVX2 masked stores instead of blend in `Avx2::threshold`
parent
e2b8403b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lightmotif/src/pli/platform/avx2.rs
+12
-27
12 additions, 27 deletions
lightmotif/src/pli/platform/avx2.rs
with
12 additions
and
27 deletions
lightmotif/src/pli/platform/avx2.rs
+
12
−
27
View file @
46297c96
...
...
@@ -195,11 +195,8 @@ unsafe fn threshold_avx2(
}
else
{
let
data
=
scores
.matrix
();
let
rows
=
data
.rows
();
let
mut
indices
=
vec!
[
0
u32
;
data
.columns
()
*
rows
];
let
mut
indices
=
vec!
[
u32
::
MAX
;
data
.columns
()
*
rows
];
unsafe
{
// NOTE(@althonos): Using `u32::MAX` as a sentinel instead of `0`
// because `0` may be a valid index.
let
max
=
_mm256_set1_epi32
(
u32
::
MAX
as
i32
);
let
t
=
_mm256_set1_ps
(
threshold
);
let
ones
=
_mm256_set1_epi32
(
1
);
let
mut
dst
=
indices
.as_mut_ptr
()
as
*
mut
__m256i
;
...
...
@@ -252,23 +249,18 @@ unsafe fn threshold_avx2(
let
r3
=
_mm256_load_ps
(
row
[
0x10
..
]
.as_ptr
());
let
r4
=
_mm256_load_ps
(
row
[
0x18
..
]
.as_ptr
());
// check whether scores are greater or equal to the threshold
let
m1
=
_mm256_castps_si256
(
_mm256_cmp_ps
(
r1
,
t
,
_CMP_LT_OS
));
let
m2
=
_mm256_castps_si256
(
_mm256_cmp_ps
(
r2
,
t
,
_CMP_LT_OS
));
let
m3
=
_mm256_castps_si256
(
_mm256_cmp_ps
(
r3
,
t
,
_CMP_LT_OS
));
let
m4
=
_mm256_castps_si256
(
_mm256_cmp_ps
(
r4
,
t
,
_CMP_LT_OS
));
// Mask indices that should be removed
let
i1
=
_mm256_blendv_epi8
(
x1
,
max
,
m1
);
let
i2
=
_mm256_blendv_epi8
(
x2
,
max
,
m2
);
let
i3
=
_mm256_blendv_epi8
(
x3
,
max
,
m3
);
let
i4
=
_mm256_blendv_epi8
(
x4
,
max
,
m4
);
// Store masked indices into the destination vector
_mm256_storeu_si256
(
dst
,
i1
);
_mm256_storeu_si256
(
dst
.add
(
1
),
i2
);
_mm256_storeu_si256
(
dst
.add
(
2
),
i3
);
_mm256_storeu_si256
(
dst
.add
(
3
),
i4
);
// Advance result buffer to next row
let
m1
=
_mm256_castps_si256
(
_mm256_cmp_ps
(
r1
,
t
,
_CMP_GE_OS
));
let
m2
=
_mm256_castps_si256
(
_mm256_cmp_ps
(
r2
,
t
,
_CMP_GE_OS
));
let
m3
=
_mm256_castps_si256
(
_mm256_cmp_ps
(
r3
,
t
,
_CMP_GE_OS
));
let
m4
=
_mm256_castps_si256
(
_mm256_cmp_ps
(
r4
,
t
,
_CMP_GE_OS
));
// store masked indices into the destination vector
_mm256_maskstore_epi32
(
dst
as
*
mut
_
,
m1
,
x1
);
_mm256_maskstore_epi32
(
dst
.add
(
1
)
as
*
mut
_
,
m2
,
x2
);
_mm256_maskstore_epi32
(
dst
.add
(
2
)
as
*
mut
_
,
m3
,
x3
);
_mm256_maskstore_epi32
(
dst
.add
(
3
)
as
*
mut
_
,
m4
,
x4
);
// advance result buffer to next row
dst
=
dst
.add
(
4
);
//
A
dvance sequence indices to next row
//
a
dvance sequence indices to next row
x1
=
_mm256_add_epi32
(
x1
,
ones
);
x2
=
_mm256_add_epi32
(
x2
,
ones
);
x3
=
_mm256_add_epi32
(
x3
,
ones
);
...
...
@@ -279,13 +271,6 @@ unsafe fn threshold_avx2(
// NOTE: Benchmarks suggest that `indices.retain(...)` is faster than
// `indices.into_iter().filter(...).
// FIXME: The `Vec::retain` implementation may not be optimal for this,
// since it takes extra care of the vector elements deallocation
// because they may implement `Drop`. It may be faster to use
// a double-pointer algorithm, swapping sentinels and concrete
// values until the end of the vector is reached, and then
// clipping the vector with `indices.set_len`.
// Remove all masked items and convert the indices to usize
indices
.retain
(|
&
x
|
(
x
as
usize
)
<
scores
.len
());
indices
.into_iter
()
.map
(|
i
|
i
as
usize
)
.collect
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment