| 30 | |
| 31 | template<typename T> |
| 32 | void assign(Array<T>& out, const af_index_t idxrs[], const Array<T>& rhs) { |
| 33 | kernel::AssignKernelParam_t p; |
| 34 | std::vector<af_seq> seqs(4, af_span); |
| 35 | // create seq vector to retrieve output |
| 36 | // dimensions, offsets & offsets |
| 37 | for (dim_t x = 0; x < 4; ++x) { |
| 38 | if (idxrs[x].isSeq) { seqs[x] = idxrs[x].idx.seq; } |
| 39 | } |
| 40 | |
| 41 | // retrieve dimensions, strides and offsets |
| 42 | const dim4& dDims = out.dims(); |
| 43 | // retrieve dimensions & strides for array |
| 44 | // to which rhs is being copied to |
| 45 | dim4 dstOffs = toOffset(seqs, dDims); |
| 46 | dim4 dstStrds = toStride(seqs, dDims); |
| 47 | |
| 48 | for (dim_t i = 0; i < 4; ++i) { |
| 49 | p.isSeq[i] = idxrs[i].isSeq; |
| 50 | p.offs[i] = dstOffs[i]; |
| 51 | p.strds[i] = dstStrds[i]; |
| 52 | } |
| 53 | |
| 54 | cl::Buffer* bPtrs[4]; |
| 55 | |
| 56 | std::vector<Array<uint>> idxArrs(4, createEmptyArray<uint>(dim4())); |
| 57 | |
| 58 | // Prepare commonBuffer for empty indexes |
| 59 | // Buffer is dependent on the context. |
| 60 | // To avoid copying between devices, we add also deviceId as a dependency |
| 61 | cl::Buffer* emptyBuffer; |
| 62 | { |
| 63 | std::lock_guard<std::mutex> lck(mtx); |
| 64 | const auto dependent = std::make_pair<const cl::Context*, const int>( |
| 65 | &getContext(), getActiveDeviceId()); |
| 66 | auto it = cachedEmptyBuffers.find(dependent); |
| 67 | if (it == cachedEmptyBuffers.end()) { |
| 68 | emptyBuffer = new cl::Buffer( |
| 69 | getContext(), |
| 70 | CL_MEM_READ_ONLY, // NOLINT(hicpp-signed-bitwise) |
| 71 | sizeof(uint)); |
| 72 | cachedEmptyBuffers[dependent] = emptyBuffer; |
| 73 | } else { |
| 74 | emptyBuffer = it->second; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // look through indexs to read af_array indexs |
| 79 | for (dim_t x = 0; x < 4; ++x) { |
| 80 | // set index pointers were applicable |
| 81 | if (!p.isSeq[x]) { |
| 82 | idxArrs[x] = castArray<uint>(idxrs[x].idx.arr); |
| 83 | bPtrs[x] = idxArrs[x].get(); |
| 84 | } else { |
| 85 | // alloc an 1-element buffer to avoid OpenCL from failing using |
| 86 | // direct buffer allocation as opposed to mem manager to avoid |
| 87 | // reference count desprepancies between different backends |
| 88 | bPtrs[x] = emptyBuffer; |
| 89 | } |
nothing calls this directly
no test coverage detected