jdk

Форк
0
/
TestFloatConversionsVector.java 
140 строк · 4.7 Кб
1
/*
2
 * Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
/**
25
 * @test
26
 * @bug 8294588
27
 * @summary Auto-vectorize Float.floatToFloat16, Float.float16ToFloat APIs
28
 * @requires vm.compiler2.enabled
29
 * @requires (os.simpleArch == "x64" & (vm.cpu.features ~= ".*avx512f.*" | vm.cpu.features ~= ".*f16c.*")) |
30
 *           os.arch == "aarch64" |
31
 *           (os.arch == "riscv64" & vm.cpu.features ~= ".*zvfh.*")
32
 * @library /test/lib /
33
 * @run driver compiler.vectorization.TestFloatConversionsVector
34
 */
35

36
package compiler.vectorization;
37

38
import compiler.lib.ir_framework.*;
39
import jdk.test.lib.Asserts;
40

41
public class TestFloatConversionsVector {
42
    private static final int ARRLEN = 1024;
43
    private static final int ITERS  = 11000;
44
    private static float  [] finp;
45
    private static short  [] sout;
46
    private static short  [] sinp;
47
    private static float  [] fout;
48

49
    public static void main(String args[]) {
50
        TestFramework.runWithFlags("-XX:-TieredCompilation",
51
                                   "-XX:CompileThresholdScaling=0.3");
52
        System.out.println("PASSED");
53
    }
54

55
    @Test
56
    @IR(counts = {IRNode.VECTOR_CAST_F2HF, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})
57
    public void test_float_float16(short[] sout, float[] finp) {
58
        for (int i = 0; i < finp.length; i++) {
59
            sout[i] = Float.floatToFloat16(finp[i]);
60
        }
61
    }
62

63
    @Test
64
    public void test_float_float16_strided(short[] sout, float[] finp) {
65
        for (int i = 0; i < finp.length/2; i++) {
66
            sout[i*2] = Float.floatToFloat16(finp[i*2]);
67
        }
68
    }
69

70
    @Run(test = {"test_float_float16", "test_float_float16_strided"}, mode = RunMode.STANDALONE)
71
    public void kernel_test_float_float16() {
72
        finp = new float[ARRLEN];
73
        sout = new short[ARRLEN];
74

75
        for (int i = 0; i < ARRLEN; i++) {
76
            finp[i] = (float) i * 1.4f;
77
        }
78

79
        for (int i = 0; i < ITERS; i++) {
80
            test_float_float16(sout, finp);
81
        }
82

83
        // Verifying the result
84
        for (int i = 0; i < ARRLEN; i++) {
85
            Asserts.assertEquals(Float.floatToFloat16(finp[i]), sout[i]);
86
        }
87

88
        for (int i = 0; i < ITERS; i++) {
89
            test_float_float16_strided(sout, finp);
90
        }
91

92
        // Verifying the result
93
        for (int i = 0; i < ARRLEN/2; i++) {
94
            Asserts.assertEquals(Float.floatToFloat16(finp[i*2]), sout[i*2]);
95
        }
96
    }
97

98
    @Test
99
    @IR(counts = {IRNode.VECTOR_CAST_HF2F, IRNode.VECTOR_SIZE + "min(max_float, max_short)", "> 0"})
100
    public void test_float16_float(float[] fout, short[] sinp) {
101
        for (int i = 0; i < sinp.length; i++) {
102
            fout[i] = Float.float16ToFloat(sinp[i]);
103
        }
104
    }
105

106
    @Test
107
    public void test_float16_float_strided(float[] fout, short[] sinp) {
108
        for (int i = 0; i < sinp.length/2; i++) {
109
            fout[i*2] = Float.float16ToFloat(sinp[i*2]);
110
        }
111
    }
112

113
    @Run(test = {"test_float16_float", "test_float16_float_strided"}, mode = RunMode.STANDALONE)
114
    public void kernel_test_float16_float() {
115
        sinp = new short[ARRLEN];
116
        fout = new float[ARRLEN];
117

118
        for (int i = 0; i < ARRLEN; i++) {
119
            sinp[i] = (short)i;
120
        }
121

122
        for (int i = 0; i < ITERS; i++) {
123
            test_float16_float(fout, sinp);
124
        }
125

126
        // Verifying the result
127
        for (int i = 0; i < ARRLEN; i++) {
128
            Asserts.assertEquals(Float.float16ToFloat(sinp[i]), fout[i]);
129
        }
130

131
        for (int i = 0; i < ITERS; i++) {
132
            test_float16_float_strided(fout, sinp);
133
        }
134

135
        // Verifying the result
136
        for (int i = 0; i < ARRLEN/2; i++) {
137
            Asserts.assertEquals(Float.float16ToFloat(sinp[i*2]), fout[i*2]);
138
        }
139
    }
140
}
141

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.