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

Extend SIMD benchmark tests #162

Merged
merged 1 commit into from
Oct 11, 2023
Merged

Conversation

GorogPeter
Copy link
Contributor

No description provided.

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"
Copy link
Collaborator

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

Copy link
Contributor Author

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() {
Copy link
Collaborator

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.

Copy link
Contributor Author

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) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearNthBit

Copy link
Contributor Author

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))
Copy link
Collaborator

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

Copy link
Contributor Author

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++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline before

Copy link
Contributor Author

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++) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline before

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.

Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add newline before

Copy link
Contributor Author

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;
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@zherczeg
Copy link
Collaborator

I realized the base branch is not good. This should be based on the interpreter

@@ -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')
Copy link
Collaborator

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

Copy link
Contributor Author

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.

@GorogPeter GorogPeter force-pushed the addSimdTest branch 2 times, most recently from 6614277 to 27a0ee7 Compare September 11, 2023 13:17
@GorogPeter GorogPeter changed the base branch from jit_next to interp September 11, 2023 13:17
Copy link
Collaborator

@zherczeg zherczeg left a 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

@GorogPeter GorogPeter force-pushed the addSimdTest branch 3 times, most recently from 35c5fe0 to 5d9e9d3 Compare September 12, 2023 11:30
@GorogPeter
Copy link
Contributor Author

Please don't merge.

I will change the "no-SIMD" Mandelbrot test to calculate the same thing.

z_real = next_z_real;
z_imaginary = next_z_imaginary;
}
if (result == 0) {
Copy link
Collaborator

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;
}
Copy link
Collaborator

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;
}
Copy link
Collaborator

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) {
Copy link
Collaborator

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.

Copy link
Collaborator

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines 1 to 15
/*
* 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.
*/
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@clover2123
Copy link
Collaborator

clover2123 commented Oct 4, 2023

One more,
This patch just adds simdMandelbrot test, but not enabled in default.
If possible, please enable this test on available platforms in our CI (actions)
(interpreter mode supports basic SIMD features now)

@GorogPeter GorogPeter changed the title Add Mandelbrot SIMD test to the benchmark tests Extend SIMD benchmark tests Oct 6, 2023
@GorogPeter GorogPeter force-pushed the addSimdTest branch 2 times, most recently from a612301 to fef3850 Compare October 8, 2023 11:35
Copy link
Collaborator

@zherczeg zherczeg left a 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.
Copy link
Collaborator

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@clover2123 clover2123 merged commit 54c0b6a into Samsung:interp Oct 11, 2023
12 checks passed
@GorogPeter GorogPeter deleted the addSimdTest branch November 2, 2023 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants