MCPcopy Create free account
hub / github.com/ROCm/rocPRIM / main

Function main

example/rocprim/device/example_device_search.cpp:23–63  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21#include "../../example_utils.hpp"
22
23int 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}

Callers

nothing calls this directly

Calls 4

searchFunction · 0.85
getMethod · 0.45
sizeMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected