| 342 | } |
| 343 | } |
| 344 | void Tensor::print() const { |
| 345 | // print dimensions |
| 346 | MNN_PRINT("====== Tensor %p ======", this); |
| 347 | MNN_PRINT("\nDimension: "); |
| 348 | for (int i = 0; i < mBuffer.dimensions; i++) { |
| 349 | MNN_PRINT("%d, ", mBuffer.dim[i].extent); |
| 350 | } |
| 351 | |
| 352 | // convert to host if needed |
| 353 | auto printee = this; |
| 354 | auto bnType = MNN_FORWARD_CPU; |
| 355 | if (nullptr != mDescribe->getBackend()) { |
| 356 | bnType = mDescribe->getBackend()->type(); |
| 357 | } |
| 358 | bool device = bnType != MNN_FORWARD_CPU; |
| 359 | if (device) { |
| 360 | printee = this->createHostTensorFromDevice(this, true); |
| 361 | } |
| 362 | auto buffer = printee->buffer().host; |
| 363 | |
| 364 | MNN_PRINT("\nData: "); |
| 365 | if (printee->getType().code == halide_type_int) { |
| 366 | if (printee->getType().bits == 8) { // int8 |
| 367 | printData<int8_t>(printee, buffer, "%d, "); |
| 368 | } else if (printee->getType().bits == 16) { // int16 |
| 369 | printData<int16_t>(printee, buffer, "%d, "); |
| 370 | } else if (printee->getType().bits == 32) { // int32 |
| 371 | printData<int32_t>(printee, buffer, "%d, "); |
| 372 | } else { |
| 373 | MNN_PRINT("\nunsupported data type"); |
| 374 | } |
| 375 | } else if (printee->getType().code == halide_type_uint) { |
| 376 | if (printee->getType().bits == 8) { // uint8 |
| 377 | printData<uint8_t>(printee, buffer, "%d, "); |
| 378 | } else { |
| 379 | MNN_PRINT("\nunsupported data type"); |
| 380 | } |
| 381 | } else if (printee->getType().code == halide_type_float) { |
| 382 | if (printee->getType().bits == 32) { // float32 |
| 383 | printData<float>(printee, buffer, "%f, "); |
| 384 | } else { |
| 385 | MNN_PRINT("\nunsupported data type\n"); |
| 386 | } |
| 387 | } else { |
| 388 | MNN_PRINT("\nunsupported data type"); |
| 389 | } |
| 390 | |
| 391 | // clean up |
| 392 | if (printee != this) { |
| 393 | delete printee; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | void Tensor::printShape() const { |
| 398 | const int dims = this->dimensions(); |