void sort0_by_key(Param okey, Param oval)
        {
            try {
                compute::command_queue c_queue(getQueue()());

                compute::buffer okey_buf((*okey.data)());
                compute::buffer oval_buf((*oval.data)());

                for(dim_type w = 0; w < okey.info.dims[3]; w++) {
                    dim_type okeyW = w * okey.info.strides[3];
                    dim_type ovalW = w * oval.info.strides[3];
                    for(dim_type z = 0; z < okey.info.dims[2]; z++) {
                        dim_type okeyWZ = okeyW + z * okey.info.strides[2];
                        dim_type ovalWZ = ovalW + z * oval.info.strides[2];
                        for(dim_type y = 0; y < okey.info.dims[1]; y++) {

                            dim_type okeyOffset = okeyWZ + y * okey.info.strides[1];
                            dim_type ovalOffset = ovalWZ + y * oval.info.strides[1];

                            if(isAscending) {
                                compute::sort_by_key(
                                        compute::make_buffer_iterator<Tk>(okey_buf, okeyOffset),
                                        compute::make_buffer_iterator<Tk>(okey_buf, okeyOffset + okey.info.dims[0]),
                                        compute::make_buffer_iterator<Tv>(oval_buf, ovalOffset),
                                        compute::less<Tk>(), c_queue);
                            } else {
                                compute::sort_by_key(
                                        compute::make_buffer_iterator<Tk>(okey_buf, okeyOffset),
                                        compute::make_buffer_iterator<Tk>(okey_buf, okeyOffset + okey.info.dims[0]),
                                        compute::make_buffer_iterator<Tv>(oval_buf, ovalOffset),
                                        compute::greater<Tk>(), c_queue);
                            }
                        }
                    }
                }

                CL_DEBUG_FINISH(getQueue());
            } catch (cl::Error err) {
                CL_TO_AF_ERROR(err);
                throw;
            }
        }
Exemple #2
0
        void sort0(Param val)
        {
            try {
                compute::command_queue c_queue(getQueue()());

                compute::buffer val_buf((*val.data)());

                for(int w = 0; w < val.info.dims[3]; w++) {
                    int valW = w * val.info.strides[3];
                    for(int z = 0; z < val.info.dims[2]; z++) {
                        int valWZ = valW + z * val.info.strides[2];
                        for(int y = 0; y < val.info.dims[1]; y++) {

                            int valOffset = valWZ + y * val.info.strides[1];

                            if(isAscending) {
                                compute::stable_sort(
                                        compute::make_buffer_iterator<T>(val_buf, valOffset),
                                        compute::make_buffer_iterator<T>(val_buf, valOffset + val.info.dims[0]),
                                        compute::less<T>(), c_queue);
                            } else {
                                compute::stable_sort(
                                        compute::make_buffer_iterator<T>(val_buf, valOffset),
                                        compute::make_buffer_iterator<T>(val_buf, valOffset + val.info.dims[0]),
                                        compute::greater<T>(), c_queue);
                            }
                        }
                    }
                }

                CL_DEBUG_FINISH(getQueue());
            } catch (cl::Error err) {
                CL_TO_AF_ERROR(err);
                throw;
            }
        }