per expert: rows [r0, r1) of t1 then of t2 (gate; up), expert-major
| 604 | } |
| 605 | // per expert: rows [r0, r1) of t1 then of t2 (gate; up), expert-major |
| 606 | DW expert_rows2(const Tensor& t1, const Tensor& t2, int r0, int r1, size_t& stride, const char** host_of = nullptr) { |
| 607 | if (t1.type != t2.type || t1.ne[0] != t2.ne[0] || t1.ne[2] != t2.ne[2]) throw std::runtime_error(t1.name + " and " + t2.name + " do not stack"); |
| 608 | row_range(t1, r0, r1); |
| 609 | row_range(t2, r0, r1); |
| 610 | DW w; |
| 611 | w.type = t1.type; |
| 612 | w.n_in = (int) t1.ne[0]; |
| 613 | w.n_out = 2 * (r1 - r0); |
| 614 | w.row_bytes = t1.row_bytes(); |
| 615 | stride = (size_t) w.n_out * w.row_bytes; |
| 616 | const size_t half = (size_t) (r1 - r0) * w.row_bytes, src_mat = (size_t) t1.ne[1] * w.row_bytes; |
| 617 | std::vector<uint8_t> tmp; |
| 618 | const size_t bytes = (size_t) t1.ne[2] * stride; |
| 619 | uint8_t* h = expert_buf(bytes, host_of, tmp); |
| 620 | for (int64_t e = 0; e < t1.ne[2]; ++e) { |
| 621 | std::memcpy(&h[e * stride], t1.data + e * src_mat + (size_t) r0 * w.row_bytes, half); |
| 622 | std::memcpy(&h[e * stride + half], t2.data + e * src_mat + (size_t) r0 * w.row_bytes, half); |
| 623 | } |
| 624 | place(w, h, bytes, stride, host_of); |
| 625 | return w; |
| 626 | } |
| 627 | // f32 tensors' rows one after another |
| 628 | float* f32_cat(const Tensor& t1, const Tensor& t2, size_t row_floats) { |
| 629 | if (t1.type != T_F32 || t2.type != T_F32 || t1.ne[0] != t2.ne[0]) throw std::runtime_error(t1.name + " and " + t2.name + " do not stack"); |
no test coverage detected