#!/bin/bash # # Copyright (c) 2018, 2022, 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. Oracle designates this # particular file as subject to the "Classpath" exception as provided # by Oracle in the LICENSE file that accompanied this code. # # 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. #
function replace_variables {
local filename=$1
local output=$2
local kernel=$3
local test=$4
local op=$5
local init=$6
local guard=$7
local masked=$8
local op_name=$9
local kernel_smoke=${10}
if [ "x${kernel}" != "x" ]; then
local kernel_escaped=$(echo -e "$kernel" | tr '\n''`')
sed "s/\[\[KERNEL\]\]/${kernel_escaped}/g" $filename > ${filename}.current1 cat ${filename}.current1 | tr '`'"\n" > ${filename}.current rm -f "${filename}.current1" else cp $filename ${filename}.current fi
# Check if we need to do multiple replacements # If you want to emit for an operation using lanewise(VectorOperator.**, ..) and also using dedicated instruction (e.g. add(..)), then # pass the 'test' argument as "OPERATOR_NAME+func_Name" (e.g. "ADD+add") # if there is a masked version available for the operation add "withMask" to 'test' argument (e.g. "ADD+add+withMask")
local test_func=""
local withMask=""
local tests=($(awk -F+ '{$1=$1} 1' <<< $test)) if [ "${tests[2]}" == "withMask" ]; then
test=${tests[0]}
test_func=${tests[1]}
withMask=${tests[2]} elif [ "${tests[1]}" == "withMask" ]; then
test=""
test_func=${tests[0]}
withMask=${tests[1]} elif [ "${tests[1]}" != "" ]; then
test=${tests[0]}
test_func=${tests[1]} fi
# Guard the test if necessary if [ "$guard" != "" ]; then echo -e "#if[${guard}]" >> $output fi if [ "$test" != "" ]; then
sed -e "$sed_prog" < ${filename}.current >> $output fi # If we also have a dedicated function for the operation then use 2nd sed expression if [[ "$filename" == *"Unit"* ]] && [ "$test_func" != "" ]; then if [ "$masked" == "" ] || [ "$withMask" != "" ]; then if [ ! -z "$kernel_smoke" ]; then
local kernel_smoke_escaped=$(echo -e "$kernel_smoke" | tr '\n''`')
sed "s/\[\[KERNEL\]\]/${kernel_smoke_escaped}/g" $filename > ${filename}.scurrent1 cat ${filename}.scurrent1 | tr '`'"\n" > ${filename}.scurrent rm -f "${filename}.scurrent1" else cp $filename.current ${filename}.scurrent fi
sed -e "$sed_prog_2" < ${filename}.scurrent >> $output rm -f ${filename}.scurrent fi fi if [ "$guard" != "" ]; then echo -e "#end[${guard}]" >> $output fi
rm -f ${filename}.current
}
function gen_op_tmpl {
local template=$1
local test=$2
local op=$3
local guard=""
local init="" if [ $# -gt 3 ]; then
guard=$4 fi if [ $# == 5 ]; then
init=$5 fi
local masked="" if [[ $template == *"Masked"* ]]; then
masked="Masked" fi
local op_name="" if [[ $template == *"Shift"* ]]; then
op_name="Shift" elif [[ $template == *"Get"* ]]; then
op_name="extract" fi
local kernel_filename="${TEMPLATE_FOLDER}/Kernel-${template}.template"
local kernel_smoke_filename="${TEMPLATE_FOLDER}/Kernel-${template}-smoke.template"
local unit_filename="${TEMPLATE_FOLDER}/Unit-${template}.template" if [ ! -f $unit_filename ]; then # Leverage general unit code snippet if no specialization exists
unit_filename="${TEMPLATE_FOLDER}/Unit-${template%_*}.template" echo $unit_filename fi
local kernel="" if [ -f $kernel_filename ]; then
kernel="$(cat $kernel_filename)" fi
local kernel_smoke="" if [ -f $kernel_smoke_filename ]; then
kernel_smoke="$(cat $kernel_smoke_filename)" else
kernel_smoke="$kernel" fi
# Replace template variables in unit test files (if any)
replace_variables $unit_filename $unit_output "$kernel""$test""$op""$init""$guard""$masked""$op_name""$kernel_smoke"
local gen_perf_tests=$generate_perf_tests
gen_perf_tests=true if [[ $template == *"-Broadcast-"* ]] || [[ $template == "Miscellaneous" ]] ||
[[ $template == *"Compare-Masked"* ]] || [[ $template == *"Compare-Broadcast"* ]]; then
gen_perf_tests=false fi if [ $gen_perf_tests == true ]; then # Replace template variables in performance test files (if any)
local perf_wrapper_filename="${TEMPLATE_FOLDER}/Perf-wrapper.template"
local perf_vector_filename="${TEMPLATE_FOLDER}/Perf-${template}.template"
local perf_scalar_filename="${TEMPLATE_FOLDER}/Perf-Scalar-${template}.template"
if [ -f $perf_vector_filename ]; then
replace_variables $perf_vector_filename $perf_output "$kernel""$test""$op""$init""$guard""$masked""$op_name""" elif [ -f $kernel_filename ]; then
replace_variables $perf_wrapper_filename $perf_output "$kernel""$test""$op""$init""$guard""$masked""$op_name""" elif [[ $template != *"-Scalar-"* ]] && [[ $template != "Get-op" ]] && [[ $template != "With-Op" ]]; then echo"Warning: missing perf: $@" fi
if [ -f $perf_scalar_filename ]; then
replace_variables $perf_scalar_filename $perf_scalar_output "$kernel""$test""$op""$init""$guard""$masked""$op_name""" elif [[ $template != *"-Scalar-"* ]] && [[ $template != "Get-op" ]] && [[ $template != "With-Op" ]]; then echo"Warning: Missing PERF SCALAR: $perf_scalar_filename" fi fi
}
function gen_binary_alu_op { echo"Generating binary op $1 ($2)..."
gen_op_tmpl $binary "$@"
gen_op_tmpl $binary_masked "$@"
}
function gen_binary_alu_bcst_op { echo"Generating binary broadcast op $1 ($2)..."
gen_op_tmpl $binary_broadcast "$@"
gen_op_tmpl $binary_broadcast_masked "$@"
}
function gen_binary_alu_bcst_long_op { echo"Generating binary broadcast long op $1 ($2)..."
gen_op_tmpl $binary_broadcast_long "$@"
gen_op_tmpl $binary_broadcast_masked_long "$@"
}
function gen_shift_op { echo"Generating Shift constant op $1 ($2)..."
gen_op_tmpl $shift_template "$@"
gen_op_tmpl $shift_masked_template "$@"
}
function gen_shift_cst_op { echo"Generating Shift constant op $1 ($2)..."
gen_op_tmpl $shift_const_template "$@"
gen_op_tmpl $shift_masked_const_template "$@"
}
function gen_unary_alu_op { echo"Generating unary op $1 ($2)..."
gen_op_tmpl $unary_scalar "$@"
gen_op_tmpl $unary "$@"
gen_op_tmpl $unary_masked "$@"
}
function gen_ternary_alu_op { echo"Generating ternary op $1 ($2)..."
gen_op_tmpl $ternary_scalar "$@"
gen_op_tmpl $ternary "$@"
gen_op_tmpl $ternary_masked "$@"
}
function gen_ternary_alu_bcst_op { echo"Generating ternary broadcast op $1 ($2)..."
gen_op_tmpl $ternary_broadcast "$@"
gen_op_tmpl $ternary_broadcast_masked "$@"
}
function gen_ternary_alu_double_bcst_op { echo"Generating ternary double broadcast op $1 ($2)..."
gen_op_tmpl $ternary_double_broadcast "$@"
gen_op_tmpl $ternary_double_broadcast_masked "$@"
}
function gen_binary_op { echo"Generating binary op $1 ($2)..." # gen_op_tmpl $binary_scalar "$@"
gen_op_tmpl $binary "$@"
gen_op_tmpl $binary_masked "$@"
}
function gen_binary_op_no_masked { echo"Generating binary op $1 ($2)..." # gen_op_tmpl $binary_scalar "$@"
gen_op_tmpl $binary "$@"
}
function gen_binary_bcst_op_no_masked { echo"Generating binary broadcast op $1 ($2)..."
gen_op_tmpl $binary_broadcast "$@"
}
function gen_compare_op { echo"Generating compare op $1 ($2)..."
gen_op_tmpl $compare_template "$@"
gen_op_tmpl $compare_masked_template "$@"
}
function gen_compare_bcst_op { echo"Generating compare broadcast op $1 ($2)..."
gen_op_tmpl $compare_broadcast_template "$@"
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.