]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - tidl/tidl-api.git/blobdiff - examples/test/main.cpp
Remove input, output buffers from process kernel
[tidl/tidl-api.git] / examples / test / main.cpp
index 5805620a5f094dd65c4993b18f3009b37c09c5d4..4c82ca0ee7494c459206f4eefce5b93a21d625e4 100644 (file)
@@ -1,5 +1,5 @@
 /******************************************************************************
- * Copyright (c) 2017, Texas Instruments Incorporated - http://www.ti.com/
+ * Copyright (c) 2017-2018  Texas Instruments Incorporated - http://www.ti.com/
  *   All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
@@ -78,11 +78,9 @@ int main(int argc, char *argv[])
     signal(SIGTERM, exit);
 
     // If there are no devices capable of offloading TIDL on the SoC, exit
-    uint32_t num_dla =
-                Executor::GetNumDevicesSupportingTIDL(DeviceType::DLA);
-    uint32_t num_dsp =
-                Executor::GetNumDevicesSupportingTIDL(DeviceType::DSP);
-    if (num_dla == 0 && num_dsp == 0)
+    uint32_t num_eve = Executor::GetNumDevices(DeviceType::EVE);
+    uint32_t num_dsp = Executor::GetNumDevices(DeviceType::DSP);
+    if (num_eve == 0 && num_dsp == 0)
     {
         std::cout << "TI DL not supported on this SoC." << std::endl;
         return EXIT_SUCCESS;
@@ -92,7 +90,7 @@ int main(int argc, char *argv[])
     // Process arguments
     std::string config_file;
     int         num_devices = 1;
-    DeviceType  device_type = DeviceType::DLA;
+    DeviceType  device_type = DeviceType::EVE;
     ProcessArgs(argc, argv, config_file, num_devices, device_type);
 
     bool status = true;
@@ -100,17 +98,26 @@ int main(int argc, char *argv[])
         status = RunConfiguration(config_file, num_devices, device_type);
     else
     {
-        if (num_dla > 0)
+        if (num_eve > 0)
         {
-            //TODO: Use memory availability to determine # devices
             // Run on 2 devices because there is not enough CMEM available by
             // default
-            if (num_dla = 4) num_dla = 2;
-            status = RunAllConfigurations(num_dla, DeviceType::DLA);
+            if (num_eve = 4)
+            {
+                std::cout
+                 << "Running on 2 EVE devices instead of the available 4 "
+                 << "due to insufficient OpenCL global memory. Refer the "
+                 << "TIDL API User's Guide, Frequently Asked Questions, "
+                 << "Section \"Insufficient OpenCL global memory\" for details "
+                 << "on increasing the amount of CMEM available for OpenCL."
+                 << std::endl;
+                num_eve = 2;
+            }
+            status = RunAllConfigurations(num_eve, DeviceType::EVE);
             status &= RunMultipleExecutors(
                      "testvecs/config/infer/tidl_config_j11_v2.txt",
                      "testvecs/config/infer/tidl_config_j11_cifar.txt",
-                     num_dla);
+                     num_eve);
         }
 
         if (num_dsp > 0)
@@ -152,10 +159,6 @@ bool RunConfiguration(const std::string& config_file, int num_devices,
     assert (input_data_file.good());
     assert (output_data_file.good());
 
-    // Determine input frame size from configuration
-    size_t frame_sz = configuration.inWidth * configuration.inHeight *
-                      configuration.inNumChannels;
-
     try
     {
         // Create a executor with the approriate core type, number of cores
@@ -171,8 +174,10 @@ bool RunConfiguration(const std::string& config_file, int num_devices,
         std::vector<void *> buffers;
         for (auto &eo : execution_objects)
         {
-            ArgInfo in  = { ArgInfo(malloc_ddr<char>(frame_sz), frame_sz)};
-            ArgInfo out = { ArgInfo(malloc_ddr<char>(frame_sz), frame_sz)};
+            size_t in_size  = eo->GetInputBufferSizeInBytes();
+            size_t out_size = eo->GetOutputBufferSizeInBytes();
+            ArgInfo in  = { ArgInfo(malloc(in_size),  in_size)};
+            ArgInfo out = { ArgInfo(malloc(out_size), out_size)};
             eo->SetInputOutputBuffer(in, out);
 
             buffers.push_back(in.ptr());
@@ -210,6 +215,8 @@ bool RunConfiguration(const std::string& config_file, int num_devices,
                           << overhead << " %" << std::endl;
 
                 WriteFrame(*eo, output_data_file);
+                if (configuration.enableOutputTrace)
+                    eo->WriteLayerOutputsToFile();
             }
 
             // Read a frame and start processing it with current eo
@@ -221,7 +228,7 @@ bool RunConfiguration(const std::string& config_file, int num_devices,
         }
 
         for (auto b : buffers)
-            __free_ddr(b);
+            free(b);
 
     }
     catch (tidl::Exception &e)
@@ -247,7 +254,7 @@ bool RunAllConfigurations(int32_t num_devices, DeviceType device_type)
 {
     std::vector<std::string> configurations;
 
-    if (device_type == DeviceType::DLA)
+    if (device_type == DeviceType::EVE)
         configurations = {"dense_1x1",  "j11_bn", "j11_cifar",
                           "j11_controlLayers", "j11_prelu", "j11_v2",
                           "jseg21", "jseg21_tiscapes", "smallRoi", "squeeze1_1"};
@@ -263,7 +270,7 @@ bool RunAllConfigurations(int32_t num_devices, DeviceType device_type)
                                   + config + ".txt";
         std::cout << "Running " << config << " on " << num_devices
                   << " devices, type "
-                  << ((device_type == DeviceType::DLA) ? "EVE" : "DSP")
+                  << ((device_type == DeviceType::EVE) ? "EVE" : "DSP")
                   << std::endl;
 
         Configuration configuration;
@@ -371,7 +378,7 @@ void ProcessArgs(int argc, char *argv[], std::string& config_file,
                       break;
 
             case 't': if (*optarg == 'e')
-                          device_type = DeviceType::DLA;
+                          device_type = DeviceType::EVE;
                       else if (*optarg == 'd')
                           device_type = DeviceType::DSP;
                       else
@@ -402,13 +409,13 @@ void ProcessArgs(int argc, char *argv[], std::string& config_file,
 
 void DisplayHelp()
 {
-    std::cout << "Usage: test_tinn\n"
+    std::cout << "Usage: test_tidl\n"
                  "  Will run all available networks if invoked without"
                  " any arguments.\n  Use -c to run a single network.\n"
                  "Optional arguments:\n"
                  " -c                   Path to the configuration file\n"
                  " -n <number of cores> Number of cores to use (1 - 4)\n"
-                 " -t <d|e>             Type of core. d -> DSP, e -> DLA\n"
+                 " -t <d|e>             Type of core. d -> DSP, e -> EVE\n"
                  " -v                   Verbose output during execution\n"
                  " -h                   Help\n";
 }