| 187 | } |
| 188 | |
| 189 | spv_result_t ValidateTensorQuerySize(ValidationState_t& _, |
| 190 | const Instruction* inst) { |
| 191 | // Check result type |
| 192 | if (!_.IsIntScalarType(inst->type_id())) { |
| 193 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 194 | << "Expected Result Type to be an integer type scalar"; |
| 195 | } |
| 196 | |
| 197 | // Check Tensor operand |
| 198 | auto op_tensor = inst->word(3); |
| 199 | auto inst_tensor = _.FindDef(op_tensor); |
| 200 | if (!inst_tensor || !IsRankedTensor(_, inst_tensor->type_id())) { |
| 201 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 202 | << "Expected Tensor to be an OpTypeTensorARM whose Rank is " |
| 203 | "specified"; |
| 204 | } |
| 205 | |
| 206 | // Check Dimension operand |
| 207 | auto op_dim = inst->word(4); |
| 208 | auto inst_dim = _.FindDef(op_dim); |
| 209 | if (!spvOpcodeIsConstant(inst_dim->opcode()) || |
| 210 | !_.IsIntScalarType(inst_dim->type_id())) { |
| 211 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 212 | << "Dimension must come from a constant instruction of scalar " |
| 213 | "integer type."; |
| 214 | } |
| 215 | |
| 216 | auto inst_tensor_type = _.FindDef(inst_tensor->type_id()); |
| 217 | auto op_tensor_rank = inst_tensor_type->word(3); |
| 218 | uint64_t tensor_rank = 0; |
| 219 | uint64_t dim; |
| 220 | if (_.EvalConstantValUint64(op_tensor_rank, &tensor_rank) && |
| 221 | _.EvalConstantValUint64(op_dim, &dim) && (dim >= tensor_rank)) { |
| 222 | return _.diag(SPV_ERROR_INVALID_DATA, inst) |
| 223 | << "Dimension (" << dim << ") must be less than the Rank of Tensor (" |
| 224 | << tensor_rank << ")."; |
| 225 | } |
| 226 | |
| 227 | return SPV_SUCCESS; |
| 228 | } |
| 229 | |
| 230 | } // namespace |
| 231 |
no test coverage detected