Kernels.cl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* ============================================================
  2. //--cambine: kernel funtion of Breadth-First-Search
  3. //--author: created by Jianbin Fang
  4. //--date: 06/12/2010
  5. ============================================================ */
  6. #pragma OPENCL EXTENSION cl_khr_byte_addressable_store: enable
  7. //Structure to hold a node information
  8. typedef struct{
  9. int starting;
  10. int no_of_edges;
  11. } Node;
  12. //--7 parameters
  13. __kernel void BFS_1( const __global Node* g_graph_nodes,
  14. const __global int* g_graph_edges,
  15. __global char* g_graph_mask,
  16. __global char* g_updating_graph_mask,
  17. __global char* g_graph_visited,
  18. __global int* g_cost,
  19. const int no_of_nodes){
  20. int tid = get_global_id(0);
  21. if( tid<no_of_nodes && g_graph_mask[tid]){
  22. g_graph_mask[tid]=false;
  23. for(int i=g_graph_nodes[tid].starting; i<(g_graph_nodes[tid].no_of_edges + g_graph_nodes[tid].starting); i++){
  24. int id = g_graph_edges[i];
  25. if(!g_graph_visited[id]){
  26. g_cost[id]=g_cost[tid]+1;
  27. g_updating_graph_mask[id]=true;
  28. }
  29. }
  30. }
  31. }
  32. //--5 parameters
  33. __kernel void BFS_2(__global char* g_graph_mask,
  34. __global char* g_updating_graph_mask,
  35. __global char* g_graph_visited,
  36. __global char* g_over,
  37. const int no_of_nodes
  38. ) {
  39. int tid = get_global_id(0);
  40. if( tid<no_of_nodes && g_updating_graph_mask[tid]){
  41. g_graph_mask[tid]=true;
  42. g_graph_visited[tid]=true;
  43. *g_over=true;
  44. g_updating_graph_mask[tid]=false;
  45. }
  46. }