11 #include <arm_compute/dynamic_fusion/sketch/gpu/operators/GpuCast.h>
12 #include <arm_compute/dynamic_fusion/sketch/gpu/operators/GpuOutput.h>
13 #include <arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadContext.h>
14 #include <arm_compute/dynamic_fusion/sketch/gpu/GpuWorkloadSketch.h>
16 using namespace arm_compute::experimental::dynamic_fusion;
21 static constexpr arm_compute::ConvertPolicy g_AclConvertPolicy = arm_compute::ConvertPolicy::SATURATE;
23 static CastAttributes CastAttributesFromTensorInfo(
const TensorInfo& input)
25 using namespace armcomputetensorutils;
27 CastAttributes cast_attr;
29 cast_attr.data_type(dataType).convert_policy(g_AclConvertPolicy);
35 using namespace armcomputetensorutils;
38 auto compileCtx = arm_compute::CLKernelLibrary::get().get_compile_context();
39 auto workloadContext = GpuWorkloadContext(&compileCtx);
40 GpuWorkloadSketch sketch{ &workloadContext };
42 arm_compute::TensorInfo aclinputInfo = BuildArmComputeTensorInfo(input, input.
GetNumDimensions());
44 aclinputInfo.set_are_values_constant(input.
IsConstant());
46 arm_compute::ITensorInfo* inputInfo0 = workloadContext.create_tensor_info(aclinputInfo);
48 CastAttributes cast_attr = CastAttributesFromTensorInfo(output);
52 const bool validated = aclStatus.error_code() == arm_compute::ErrorCode::OK;
55 std::cout <<
"GpuFsaCastValidate failed: " << aclStatus.error_description() << std::endl;
65 using namespace armcomputetensorutils;
67 GpuWorkloadSketch* sketch = blob->
sketch.get();
69 std::vector<arm_compute::ITensorInfo*> inputTensorInfos = {};
70 std::vector<arm_compute::ITensorInfo*> outputTensorInfos = {};
72 arm_compute::TensorInfo aclinputInfo = BuildArmComputeTensorInfo(input, input.
GetNumDimensions());
74 aclinputInfo.set_are_values_constant(input.
IsConstant());
76 inputTensorInfos.emplace_back(workloadContext->create_tensor_info(aclinputInfo));
78 CastAttributes cast_attr = CastAttributesFromTensorInfo(output);
81 arm_compute::Status aclStatus = GpuCast::validate_op(*sketch, inputTensorInfos[0], cast_attr);
82 const bool validated = aclStatus.error_code() == arm_compute::ErrorCode::OK;
86 +
"\" backend failed during cast operator validation");
89 arm_compute::ITensorInfo* castOutputInfo =
90 GpuCast::create_op(*sketch, inputTensorInfos[0], cast_attr);
93 outputTensorInfos.emplace_back(workloadContext->create_tensor_info());
94 GpuOutput::create_op(*sketch, castOutputInfo, outputTensorInfos[0]);
97 blob->
inputTensorInfos = std::make_unique<std::vector<arm_compute::ITensorInfo*>>(inputTensorInfos);
98 blob->
outputTensorInfos = std::make_unique<std::vector<arm_compute::ITensorInfo*>>(outputTensorInfos);