| 204 | } |
| 205 | |
| 206 | void XlaBuilder::IsConstantVisitor(const int64 op_handle, |
| 207 | absl::flat_hash_set<int64>* visited, |
| 208 | bool* is_constant) const { |
| 209 | if (visited->contains(op_handle) || !*is_constant) { |
| 210 | return; |
| 211 | } |
| 212 | |
| 213 | const HloInstructionProto& instr = |
| 214 | *(LookUpInstructionByHandle(op_handle).ValueOrDie()); |
| 215 | const HloOpcode opcode = StringToHloOpcode(instr.opcode()).ValueOrDie(); |
| 216 | switch (opcode) { |
| 217 | default: |
| 218 | for (const int64 operand_id : instr.operand_ids()) { |
| 219 | IsConstantVisitor(operand_id, visited, is_constant); |
| 220 | } |
| 221 | // TODO(b/32495713): We aren't checking the called computations. |
| 222 | break; |
| 223 | |
| 224 | case HloOpcode::kGetDimensionSize: |
| 225 | // GetDimensionSize is always considered constant in XLA -- If a dynamic |
| 226 | // dimension is presented, -1 is returned. |
| 227 | break; |
| 228 | |
| 229 | // Non functional ops. |
| 230 | case HloOpcode::kRng: |
| 231 | case HloOpcode::kAllReduce: |
| 232 | // TODO(b/33009255): Implement constant folding for cross replica sum. |
| 233 | case HloOpcode::kInfeed: |
| 234 | case HloOpcode::kOutfeed: |
| 235 | case HloOpcode::kCall: |
| 236 | // TODO(b/32495713): We aren't checking the to_apply computation itself, |
| 237 | // so we conservatively say that computations containing the Call op |
| 238 | // cannot be constant. We cannot set is_functional=false in other similar |
| 239 | // cases since we're already relying on IsConstant to return true. |
| 240 | case HloOpcode::kCustomCall: |
| 241 | case HloOpcode::kWhile: |
| 242 | // TODO(b/32495713): We aren't checking the condition and body |
| 243 | // computations themselves. |
| 244 | case HloOpcode::kScatter: |
| 245 | // TODO(b/32495713): We aren't checking the embedded computation in |
| 246 | // Scatter. |
| 247 | case HloOpcode::kSend: |
| 248 | case HloOpcode::kRecv: |
| 249 | case HloOpcode::kParameter: |
| 250 | *is_constant = false; |
| 251 | break; |
| 252 | } |
| 253 | if (!*is_constant) { |
| 254 | VLOG(1) << "Non-constant: " << instr.name(); |
| 255 | } |
| 256 | visited->insert(op_handle); |
| 257 | } |
| 258 | |
| 259 | Status XlaBuilder::SetDynamicBinding(int64 dynamic_size_param_num, |
| 260 | ShapeIndex dynamic_size_param_index, |
nothing calls this directly
no test coverage detected