| 691 | }; |
| 692 | |
| 693 | int32_t main(int32_t argc, char** argv) |
| 694 | { |
| 695 | samplesCommon::Args args; |
| 696 | bool argsOK = samplesCommon::parseArgs(args, argc, argv); |
| 697 | if (!argsOK) |
| 698 | { |
| 699 | sample::gLogError << "Invalid arguments" << std::endl; |
| 700 | printHelpInfo(); |
| 701 | return EXIT_FAILURE; |
| 702 | } |
| 703 | if (args.help) |
| 704 | { |
| 705 | printHelpInfo(); |
| 706 | return EXIT_SUCCESS; |
| 707 | } |
| 708 | |
| 709 | auto sampleTest = sample::gLogger.defineTest(gSampleName, argc, argv); |
| 710 | |
| 711 | sample::gLogger.reportTestStart(sampleTest); |
| 712 | |
| 713 | samplesCommon::OnnxSampleParams params = initializeSampleParams(args); |
| 714 | |
| 715 | std::vector<IOSpec> vecFP16TensorFmt = { |
| 716 | IOSpec{TensorFormat::kLINEAR, "kLINEAR"}, |
| 717 | IOSpec{TensorFormat::kCHW2, "kCHW2"}, |
| 718 | IOSpec{TensorFormat::kHWC8, "kHWC8"}, |
| 719 | }; |
| 720 | std::vector<IOSpec> vecINT8TensorFmt = { |
| 721 | IOSpec{TensorFormat::kLINEAR, "kLINEAR"}, |
| 722 | IOSpec{TensorFormat::kCHW4, "kCHW4"}, |
| 723 | IOSpec{TensorFormat::kCHW32, "kCHW32"}, |
| 724 | }; |
| 725 | |
| 726 | SampleBuffer goldenInput, goldenOutput; |
| 727 | |
| 728 | SampleIOFormats sample(params); |
| 729 | |
| 730 | srand(unsigned(time(nullptr))); |
| 731 | sample.mDigit = rand() % 10; |
| 732 | |
| 733 | sample::gLogInfo << "The test chooses MNIST as the network and recognizes a randomly generated digit" << std::endl; |
| 734 | sample::gLogInfo |
| 735 | << "Firstly it runs the FP32 as the golden data, then INT8/FP16 with different formats will be tested" |
| 736 | << std::endl |
| 737 | << std::endl; |
| 738 | |
| 739 | if (!runFP32Reference(sample, sampleTest, goldenInput, goldenOutput)) |
| 740 | { |
| 741 | return sample::gLogger.reportFail(sampleTest); |
| 742 | } |
| 743 | |
| 744 | // Test FP16 formats |
| 745 | for (auto spec : vecFP16TensorFmt) |
| 746 | { |
| 747 | sample::gLogInfo << "Testing datatype FP16 with format " << spec.formatName << std::endl; |
| 748 | sample.mTensorFormat = spec.format; |
| 749 | SampleBuffer inputBuf, outputBuf; |
| 750 |
nothing calls this directly
no test coverage detected