Hi,
I’d like to do AOT compilation for Intel GPU, but cannot use Intel GPU offline compilation tool ocloc, please help check if possible to support it.
ComputeCpp expects the offline compilation tool to take arguments in a certain format, and ocloc arguments are in a different form. You can work around this by creating a wrapper script, the following script shows how this could work, though you may wish to create something more suited to your own use.
#!/bin/bash
# Wrap ocloc for use with ComputeCpp.
#
# ComputeCpp expects to pass arguments in the form:
#
# <tool> <in file> -o <out file> <flags>
#
# ocloc expects to recieve arguments in the form:
#
# ocloc -file <in file> -out_dir <out dir> -output <out basename> <flags>
#
# This wrapper translates from the form that ComputeCpp provides into the form
# that ocloc expects, and places the result where ComputeCpp specified. ocloc
# cannot place the result exactly where ComputeCpp expects because it sets the
# suffix, and ComputeCpp may be expecting a different suffix.
#
# This wrapper assumes that input type flags, e.g. `-spirv_input`, will be set
# via the `-sycl-custom-args` passed to ComputeCpp when required. E.g. to
# compile via SPIR-V for a SkyLake GPU using this wrapper:
#
# compute++ <flags> -c file.cpp \
# -sycl-target custom-spirv64 \
# --sycl-custom-tool=ocloc_wrapper \
# -sycl-custom-args "-device skl -spirv_input"
#
# Wrapper was tested on an i7-6560U with an Iris Graphics 540 using driver
# version OpenCL 3.0 NEO 21.46.21636.
function die {
echo "ERROR: $*"
exit 1
}
echo " IN> $(basename $0) $*"
# Data for running ocloc.
INPUT="" # The input source file.
OUTPUT="" # The output binary file.
OUTDIR="" # Directory ocloc will put compiled binaries in.
OUTBASE="" # Filename that ocloc will use.
EXTRA_ARGS="" # Additional compilation flags.
# Argument processing state.
PROCESSED_FIRST_ARGUMENT=0 # Whether we have processed the first argument yet.
NEXT_IS_OUTPUT=0 # When we see '-o' the output name comes next.
INPUT_SUFFIX=".o"
for arg in "$@" ; do
if [ $PROCESSED_FIRST_ARGUMENT -eq 0 ] ; then
# This is the first argument, which we know will be the input file. We
# also generate the OUTDIR and OUTBASE parameter values from the input,
# as the input is a ComputeCpp intermediate file, so we know it should be
# safe to temporarily leave the compiled binary there.
INPUT="$arg"
OUTDIR="$(dirname "$arg")"
OUTBASE="$(basename "${arg%${INPUT_SUFFIX}}")"
PROCESSED_FIRST_ARGUMENT=1
[ ! -e "$arg" ] && echo "WARNING: IN FILE ('$arg') DOES NOT EXIST"
elif [[ "$arg" == "-o" ]] ; then
# Do nothing with this argument, note what to do with the next argument.
NEXT_IS_OUTPUT=1
elif [ $NEXT_IS_OUTPUT -eq 1 ] ; then
# This is the argument after `-o`.
OUTPUT="$arg"
NEXT_IS_OUTPUT=0
else
# We know nothing about this argument, just pass it through to ocloc.
EXTRA_ARGS+=" $arg"
fi
done
[ ! -e "$INPUT" ] && die "Input file in missing."
[ ! -e "$OUTDIR" ] && die "Temporary output directory is missing."
# Where ocloc will place binaries, we will use `-output_no_suffix` below so
# that the names are not affected by device-specific compilation flags.
TMP_CPU="$OUTDIR"/"$OUTBASE" # Unused in this wrapper.
TMP_GPU="$OUTDIR"/"$OUTBASE".gen
# Run ocloc!
echo -n "OUT> ocloc -file \"$INPUT\""
echo -n " -out_dir \"$OUTDIR\" -output \"$OUTBASE\""
echo " -output_no_suffix $EXTRA_ARGS"
ocloc -file "$INPUT" \
-out_dir "$OUTDIR" -output "$OUTBASE" \
-output_no_suffix $EXTRA_ARGS \
|| die "ocloc returned an error code"
# Move the result to where ComputeCpp expects it to be.
[ ! -e "$TMP_GPU" ] && die "No GPU output file produced ($TMP_GPU)"
echo " MV> $TMP_GPU --> $OUTPUT"
mv "$TMP_GPU" "$OUTPUT" || die "Could not move result"
Thanks, the wrapper works from my side after remove .gen from TMP_GPU.
ocloc is intel official tool, hope for future computecpp release to adapt it. Thanks.