cugraph icon indicating copy to clipboard operation
cugraph copied to clipboard

[QST]: How to launc bfs multiple times with different cuda stream_view

Open Ibrahim25-ai opened this issue 10 months ago • 1 comments

raft::resources res; int n_streams = raft::resource::get_stream_pool_size(res); #pragma omp parallel num_threads(MIN(m_threadMax, v_edgeWeight.size())) {

		int threadNum = omp_get_thread_num();
			

#pragma omp for

		for (int i = 0; i < v_edgeWeight.size(); i++)
		{
		int threadNo = omp_get_thread_num();
			int thread_num = threadNo % n_streams;
			cudaStream_t stream = raft::resource::get_stream_from_stream_pool(res, thread_num);
			rmm::cuda_stream_view stream_view(stream);
			std::vector<EdgeWeight> v_edges = v_edgeWeight[i];
			for (long j=0; j<v_edges; j++)
			{
			bool valid1=true;
				if (isPathExist((long)vv1_t, (long)vv2_t, stream_view) ){
	
					valid1 = false;
				}
		-----------------------------------------------
		bool isPathExist(int64_t v1, int64_t v2,rmm::cuda_stream_view stream_view) {
if (!GraphX::graphView) {
        std::cerr << "Graph is not constructed. Please call constructGraphInGPU first." << std::endl;
        return false;
    }
		std::vector<int64_t> sources={v1};
    // Prepare device vectors for BFS output
    rmm::device_uvector<int64_t> distances(GraphX::graphView->number_of_vertices(), stream_view);
    rmm::device_uvector<int64_t> predecessors(GraphX::graphView->number_of_vertices(), stream_view);
	
	rmm::device_uvector<int64_t> d_sources(sources.size(), handle.get_stream());
	raft::update_device(d_sources.data(), sources.data(), sources.size(), handle.get_stream());

//rmm::device_scalar<int64_t> d_source(v1, stream);
cugraph::bfs(
    handle,
    *graphView,
    distances.data(),
    predecessors.data(),
    d_sources.data(),
    d_sources.size(),
    false,
    std::numeric_limits<int64_t>::max(),
    false);		
	-------------------------------------------------
	How can I efficiently launch multiple BFS searches on multiple threads using RAFT to reduce the processing time? I am considering making modifications to the graph each time I find a path and then reconstructing both the graph and its view, which I have set to be shared.

Code of Conduct

  • [X] I agree to follow cuGraph's Code of Conduct
  • [X] I have searched the open issues and have found no duplicates for this question

Ibrahim25-ai avatar Apr 24 '24 16:04 Ibrahim25-ai

We don't have a good solution for this scenario. We have a couple of cases where we take advantage of stream pools internally, but nothing at the top level API. We can explore a better long-term solution.

Here's a hack you could try in the long term... untested:

raft::handle_t new_handle{stream_view};

then use the new_handle when you call BFS. That should create the handle with the stream_view from the stream pool as the default stream.

Note that handle_t in raft is a wrapper for raft::device_resources. The documentation for that is here: https://docs.rapids.ai/api/raft/stable/cpp_api/core_resources/#_CPPv4N4raft16device_resourcesE. If you need them, you can specify other parameters to the constructor that would copy the other resources from the handle.

ChuckHastings avatar Apr 24 '24 16:04 ChuckHastings

Going to close this. If you have further questions, please open a new issue.

ChuckHastings avatar May 16 '24 19:05 ChuckHastings