MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / main

Function main

python/2_CoreConcepts/binarySearch/binarySearch.py:107–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

105
106
107def main():
108 import argparse
109
110 parser = argparse.ArgumentParser(
111 description="Parallel upper_bound / lower_bound via cuda.compute"
112 )
113 parser.add_argument("--device", type=int, default=0, help="CUDA device id")
114 args = parser.parse_args()
115
116 device = Device(args.device)
117 device.set_current()
118 print_gpu_info(device)
119 print()
120
121 ok = True
122
123 # Case 1: values both inside and outside the data range; no duplicates
124 # in the data. lower_bound and upper_bound agree on values not present.
125 print("Case 1: distinct data, mixed queries")
126 h_data1 = np.array([1, 3, 5, 7, 9], dtype=np.int32)
127 h_values1 = np.array([0, 3, 4, 10], dtype=np.int32)
128 ok &= run_binary_search(h_data1, h_values1)
129 print()
130
131 # Case 2: duplicates in the data so lower_bound and upper_bound diverge
132 # on present values.
133 print("Case 2: duplicates in data")
134 h_data2 = np.array([1, 3, 3, 5, 7, 9], dtype=np.int32)
135 h_values2 = np.array([3, 3, 5, 8], dtype=np.int32)
136 ok &= run_binary_search(h_data2, h_values2)
137
138 print()
139 if ok:
140 print("Done")
141 return 0
142 print("FAILED")
143 return 1
144
145
146if __name__ == "__main__":

Callers 1

binarySearch.pyFile · 0.70

Calls 2

print_gpu_infoFunction · 0.90
run_binary_searchFunction · 0.85

Tested by

no test coverage detected