| 38 | } |
| 39 | |
| 40 | Status GetBroadcastSize(const int index, const int in_size, const int ksize, |
| 41 | const int stride, const int pad_size, int* bindex, |
| 42 | int* bsize) { |
| 43 | // Cannot have index beyond the input size. |
| 44 | if (index * stride > in_size) { |
| 45 | return errors::InvalidArgument( |
| 46 | "index * stride must be less than or equal to input size"); |
| 47 | } |
| 48 | *bindex = index * stride; |
| 49 | *bsize = ksize; |
| 50 | if (*bindex < pad_size) { |
| 51 | // If the current index is in the padding area, start broadcast from index |
| 52 | // 0 with broadcast size reduced by padding size. |
| 53 | *bsize = ksize + *bindex - pad_size; |
| 54 | *bindex = 0; |
| 55 | } else { |
| 56 | // Otherwise, start broadcast from current index reduced by padding size. |
| 57 | *bindex -= pad_size; |
| 58 | } |
| 59 | if (*bindex + ksize > in_size) { |
| 60 | *bsize = std::min((in_size - *bindex), ksize); |
| 61 | } |
| 62 | return Status::OK(); |
| 63 | } |
| 64 | |
| 65 | string SanitizeThreadSuffix(string suffix) { |
| 66 | string clean; |