| 53 | // Host function that runs example_shared_memory kernel |
| 54 | template<class T> |
| 55 | void run_example_shared_memory(size_t size) |
| 56 | { |
| 57 | constexpr unsigned int block_size = 256; |
| 58 | // Make sure size is a multiple of block_size |
| 59 | unsigned int grid_size = (size + block_size - 1) / block_size; |
| 60 | size = block_size * grid_size; |
| 61 | |
| 62 | // Generate input on host and copy it to device |
| 63 | std::vector<T> host_input = get_random_data<T>(size, 0, 1000); |
| 64 | // Generating expected output for kernel |
| 65 | std::vector<T> host_expected_output = get_expected_output<T>(host_input, block_size); |
| 66 | // For reading device output |
| 67 | std::vector<T> host_output(size); |
| 68 | |
| 69 | // Device memory allocation |
| 70 | T* device_input; |
| 71 | T* device_output; |
| 72 | HIP_CHECK(hipMalloc(&device_input, |
| 73 | host_input.size() * sizeof(typename decltype(host_input)::value_type))); |
| 74 | HIP_CHECK(hipMalloc(&device_output, |
| 75 | host_output.size() * sizeof(typename decltype(host_output)::value_type))); |
| 76 | |
| 77 | // Writing input data to device memory |
| 78 | hip_write_device_memory<T>(device_input, host_input); |
| 79 | |
| 80 | // Launching kernel example_shared_memory |
| 81 | hipLaunchKernelGGL(HIP_KERNEL_NAME(example_shared_memory<block_size, T>), |
| 82 | dim3(grid_size), |
| 83 | dim3(block_size), |
| 84 | 0, |
| 85 | 0, |
| 86 | device_input, |
| 87 | device_output); |
| 88 | |
| 89 | // Reading output from device |
| 90 | hip_read_device_memory<T>(host_output, device_output); |
| 91 | |
| 92 | // Validating output |
| 93 | OUTPUT_VALIDATION_CHECK(validate_device_output(host_output, host_expected_output)); |
| 94 | |
| 95 | HIP_CHECK(hipFree(device_input)); |
| 96 | HIP_CHECK(hipFree(device_output)); |
| 97 | |
| 98 | std::cout << "Kernel run_example_shared_memory run was successful!" << std::endl; |
| 99 | } |
| 100 | |
| 101 | // Kernel 2 - storage_type for one primitive union'ed with storage_type of other primitive |
| 102 | template<const unsigned int BlockSize, const unsigned int ItemsPerThread, class T> |
nothing calls this directly
no test coverage detected