Lines Matching refs:aq
296 struct goacc_asyncqueue *aq;
2097 If AQ is NULL then agent->sync_queue will be used. */
2102 struct goacc_asyncqueue *aq, bool module_locked)
2123 (aq ? aq->id : 0));
2159 hsa_queue_t *command_q = (aq ? aq->hsa_queue : kernel->agent->sync_queue);
2544 execute_queue_entry (struct goacc_asyncqueue *aq, int index)
2546 struct queue_entry *entry = &aq->queue[index];
2553 aq->agent->device_id, aq->id, index);
2556 &entry->u.launch.kla, aq, false);
2559 aq->agent->device_id, aq->id, index);
2565 aq->agent->device_id, aq->id, index);
2569 aq->agent->device_id, aq->id, index);
2580 aq->agent->device_id, aq->id, index);
2597 "entry (%d) done\n", aq->agent->device_id, aq->id, index);
2619 struct goacc_asyncqueue *aq = thread_arg;
2623 aq->drain_queue_stop = 2;
2627 pthread_mutex_lock (&aq->mutex);
2631 if (aq->drain_queue_stop)
2634 if (aq->queue_n > 0)
2636 pthread_mutex_unlock (&aq->mutex);
2637 execute_queue_entry (aq, aq->queue_first);
2639 pthread_mutex_lock (&aq->mutex);
2640 aq->queue_first = ((aq->queue_first + 1)
2642 aq->queue_n--;
2646 aq->agent->device_id, aq->id);
2647 pthread_cond_broadcast (&aq->queue_cond_out);
2648 pthread_mutex_unlock (&aq->mutex);
2651 GCN_DEBUG ("Async thread %d:%d: continue\n", aq->agent->device_id,
2652 aq->id);
2653 pthread_mutex_lock (&aq->mutex);
2659 aq->agent->device_id, aq->id);
2660 pthread_cond_wait (&aq->queue_cond_in, &aq->mutex);
2663 aq->agent->device_id, aq->id);
2667 aq->drain_queue_stop = 2;
2670 aq->agent->device_id, aq->id);
2671 pthread_cond_broadcast (&aq->queue_cond_out);
2672 pthread_mutex_unlock (&aq->mutex);
2674 GCN_DEBUG ("Async thread %d:%d: returning\n", aq->agent->device_id, aq->id);
2682 drain_queue_synchronous (struct goacc_asyncqueue *aq)
2684 pthread_mutex_lock (&aq->mutex);
2686 while (aq->queue_n > 0)
2688 execute_queue_entry (aq, aq->queue_first);
2690 aq->queue_first = ((aq->queue_first + 1)
2692 aq->queue_n--;
2695 pthread_mutex_unlock (&aq->mutex);
2698 /* Block the current thread until an async queue is writable. The aq->mutex
2702 wait_for_queue_nonfull (struct goacc_asyncqueue *aq)
2704 if (aq->queue_n == ASYNC_QUEUE_SIZE)
2707 while (aq->queue_n == ASYNC_QUEUE_SIZE)
2708 pthread_cond_wait (&aq->queue_cond_out, &aq->mutex);
2717 queue_push_launch (struct goacc_asyncqueue *aq, struct kernel_info *kernel,
2720 assert (aq->agent == kernel->agent);
2722 pthread_mutex_lock (&aq->mutex);
2724 wait_for_queue_nonfull (aq);
2726 int queue_last = ((aq->queue_first + aq->queue_n)
2729 GCN_DEBUG ("queue_push_launch %d:%d: at %i\n", aq->agent->device_id,
2730 aq->id, queue_last);
2732 aq->queue[queue_last].type = KERNEL_LAUNCH;
2733 aq->queue[queue_last].u.launch.kernel = kernel;
2734 aq->queue[queue_last].u.launch.vars = vars;
2735 aq->queue[queue_last].u.launch.kla = *kla;
2737 aq->queue_n++;
2741 aq->agent->device_id, aq->id);
2742 pthread_cond_signal (&aq->queue_cond_in);
2744 pthread_mutex_unlock (&aq->mutex);
2752 queue_push_callback (struct goacc_asyncqueue *aq, void (*fn)(void *),
2755 pthread_mutex_lock (&aq->mutex);
2757 wait_for_queue_nonfull (aq);
2759 int queue_last = ((aq->queue_first + aq->queue_n)
2762 GCN_DEBUG ("queue_push_callback %d:%d: at %i\n", aq->agent->device_id,
2763 aq->id, queue_last);
2765 aq->queue[queue_last].type = CALLBACK;
2766 aq->queue[queue_last].u.callback.fn = fn;
2767 aq->queue[queue_last].u.callback.data = data;
2769 aq->queue_n++;
2773 aq->agent->device_id, aq->id);
2774 pthread_cond_signal (&aq->queue_cond_in);
2776 pthread_mutex_unlock (&aq->mutex);
2785 queue_push_asyncwait (struct goacc_asyncqueue *aq,
2788 pthread_mutex_lock (&aq->mutex);
2790 aq);
2792 int queue_last = ((aq->queue_first + aq->queue_n) % ASYNC_QUEUE_SIZE);
2794 GCN_DEBUG ("queue_push_asyncwait %d:%d: at %i\n", aq->agent->device_id,
2795 aq->id, queue_last);
2797 aq->queue[queue_last].type = ASYNC_WAIT;
2798 aq->queue[queue_last].u.asyncwait.placeholderp = placeholderp;
2800 aq->queue_n++;
2804 aq->agent->device_id, aq->id);
2805 pthread_cond_signal (&aq->queue_cond_in);
2807 pthread_mutex_unlock (&aq->mutex);
2815 queue_push_placeholder (struct goacc_asyncqueue *aq)
2819 pthread_mutex_lock (&aq->mutex);
2821 wait_for_queue_nonfull (aq);
2823 int queue_last = ((aq->queue_first + aq->queue_n) % ASYNC_QUEUE_SIZE);
2825 GCN_DEBUG ("queue_push_placeholder %d:%d: at %i\n", aq->agent->device_id,
2826 aq->id, queue_last);
2828 aq->queue[queue_last].type = ASYNC_PLACEHOLDER;
2829 placeholderp = &aq->queue[queue_last].u.placeholder;
2833 pthread_mutex_unlock (&aq->mutex);
2839 pthread_mutex_unlock (&aq->mutex);
2845 aq->queue_n++;
2849 aq->agent->device_id, aq->id);
2850 pthread_cond_signal (&aq->queue_cond_in);
2852 pthread_mutex_unlock (&aq->mutex);
2860 finalize_async_thread (struct goacc_asyncqueue *aq)
2862 pthread_mutex_lock (&aq->mutex);
2863 if (aq->drain_queue_stop == 2)
2865 pthread_mutex_unlock (&aq->mutex);
2869 aq->drain_queue_stop = 1;
2873 aq->agent->device_id, aq->id);
2874 pthread_cond_signal (&aq->queue_cond_in);
2876 while (aq->drain_queue_stop != 2)
2880 " to sleep\n", aq->agent->device_id, aq->id);
2881 pthread_cond_wait (&aq->queue_cond_out, &aq->mutex);
2884 aq->agent->device_id, aq->id);
2887 GCN_DEBUG ("Done waiting for async thread %d:%d\n", aq->agent->device_id,
2888 aq->id);
2889 pthread_mutex_unlock (&aq->mutex);
2891 int err = pthread_join (aq->thread_drain_queue, NULL);
2894 aq->agent->device_id, aq->id, strerror (err));
2895 GCN_DEBUG ("Joined with async thread %d:%d\n", aq->agent->device_id, aq->id);
2944 data->aq->agent->device_id, data->aq->id, data->len, data->src,
2963 queue_push_copy (struct goacc_asyncqueue *aq, void *dst, const void *src,
2968 aq->agent->device_id, aq->id, len, src, dst);
2974 data->aq = aq;
2975 queue_push_callback (aq, copy_data, data);
2981 queue_empty (struct goacc_asyncqueue *aq)
2983 pthread_mutex_lock (&aq->mutex);
2984 int res = aq->queue_n == 0 ? 1 : 0;
2985 pthread_mutex_unlock (&aq->mutex);
2994 wait_queue (struct goacc_asyncqueue *aq)
2998 drain_queue_synchronous (aq);
3002 pthread_mutex_lock (&aq->mutex);
3004 while (aq->queue_n > 0)
3008 aq->agent->device_id, aq->id);
3009 pthread_cond_wait (&aq->queue_cond_out, &aq->mutex);
3011 GCN_DEBUG ("thread %d:%d woke up. Rechecking\n", aq->agent->device_id,
3012 aq->id);
3015 pthread_mutex_unlock (&aq->mutex);
3016 GCN_DEBUG ("waiting for thread %d:%d, done\n", aq->agent->device_id, aq->id);
3027 struct goacc_asyncqueue *aq)
3159 queue_push_launch (aq, kernel, ind_da, &kla);
3162 aq->agent->device_id, aq->id, ind_da);
3163 queue_push_callback (aq, gomp_offload_free, ind_da);
3825 struct goacc_asyncqueue *aq)
3830 aq);
3842 struct goacc_asyncqueue *aq = GOMP_PLUGIN_malloc (sizeof (*aq));
3843 aq->agent = get_agent_info (device);
3844 aq->prev = NULL;
3845 aq->next = agent->async_queues;
3846 if (aq->next)
3848 aq->next->prev = aq;
3849 aq->id = aq->next->id + 1;
3852 aq->id = 1;
3853 agent->async_queues = aq;
3855 aq->queue_first = 0;
3856 aq->queue_n = 0;
3857 aq->drain_queue_stop = 0;
3859 if (pthread_mutex_init (&aq->mutex, NULL))
3864 if (pthread_cond_init (&aq->queue_cond_in, NULL))
3869 aq->queue_cond_out, NULL))
3880 &aq->hsa_queue);
3884 int err = pthread_create (&aq->thread_drain_queue, NULL, &drain_queue, aq);
3888 GCN_DEBUG ("Async thread %d:%d: created\n", aq->agent->device_id,
3889 aq->id);
3893 return aq;
3900 GOMP_OFFLOAD_openacc_async_destruct (struct goacc_asyncqueue *aq)
3902 struct agent_info *agent = aq->agent;
3904 finalize_async_thread (aq);
3909 if ((err = pthread_mutex_destroy (&aq->mutex)))
3914 if (pthread_cond_destroy (&aq->queue_cond_in))
3919 if (pthread_cond_destroy (&aq->queue_cond_out))
3924 hsa_status_t status = hsa_fns.hsa_queue_destroy_fn (aq->hsa_queue);
3931 if (aq->prev)
3932 aq->prev->next = aq->next;
3933 if (aq->next)
3934 aq->next->prev = aq->prev;
3935 if (agent->async_queues == aq)
3936 agent->async_queues = aq->next;
3938 GCN_DEBUG ("Async thread %d:%d: destroyed\n", agent->device_id, aq->id);
3940 free (aq);
3952 GOMP_OFFLOAD_openacc_async_test (struct goacc_asyncqueue *aq)
3954 return queue_empty (aq);
3961 GOMP_OFFLOAD_openacc_async_synchronize (struct goacc_asyncqueue *aq)
3963 wait_queue (aq);
3988 GOMP_OFFLOAD_openacc_async_queue_callback (struct goacc_asyncqueue *aq,
3991 queue_push_callback (aq, fn, data);
3998 size_t n, struct goacc_asyncqueue *aq)
4001 assert (agent == aq->agent);
4002 queue_push_copy (aq, dst, src, n);
4010 size_t n, struct goacc_asyncqueue *aq)
4013 assert (agent == aq->agent);
4014 queue_push_copy (aq, dst, src, n);