This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
1
Further optimize AVX vectorized sum of two stl vectors
Post Flair (click to view more posts with a particular flair)
Post Body
Hi,
I am writing a function that adds two stl vectors of floats with each other as fast as possible. What I currently have is as follows:
void AvxSum(vector<float> &a, vector<float> &b)
{
count = 8
int num = 0;
int bound = a.size();
for (int num1 = 0; num1 < bound; num1 = count)
{
__m256 vec1 = _mm256_setr_ps(a[num], a[num 1], a[num 2], a[num 3], a[num 4], a[num 5], a[num 6], a[num 7]);
__m256 vec2 = _mm256_setr_ps(b[num], b[num 1], b[num 2], b[num 3], b[num 4], b[num 5], b[num 6], b[num 7]);
__m256 res = _mm256_add_ps(vec1, vec2);
float* f = (float*)&res;
a[num] = f[num]; a[num 1] = f[num 1];
a[num 2] = f[num 2]; a[num 3] = f[num 3];
a[num 4] = f[num 4]; a[num 5] = f[num 5];
a[num 6] = f[num 6]; a[num 7] = f[num 7];
}
}
Making each vectorized addition parallel (with an OMP pragma) makes this about 10x slower (I think because there are so many small operations). Maybe we could split large vectors into fairly large chunks and do this in parallel, though.
However, I am unsure of how to further optimize this inner loop.
Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
150,005
Link Karma
18,628
Comment Karma
129,390
Profile updated: 1 day ago
Posts updated: 7 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 8 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cpp_questio...