| 500 | } |
| 501 | |
| 502 | std::shared_ptr<KernelWrap> OpenCLRuntime::buildKernelWithCache(const std::string &programName, const std::string &kernelName, |
| 503 | const std::set<std::string> &buildOptions, int precisionLevel, const Tensor *input, const Tensor *output, bool useCache) { |
| 504 | std::string buildOptionsStr; |
| 505 | if (precisionLevel == 2) {// Fp16 Memory and fp16 compute |
| 506 | buildOptionsStr = "-DFLOAT=half -DFLOAT2=half2 -DFLOAT3=half3 -DFLOAT4=half4 -DFLOAT8=half8 -DFLOAT16=half16 -DCOMPUTE_FLOAT=half -DCOMPUTE_FLOAT2=half2 -DCOMPUTE_FLOAT3=half3 -DCOMPUTE_FLOAT4=half4 -DCOMPUTE_FLOAT8=half8 -DCOMPUTE_FLOAT16=half16 -DCONVERT_COMPUTE_FLOAT=convert_half -DCONVERT_COMPUTE_FLOAT2=convert_half2 -DCONVERT_COMPUTE_FLOAT3=convert_half3 -DCONVERT_COMPUTE_FLOAT4=convert_half4 -DCONVERT_COMPUTE_FLOAT8=convert_half8 -DCONVERT_COMPUTE_FLOAT16=convert_half16 -DRI_F=read_imageh -DWI_F=write_imageh -DCONVERT_FLOAT=convert_half -DCONVERT_FLOAT2=convert_half2 -DCONVERT_FLOAT3=convert_half3 -DCONVERT_FLOAT4=convert_half4 -DCONVERT_FLOAT8=convert_half8 -DCONVERT_FLOAT16=convert_half16 -DMNN_SUPPORT_FP16"; |
| 507 | } else if (precisionLevel == 0) {// Fp16 Memory and fp32 compute |
| 508 | buildOptionsStr = "-DFLOAT=half -DFLOAT2=half2 -DFLOAT3=half3 -DFLOAT4=half4 -DFLOAT8=half8 -DFLOAT16=half16 -DCOMPUTE_FLOAT=float -DCOMPUTE_FLOAT2=float2 -DCOMPUTE_FLOAT3=float3 -DCOMPUTE_FLOAT4=float4 -DCOMPUTE_FLOAT8=float8 -DCOMPUTE_FLOAT16=float16 -DCONVERT_COMPUTE_FLOAT=convert_float -DCONVERT_COMPUTE_FLOAT2=convert_float2 -DCONVERT_COMPUTE_FLOAT3=convert_float3 -DCONVERT_COMPUTE_FLOAT4=convert_float4 -DCONVERT_COMPUTE_FLOAT8=convert_float8 -DCONVERT_COMPUTE_FLOAT16=convert_float16 -DCONVERT_FLOAT=convert_half -DCONVERT_FLOAT2=convert_half2 -DCONVERT_FLOAT3=convert_half3 -DCONVERT_FLOAT4=convert_half4 -DCONVERT_FLOAT8=convert_half8 -DCONVERT_FLOAT16=convert_half16 -DRI_F=read_imageh -DWI_F=write_imageh -DMNN_SUPPORT_FP16"; |
| 509 | } else {// Fp32 Memory and fp32 compute |
| 510 | buildOptionsStr = "-DFLOAT=float -DFLOAT2=float2 -DFLOAT3=float3 -DFLOAT4=float4 -DFLOAT8=float8 -DFLOAT16=float16 -DCOMPUTE_FLOAT=float -DCOMPUTE_FLOAT2=float2 -DCOMPUTE_FLOAT3=float3 -DCOMPUTE_FLOAT4=float4 -DCOMPUTE_FLOAT8=float8 -DCOMPUTE_FLOAT16=float16 -DCONVERT_COMPUTE_FLOAT=convert_float -DCONVERT_COMPUTE_FLOAT2=convert_float2 -DCONVERT_COMPUTE_FLOAT3=convert_float3 -DCONVERT_COMPUTE_FLOAT4=convert_float4 -DCONVERT_COMPUTE_FLOAT8=convert_float8 -DCONVERT_COMPUTE_FLOAT16=convert_float16 -DRI_F=read_imagef -DFLOAT16=float16 -DWI_F=write_imagef -DCONVERT_FLOAT=convert_float -DCONVERT_FLOAT2=convert_float2 -DCONVERT_FLOAT3=convert_float3 -DCONVERT_FLOAT4=convert_float4 -DCONVERT_FLOAT8=convert_float8 -DCONVERT_FLOAT16=convert_float16"; |
| 511 | } |
| 512 | |
| 513 | if(nullptr != input){ |
| 514 | if(input->getType().code == halide_type_int) { |
| 515 | buildOptionsStr += " -DINPUT_TYPE_I=int"; |
| 516 | buildOptionsStr += " -DINPUT_TYPE_I4=int4"; |
| 517 | if(input->getType().bits == 8){ |
| 518 | buildOptionsStr += " -DINPUT_TYPE=char"; |
| 519 | buildOptionsStr += " -DINPUT_TYPE4=char4"; |
| 520 | buildOptionsStr += " -DRI_DATA=read_imagei"; |
| 521 | } else if(input->getType().bits == 32){ |
| 522 | buildOptionsStr += " -DINPUT_TYPE=int"; |
| 523 | buildOptionsStr += " -DINPUT_TYPE4=int4"; |
| 524 | buildOptionsStr += " -DRI_DATA=read_imagei"; |
| 525 | } else { |
| 526 | MNN_PRINT("opencl input datatype not support, bit:%d\n", input->getType().bits); |
| 527 | MNN_ASSERT(false); |
| 528 | } |
| 529 | } else if(input->getType().code == halide_type_uint){ |
| 530 | buildOptionsStr += " -DINPUT_TYPE_I=uint"; |
| 531 | buildOptionsStr += " -DINPUT_TYPE_I4=uint4"; |
| 532 | if(input->getType().bits == 8){ |
| 533 | buildOptionsStr += " -DINPUT_TYPE=uchar"; |
| 534 | buildOptionsStr += " -DINPUT_TYPE4=uchar4"; |
| 535 | buildOptionsStr += " -DRI_DATA=read_imageui"; |
| 536 | } else if(input->getType().bits == 32){ |
| 537 | buildOptionsStr += " -DINPUT_TYPE=uint"; |
| 538 | buildOptionsStr += " -DINPUT_TYPE4=uint4"; |
| 539 | buildOptionsStr += " -DRI_DATA=read_imageui"; |
| 540 | } else { |
| 541 | MNN_PRINT("opencl input datatype not support, bit:%d\n", input->getType().bits); |
| 542 | MNN_ASSERT(false); |
| 543 | } |
| 544 | } else { |
| 545 | if(precisionLevel != 1){ |
| 546 | buildOptionsStr += " -DINPUT_TYPE_I=half"; |
| 547 | buildOptionsStr += " -DINPUT_TYPE_I4=half4"; |
| 548 | buildOptionsStr += " -DINPUT_TYPE=half"; |
| 549 | buildOptionsStr += " -DINPUT_TYPE4=half4"; |
| 550 | buildOptionsStr += " -DINPUT_TYPE16=half16"; |
| 551 | buildOptionsStr += " -DRI_DATA=read_imageh"; |
| 552 | }else{ |
| 553 | buildOptionsStr += " -DINPUT_TYPE_I=float"; |
| 554 | buildOptionsStr += " -DINPUT_TYPE_I4=float4"; |
| 555 | buildOptionsStr += " -DINPUT_TYPE=float"; |
| 556 | buildOptionsStr += " -DINPUT_TYPE4=float4"; |
| 557 | buildOptionsStr += " -DINPUT_TYPE16=float16"; |
| 558 | buildOptionsStr += " -DRI_DATA=read_imagef"; |
| 559 | } |
no test coverage detected