-
Notifications
You must be signed in to change notification settings - Fork 10
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
Extend SIMD benchmark tests #162
Conversation
test/wasmBenchmarker/benchmark.py
Outdated
print("compiling " + name) | ||
bob_the_stringbuilder = "./emsdk/upstream/emscripten/emcc " + path + "/" + file + " --no-entry -s WASM=1 -s EXPORTED_FUNCTIONS=_runtime -s EXPORTED_RUNTIME_METHODS=ccall,cwrap -o " + path + "/wasm/" + name + ".wasm" | ||
bob_the_stringbuilder = "./emsdk/upstream/emscripten/emcc " + path + "/" + file + " " + extraFlags + " --no-entry -s WASM=1 -s EXPORTED_FUNCTIONS=_runtime -s EXPORTED_RUNTIME_METHODS=ccall,cwrap -o " + path + "/wasm/" + name + ".wasm" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if simd tests could be enabled by a command line argument
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I'm on it.
|
||
uint32_t runtime(); | ||
|
||
int main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Man could be moved below, and runtime forward definition is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
uint32_t runtime(); | ||
|
||
int main() { | ||
if (WIDTH % 4 != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this useful? Add a comment to WIDTH instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
|
||
#define getNthBit(b, n) ((b & (0b00000001 << (7 - n))) > 0) | ||
|
||
#define setNthBitZero(b, n) b = b & (0b11111111 - (0b00000001 << (7 - n))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clearNthBit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
|
||
#define setNthBitZero(b, n) b = b & (0b11111111 - (0b00000001 << (7 - n))) | ||
|
||
#define setNthBitOne(b, n) b = b | (0b00000001 << (7 - n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setNthBit
set / clear tells the bit value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
__m128 real = _mm_add_ps(_mm_mul_ps(_mm_set_ps(j+3, j+2, j+1, j), _mm_set1_ps(ZOOM)), _mm_set1_ps(REAL_AXIS_SHIFT)); | ||
__m128 imaginary = _mm_add_ps(_mm_mul_ps(_mm_set1_ps(i), _mm_set1_ps(ZOOM)), _mm_set1_ps(IMAGINARY_AXIS_SHIFT)); | ||
byte pixels = areInMandelbrotSet(real, imaginary); | ||
for (int i = 0; i < 4; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
__m128 z_imaginary = _mm_set1_ps(0); | ||
for (size_t i = 0; i < N; i++) { | ||
__m128 cmp_result = _mm_cmpgt_ps(ABS_COMPLEX(z_real, z_imaginary), _mm_set1_ps(2)); | ||
for (size_t j = 0; j < 4; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not added
setNthBitZero(result, j); | ||
} | ||
} | ||
__m128 next_z_real = _mm_add_ps(_mm_sub_ps(SQUARE(z_real), SQUARE(z_imaginary)), c_real); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
z_real = next_z_real; | ||
z_imaginary = next_z_imaginary; | ||
if (result == 0b00000000) { | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it break or return? Break just stops the inner loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I'll change it.
46c03a5
to
882a3ef
Compare
I realized the base branch is not good. This should be based on the interpreter |
test/wasmBenchmarker/benchmark.py
Outdated
@@ -58,6 +61,7 @@ def prepare_arg_pars(): | |||
parser.add_argument('--iterations', metavar='NUMBER', help='how many times run the tests', nargs='?', | |||
const='10', default=10, type=int) | |||
parser.add_argument('--compile-anyway', help='compile the tests even if they are compiled', action='store_true') | |||
parser.add_argument('--simd-tests', help='run SIMD tests too', action='store_true') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--enable-simd
would sound better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I'll change it.
6614277
to
27a0ee7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the newline is added
35c5fe0
to
5d9e9d3
Compare
Please don't merge. I will change the "no-SIMD" Mandelbrot test to calculate the same thing. |
5d9e9d3
to
e975a36
Compare
z_real = next_z_real; | ||
z_imaginary = next_z_imaginary; | ||
} | ||
if (result == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline before if
} | ||
|
||
int main() { | ||
printf("%d\n", runtime()); | ||
printf("%u\n", runtime()); | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline at the end
int main() { | ||
printf("%u\n", runtime()); | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline at the end.
v128_t next_z_imaginary = wasm_f32x4_add(wasm_f32x4_mul(wasm_f32x4_mul(z_real, z_imaginary), wasm_f32x4_const_splat(2)), c_imaginary); | ||
z_real = next_z_real; | ||
z_imaginary = next_z_imaginary; | ||
if (result == 0b00000000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline before if. The other code use == 0
, I would prefer that here.
e975a36
to
d3f02b5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/* | ||
* Copyright (c) 2023-present Samsung Electronics Co., Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove these license comments?
I also wonder the origin of this test code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I accidently removed it. Thank you for noticing it.
When I started to write the SIMD Mandelbrot test, at first I made a non-SIMD version, then I made the SIMD version based on it. To ensure that both of the Mandelbrot tests calculate the same thing, I copied my non-SIMD version to the benchmark tests (replacing the old one). Now, their results can be compared.
One more, |
a612301
to
fef3850
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good patch. Could you squash the patches and rebase the patch?
SIMD versions of Mandelbrot and NBody tests have been added. Their non-SIMD pairs have been change to work similarly. Thus, the SIMD and non-SIMD results can be compared.
fef3850
to
5d83957
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.