Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks done
Ibrahim25-ai opened this issue Apr 24, 2024 · 2 comments
Closed
2 tasks done
Assignees
Labels
question Further information is requested

Comments

@Ibrahim25-ai
Copy link

Ibrahim25-ai commented Apr 24, 2024

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

  • I agree to follow cuGraph's Code of Conduct
  • I have searched the open issues and have found no duplicates for this question
@Ibrahim25-ai Ibrahim25-ai added the question Further information is requested label Apr 24, 2024
@ChuckHastings
Copy link
Collaborator

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants