| 21 | #include "../../example_utils.hpp" |
| 22 | |
| 23 | int main() |
| 24 | { |
| 25 | // Prepare input and output |
| 26 | common::device_ptr<int> input(std::vector{6, 3, 5, 4, 1, 8, 2, 5, 4, 1}); |
| 27 | common::device_ptr<int> key(std::vector{5, 4, 1}); |
| 28 | common::device_ptr<int> output(1); |
| 29 | |
| 30 | // Get required size of the temporary storage |
| 31 | size_t temp_storage_size; |
| 32 | HIP_CHECK(rocprim::search(nullptr, |
| 33 | temp_storage_size, |
| 34 | input.get(), |
| 35 | key.get(), |
| 36 | output.get(), |
| 37 | input.size(), |
| 38 | key.size())); |
| 39 | |
| 40 | // Allocate temporary storage |
| 41 | common::device_ptr<void> temp_storage(temp_storage_size); |
| 42 | |
| 43 | // Perform search |
| 44 | HIP_CHECK(rocprim::search(temp_storage.get(), |
| 45 | temp_storage_size, |
| 46 | input.get(), |
| 47 | key.get(), |
| 48 | output.get(), |
| 49 | input.size(), |
| 50 | key.size())); |
| 51 | |
| 52 | // Check for any errors |
| 53 | HIP_CHECK(hipGetLastError()); |
| 54 | |
| 55 | // Wait for the algorithm to finish |
| 56 | HIP_CHECK(hipDeviceSynchronize()); |
| 57 | |
| 58 | // Copy output to host |
| 59 | auto result = output.load(); |
| 60 | |
| 61 | // Check that the result is correct |
| 62 | ASSERT_TRUE(result[0] == 2); |
| 63 | } |