-
Notifications
You must be signed in to change notification settings - Fork 109
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
8308363: Initial compiler support for FP16 scalar operations. #848
Closed
+880
−13
Closed
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
98d8ea1
8308363: Initial compiler support for FP16 scalar operations.
jatin-bhateja 3629c43
Cleanup Float16 class definition.
jatin-bhateja 5cd42f3
Merge branch 'lworld+fp16' of http://github.com/openjdk/valhalla into…
jatin-bhateja 6989b46
Addressing offline review comments from Sandhya, new IR test addition.
jatin-bhateja 53ac892
Resolving offline review comments from Paul Sandoz and Xiaohong Gong.
jatin-bhateja 9e2e330
Tuning backend to use new 16 bit moves b/w GPR and XMMs.
jatin-bhateja 11f2b00
Auto-vectorizer support for Float16.sum operation.
jatin-bhateja ed10ca9
Review comments resolution.
jatin-bhateja b72bb36
Review comments resolutions.
jatin-bhateja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
test/hotspot/jtreg/compiler/intrinsics/float16/TestFP16ScalarAdd.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/** | ||
* @test | ||
* @bug 8308363 | ||
* @summary Validate compiler IR for FP16 scalar operations. | ||
* @requires vm.compiler2.enabled | ||
* @library /test/lib / | ||
* @compile -XDenablePrimitiveClasses TestFP16ScalarAdd.java | ||
* @run driver compiler.vectorization.TestFP16ScalarAdd | ||
*/ | ||
|
||
package compiler.vectorization; | ||
import compiler.lib.ir_framework.*; | ||
import java.util.Random; | ||
|
||
public class TestFP16ScalarAdd { | ||
private static final int count = 1024; | ||
|
||
private short[] src; | ||
private short[] dst; | ||
private short res; | ||
|
||
public static void main(String args[]) { | ||
TestFramework.run(TestFP16ScalarAdd.class); | ||
} | ||
|
||
public TestFP16ScalarAdd() { | ||
src = new short[count]; | ||
dst = new short[count]; | ||
for (int i = 0; i < count; i++) { | ||
src[i] = Float.floatToFloat16(i); | ||
} | ||
} | ||
|
||
@Test | ||
@IR(applyIfCPUFeature = {"avx512_fp16", "true"}, counts = {IRNode.ADD_HF, "> 0", IRNode.REINTERPRET_S2HF, "> 0", IRNode.REINTERPRET_HF2S, "> 0"}) | ||
public void test1() { | ||
Float16 res = new Float16((short)0); | ||
for (int i = 0; i < count; i++) { | ||
res = res.add(Float16.valueOf(src[i])); | ||
dst[i] = res.float16ToRawShortBits(); | ||
} | ||
} | ||
|
||
@Test | ||
@IR(applyIfCPUFeature = {"avx512_fp16", "true"}, failOn = {IRNode.ADD_HF, IRNode.REINTERPRET_S2HF, IRNode.REINTERPRET_HF2S}) | ||
public void test2() { | ||
Float16 hf0 = Float16.valueOf((short)0); | ||
Float16 hf1 = Float16.valueOf((short)15360); | ||
Float16 hf2 = Float16.valueOf((short)16384); | ||
Float16 hf3 = Float16.valueOf((short)16896); | ||
Float16 hf4 = Float16.valueOf((short)17408); | ||
res = hf0.add(hf1).add(hf2).add(hf3).add(hf4).float16ToRawShortBits(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
test/jdk/java/lang/Float16/FP16ReductionOperations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
/* | ||
* @test | ||
* @bug 8308363 | ||
* @summary Test FP16 reduction operations. | ||
* @compile -XDenablePrimitiveClasses FP16ReductionOperations.java | ||
* @run main/othervm -XX:+EnablePrimitiveClasses -XX:-TieredCompilation -Xbatch FP16ReductionOperations | ||
*/ | ||
|
||
import java.util.Random; | ||
|
||
public class FP16ReductionOperations { | ||
|
||
public static Random r = new Random(1024); | ||
|
||
public static short test_reduction_add_constants() { | ||
Float16 hf0 = Float16.valueOf((short)0); | ||
Float16 hf1 = Float16.valueOf((short)15360); | ||
Float16 hf2 = Float16.valueOf((short)16384); | ||
Float16 hf3 = Float16.valueOf((short)16896); | ||
Float16 hf4 = Float16.valueOf((short)17408); | ||
return hf0.add(hf1).add(hf2).add(hf3).add(hf4).float16ToRawShortBits(); | ||
} | ||
|
||
public static short expected_reduction_add_constants() { | ||
Float16 hf0 = Float16.valueOf((short)0); | ||
Float16 hf1 = Float16.valueOf((short)15360); | ||
Float16 hf2 = Float16.valueOf((short)16384); | ||
Float16 hf3 = Float16.valueOf((short)16896); | ||
Float16 hf4 = Float16.valueOf((short)17408); | ||
return Float.floatToFloat16(Float.float16ToFloat(hf0.float16ToRawShortBits()) + | ||
Float.float16ToFloat(hf1.float16ToRawShortBits()) + | ||
Float.float16ToFloat(hf2.float16ToRawShortBits()) + | ||
Float.float16ToFloat(hf3.float16ToRawShortBits()) + | ||
Float.float16ToFloat(hf4.float16ToRawShortBits())); | ||
} | ||
|
||
public static void test_reduction_constants(char oper) { | ||
short actual = 0; | ||
short expected = 0; | ||
switch(oper) { | ||
case '+' -> { | ||
actual = test_reduction_add_constants(); | ||
expected = expected_reduction_add_constants(); | ||
} | ||
default -> throw new AssertionError("Unsupported Operation."); | ||
} | ||
if (actual != expected) { | ||
throw new AssertionError("Result mismatch!, expected = " + expected + " actual = " + actual); | ||
} | ||
} | ||
|
||
public static short test_reduction_add(short [] arr) { | ||
Float16 res = Float16.valueOf((short)0); | ||
for (int i = 0; i < arr.length; i++) { | ||
res = res.add(Float16.valueOf(arr[i])); | ||
} | ||
return res.float16ToRawShortBits(); | ||
} | ||
|
||
public static short expected_reduction_add(short [] arr) { | ||
short res = 0; | ||
for (int i = 0; i < arr.length; i++) { | ||
res = Float.floatToFloat16(Float.float16ToFloat(res) + Float.float16ToFloat(arr[i])); | ||
} | ||
return res; | ||
} | ||
|
||
public static void test_reduction(char oper, short [] arr) { | ||
short actual = 0; | ||
short expected = 0; | ||
switch(oper) { | ||
case '+' -> { | ||
actual = test_reduction_add(arr); | ||
expected = expected_reduction_add(arr); | ||
} | ||
default -> throw new AssertionError("Unsupported Operation."); | ||
} | ||
if (actual != expected) { | ||
throw new AssertionError("Result mismatch!, expected = " + expected + " actual = " + actual); | ||
} | ||
} | ||
|
||
public static short [] get_fp16_array(int size) { | ||
short [] arr = new short[size]; | ||
for (int i = 0; i < arr.length; i++) { | ||
arr[i] = Float.floatToFloat16(r.nextFloat()); | ||
} | ||
return arr; | ||
} | ||
|
||
public static void main(String [] args) { | ||
int res = 0; | ||
short [] input = get_fp16_array(1024); | ||
short [] special_values = { | ||
32256, // NAN | ||
31744, // +Inf | ||
(short)-1024, // -Inf | ||
0, // +0.0 | ||
(short)-32768, // -0.0 | ||
}; | ||
for (int i = 0; i < 1000; i++) { | ||
test_reduction('+', input); | ||
test_reduction('+', special_values); | ||
test_reduction_constants('+'); | ||
} | ||
System.out.println("PASS"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The last condition
(!EnablePrimitiveClasses && !is_jdk_internal_class_sig(signature))
seems not right to me. Assume there is a jdk internal primitive class defined , andEnablePrimitiveClasses
is disabled, then result of(!EnablePrimitiveClasses && !is_jdk_internal_class_sig(signature))
isfalse
(i.e.true && false
), then the followed error is not printed if the jdk version matches >= 51. But it should report the error sinceEnablePrimitiveClasses
is closed. So it should be:right?
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.
Idea here is to relax the need to use an explicit JVM flag -XX:+EnablePrimtiiveClasses for primitive classes known to VM.