| 43 | CLCacheExample() = default; |
| 44 | |
| 45 | bool do_setup(int argc, char **argv) override |
| 46 | { |
| 47 | std::cout << "Once the program has run and created the file cache.bin, rerun with --restore_cache." |
| 48 | << std::endl; |
| 49 | CLScheduler::get().default_init(); |
| 50 | |
| 51 | if (argc > 1) |
| 52 | { |
| 53 | std::string argv1 = argv[1]; |
| 54 | std::transform(argv1.begin(), argv1.end(), argv1.begin(), ::tolower); |
| 55 | if (argv1 == "--restore_cache") |
| 56 | { |
| 57 | // Load the precompiled kernels from a file into the kernel library, in this way the next time they are needed |
| 58 | // compilation won't be required. |
| 59 | restore_program_cache_from_file(); |
| 60 | } |
| 61 | else |
| 62 | { |
| 63 | std::cout << "Unkown option " << argv1 << std::endl; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // Initialise shapes |
| 68 | init_tensor(TensorShape(8U, 4U, 2U), tensor_nchw, DataType::U8, DataLayout::NCHW); |
| 69 | init_tensor(TensorShape(2U, 8U, 4U), tensor_nhwc, DataType::U8, DataLayout::NHWC); |
| 70 | init_tensor(TensorShape(8U, 4U, 2U), tensor_nchw_result, DataType::U8, DataLayout::NCHW); |
| 71 | |
| 72 | // Create the permutation vector to turn a NCHW tensor to NHWC. |
| 73 | // The input tensor is NCHW, which means that the fastest changing coordinate is W=8U. |
| 74 | // For permutation vectors the fastest changing coordinate is the one on the left too. |
| 75 | // Each element in the permutation vector specifies a mapping from the source tensor to the destination one, thus if we |
| 76 | // use 2U in the permutation vector's first element we are telling the function to move the channels to the fastest |
| 77 | // changing coordinate in the destination tensor. |
| 78 | |
| 79 | const PermutationVector vector_nchw_to_nhwc(2U, 0U, 1U); |
| 80 | permute_nhwc.configure(&tensor_nchw, &tensor_nhwc, vector_nchw_to_nhwc); |
| 81 | |
| 82 | // Allocate and fill tensors |
| 83 | tensor_nhwc.allocator()->allocate(); |
| 84 | tensor_nchw.allocator()->allocate(); |
| 85 | fill_tensor(tensor_nchw); |
| 86 | |
| 87 | // Demostrate autoconfigure for the output tensor |
| 88 | const PermutationVector vector_nhwc_to_nchw(1U, 2U, 0U); |
| 89 | permute_nchw.configure(&tensor_nhwc, &tensor_nchw_result, vector_nhwc_to_nchw); |
| 90 | tensor_nchw_result.allocator()->allocate(); |
| 91 | |
| 92 | // Save the opencl kernels to a file |
| 93 | save_program_cache_to_file(); |
| 94 | |
| 95 | return true; |
| 96 | } |
| 97 | void do_run() override |
| 98 | { |
| 99 | permute_nhwc.run(); |
nothing calls this directly
no test coverage detected