/** * Copyright (c) 2023 by Contributors * Copyright (c) 2023, GT-TDAlab (Muhammed Fatih Balin & Umit V. Catalyurek) * @file cuda/isin.cu * @brief IsIn operator implementation on CUDA. */ #include #include #include #include "./common.h" namespace graphbolt { namespace ops { torch::Tensor IsIn(torch::Tensor elements, torch::Tensor test_elements) { auto sorted_test_elements = Sort(test_elements); auto allocator = cuda::GetAllocator(); auto stream = cuda::GetCurrentStream(); const auto exec_policy = thrust::cuda::par_nosync(allocator).on(stream); auto result = torch::empty_like(elements, torch::kBool); AT_DISPATCH_INTEGRAL_TYPES( elements.scalar_type(), "IsInOperation", ([&] { thrust::binary_search( exec_policy, sorted_test_elements.data_ptr(), sorted_test_elements.data_ptr() + sorted_test_elements.size(0), elements.data_ptr(), elements.data_ptr() + elements.size(0), result.data_ptr()); })); return result; } } // namespace ops } // namespace graphbolt