diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..008b10f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,130 @@ +# Use an image supported by https://rocm.docs.amd.com/projects/install-on-linux/en/latest/tutorial/quick-start.html +FROM ubuntu:22.04 as build + +# Install necessary packages +RUN apt-get update && \ + apt-get install -y \ + build-essential \ + cmake \ + git \ + wget \ + unzip \ + libtool \ + zlib1g-dev \ + vim-common \ + curl \ + unzip \ + zlib1g \ + python3 \ + python3-pip \ + python3-dev \ + libopenblas-dev \ + opencl-headers \ + clinfo \ + ocl-icd-opencl-dev \ + clang \ + libclang-dev \ + libc++-dev \ + linux-headers-generic \ + software-properties-common \ + libabsl-dev \ + libusb-1.0-0-dev \ + gnupg2 && \ + apt-get clean + +# Install Bazelisk for building TensorFlow +ARG TARGETARCH +RUN wget -O /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.10.1/bazelisk-linux-$TARGETARCH && \ + chmod +x /usr/local/bin/bazel + +ENV TMP=/tmp + +# Clone TensorFlow repository +# https://www.tensorflow.org/install/source#gpu (lib compatibility list) +RUN git clone --depth 1 --branch "v2.16.1" https://github.com/tensorflow/tensorflow + +# ======================= +# build edge TPU delegate +# ======================= + +WORKDIR /tensorflow +RUN git clone https://github.com/google-coral/libedgetpu +WORKDIR /tensorflow/libedgetpu + +# Build TensorFlow Lite GPU delegate (excluding Android, linux only) +ARG TARGETPLATFORM +RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \ + make libedgetpu-direct CPU=k8 && \ + mkdir -p /usr/local/lib && \ + cp /tensorflow/libedgetpu/out/direct/k8/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so; \ + elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \ + make libedgetpu-direct CPU=aarch64 && \ + mkdir -p /usr/local/lib && \ + cp /tensorflow/libedgetpu/out/direct/aarch64/libedgetpu.so.1.0 /usr/local/lib/libedgetpu.so; \ + else \ + echo "Unknown platform"; \ + exit 1; \ + fi + +# ================================== +# Build tensorflow lite GPU delegate +# ================================== + +WORKDIR /tensorflow + +# Configure TensorFlow build (excluding Android) +RUN ./configure < Void), user_data : Void*) - fun interpreter_options_add_registration_external = TfLiteInterpreterOptionsAddRegistrationExternal(options : InterpreterOptions, registration : RegistrationExternal) - type RegistrationExternal = Void* + fun interpreter_options_add_registration_external = TfLiteInterpreterOptionsAddRegistrationExternal(options : InterpreterOptions, registration : LibC::Int*) fun interpreter_options_enable_cancellation = TfLiteInterpreterOptionsEnableCancellation(options : InterpreterOptions, enable : LibC::Int) : Status enum Status Ok = 0 @@ -267,7 +307,8 @@ lib LibTensorflowLite fun tensor_quantization_params = TfLiteTensorQuantizationParams(tensor : Tensor) : QuantizationParams fun tensor_copy_from_buffer = TfLiteTensorCopyFromBuffer(tensor : Tensor, input_data : Void*, input_data_size : LibC::SizeT) : Status fun tensor_copy_to_buffer = TfLiteTensorCopyToBuffer(output_tensor : Tensor, output_data : Void*, output_data_size : LibC::SizeT) : Status - fun registration_external_create = TfLiteRegistrationExternalCreate(builtin_code : BuiltinOperator, custom_name : LibC::Char*, version : LibC::Int) : RegistrationExternal + fun interpreter_reset_variable_tensors = TfLiteInterpreterResetVariableTensors(interpreter : Interpreter) : Status + fun interpreter_options_add_builtin_op = TfLiteInterpreterOptionsAddBuiltinOp(options : InterpreterOptions, op : BuiltinOperator, registration : LibC::Int*, min_version : Int32T, max_version : Int32T) enum BuiltinOperator BuiltinAdd = 0 BuiltinAveragePool2d = 1 @@ -431,23 +472,53 @@ lib LibTensorflowLite BuiltinBitcast = 159 BuiltinBitwiseXor = 160 BuiltinRightShift = 161 + BuiltinStablehloLogistic = 162 + BuiltinStablehloAdd = 163 + BuiltinStablehloDivide = 164 + BuiltinStablehloMultiply = 165 + BuiltinStablehloMaximum = 166 + BuiltinStablehloReshape = 167 + BuiltinStablehloClamp = 168 + BuiltinStablehloConcatenate = 169 + BuiltinStablehloBroadcastInDim = 170 + BuiltinStablehloConvolution = 171 + BuiltinStablehloSlice = 172 + BuiltinStablehloCustomCall = 173 + BuiltinStablehloReduce = 174 + BuiltinStablehloAbs = 175 + BuiltinStablehloAnd = 176 + BuiltinStablehloCosine = 177 + BuiltinStablehloExponential = 178 + BuiltinStablehloFloor = 179 + BuiltinStablehloLog = 180 + BuiltinStablehloMinimum = 181 + BuiltinStablehloNegate = 182 + BuiltinStablehloOr = 183 + BuiltinStablehloPower = 184 + BuiltinStablehloRemainder = 185 + BuiltinStablehloRsqrt = 186 + BuiltinStablehloSelect = 187 + BuiltinStablehloSubtract = 188 + BuiltinStablehloTanh = 189 + BuiltinStablehloScatter = 190 + BuiltinStablehloCompare = 191 + BuiltinStablehloConvert = 192 + BuiltinStablehloDynamicSlice = 193 + BuiltinStablehloDynamicUpdateSlice = 194 + BuiltinStablehloPad = 195 + BuiltinStablehloIota = 196 + BuiltinStablehloDotGeneral = 197 + BuiltinStablehloReduceWindow = 198 + BuiltinStablehloSort = 199 + BuiltinStablehloWhile = 200 + BuiltinStablehloGather = 201 + BuiltinStablehloTranspose = 202 end - fun registration_external_get_built_in_code = TfLiteRegistrationExternalGetBuiltInCode(registration : RegistrationExternal) : BuiltinOperator - fun registration_external_get_version = TfLiteRegistrationExternalGetVersion(registration : RegistrationExternal) : LibC::Int - fun registration_external_get_custom_name = TfLiteRegistrationExternalGetCustomName(registration : RegistrationExternal) : LibC::Char* - fun registration_external_delete = TfLiteRegistrationExternalDelete(registration : RegistrationExternal) - fun registration_external_set_init = TfLiteRegistrationExternalSetInit(registration : RegistrationExternal, init : (OpaqueContext, LibC::Char*, LibC::SizeT -> Void*)) - type OpaqueContext = Void* - fun registration_external_set_free = TfLiteRegistrationExternalSetFree(registration : RegistrationExternal, free : (OpaqueContext, Void* -> Void)) - fun registration_external_set_prepare = TfLiteRegistrationExternalSetPrepare(registration : RegistrationExternal, prepare : (OpaqueContext, OpaqueNode -> Status)) - type OpaqueNode = Void* - fun registration_external_set_invoke = TfLiteRegistrationExternalSetInvoke(registration : RegistrationExternal, invoke : (OpaqueContext, OpaqueNode -> Status)) - fun registration_external_set_async_kernel = TfLiteRegistrationExternalSetAsyncKernel(registration : RegistrationExternal, async_kernel : (OpaqueContext, OpaqueNode -> LibC::Int*)) - fun interpreter_reset_variable_tensors = TfLiteInterpreterResetVariableTensors(interpreter : Interpreter) : Status - fun interpreter_options_add_builtin_op = TfLiteInterpreterOptionsAddBuiltinOp(options : InterpreterOptions, op : BuiltinOperator, registration : LibC::Int*, min_version : Int32T, max_version : Int32T) fun interpreter_options_add_custom_op = TfLiteInterpreterOptionsAddCustomOp(options : InterpreterOptions, name : LibC::Char*, registration : LibC::Int*, min_version : Int32T, max_version : Int32T) - fun interpreter_options_set_op_resolver_external = TfLiteInterpreterOptionsSetOpResolverExternal(options : InterpreterOptions, find_builtin_op : (Void*, LibC::Int, LibC::Int -> RegistrationExternal), find_custom_op : (Void*, LibC::Char*, LibC::Int -> RegistrationExternal), op_resolver_user_data : Void*) + fun interpreter_options_set_op_resolver_external = TfLiteInterpreterOptionsSetOpResolverExternal(options : InterpreterOptions, find_builtin_op : (Void*, LibC::Int, LibC::Int -> LibC::Int*), find_custom_op : (Void*, LibC::Char*, LibC::Int -> LibC::Int*), op_resolver_user_data : Void*) + fun interpreter_options_set_op_resolver_external_with_fallback = TfLiteInterpreterOptionsSetOpResolverExternalWithFallback(options : InterpreterOptions, find_builtin_op_external : (Void*, LibC::Int, LibC::Int -> LibC::Int*), find_custom_op_external : (Void*, LibC::Char*, LibC::Int -> LibC::Int*), find_builtin_op : (Void*, BuiltinOperator, LibC::Int -> LibC::Int*), find_custom_op : (Void*, LibC::Char*, LibC::Int -> LibC::Int*), op_resolver_user_data : Void*) fun interpreter_options_set_op_resolver = TfLiteInterpreterOptionsSetOpResolver(options : InterpreterOptions, find_builtin_op : (Void*, BuiltinOperator, LibC::Int -> LibC::Int*), find_custom_op : (Void*, LibC::Char*, LibC::Int -> LibC::Int*), op_resolver_user_data : Void*) + fun interpreter_options_set_op_resolver_v3 = TfLiteInterpreterOptionsSetOpResolverV3(options : InterpreterOptions, find_builtin_op_v3 : (Void*, BuiltinOperator, LibC::Int -> LibC::Int*), find_custom_op_v3 : (Void*, LibC::Char*, LibC::Int -> LibC::Int*), op_resolver_user_data : Void*) fun interpreter_options_set_op_resolver_v2 = TfLiteInterpreterOptionsSetOpResolverV2(options : InterpreterOptions, find_builtin_op_v2 : (Void*, BuiltinOperator, LibC::Int -> LibC::Int*), find_custom_op_v2 : (Void*, LibC::Char*, LibC::Int -> LibC::Int*), op_resolver_user_data : Void*) fun interpreter_options_set_op_resolver_v1 = TfLiteInterpreterOptionsSetOpResolverV1(options : InterpreterOptions, find_builtin_op_v1 : (Void*, BuiltinOperator, LibC::Int -> LibC::Int*), find_custom_op_v1 : (Void*, LibC::Char*, LibC::Int -> LibC::Int*), op_resolver_user_data : Void*) fun interpreter_create_with_selected_ops = TfLiteInterpreterCreateWithSelectedOps(model : Model, options : InterpreterOptions) : Interpreter @@ -473,4 +544,5 @@ lib LibTensorflowLite fun signature_runner_get_output_tensor = TfLiteSignatureRunnerGetOutputTensor(signature_runner : SignatureRunner, output_name : LibC::Char*) : Tensor fun signature_runner_cancel = TfLiteSignatureRunnerCancel(signature_runner : SignatureRunner) : Status fun signature_runner_delete = TfLiteSignatureRunnerDelete(signature_runner : SignatureRunner) + # fun interpreter_options_set_telemetry_profiler = TfLiteInterpreterOptionsSetTelemetryProfiler(options : InterpreterOptions, profiler : TelemetryProfilerStruct*) end