This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28388D: Deploy neural network model ( from my own ONNX file export by Pytorch) using edgeAI studio for C2000

Part Number: TMS320F28388D
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Hi,

My project needs to deploy a AI model on C2000 device, I trained and generated model using Pytorch  and exported to ONNX file. But I don't know how to upload this custom ONNX file into edge AI studio to generate C code (artifacts) to deploy on C2000 devices like some example motor arc fault.......

Can you guide me?

Thanks.

longpt10

  • Hey Long,

    From your statements, I am assuming you are using your own Pytorch training environment (and not TI's modelmaker or Edge AI Studio).

    You do not need to upload the onnx to the Edge AI Studio, there are 2 other ways.

    Option 1: (quick, recommended) If you know what compiler options you need to give to compile the model to a binary, you can directly use the Neural Network Compiler  (refer docs). There are examples here of compiler options as well that you can use with your C2000Ware. 

    Option 2: (long way) If you don't know what compiler options you need to provide, you will have to install TI's Tiny ML Tensorlab and then go through the instructions in Step 2 of Tiny ML Modelmaker to set up repositories, and finally use this to compile your model.

    Both the above options create a mod.a which can be used into the CCS project for further application development.

    Thanks,

    Adithya

  • Hi Adithya,

    Thanks for your support,

    Yes, I am using my own Pytorch trainning environment,

    I follow the step in the guideline of option 1. But when build the model I get some error:

    $ tvmc compile --target="c, ti-npu type=soft" --target-c-mcpu=c28 ./sine_model.onnx -o artifacts_c28/mod.a --cross-compiler="cl2000" --cross-compiler-options="$CL2000_OPTIONS"
    Traceback (most recent call last):
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\_ffi\registry.py", line 29, in <module>
    from ._cy3.core import _register_object, _get_object_type_index
    ImportError: DLL load failed while importing core: The specified procedure could not be found.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\Scripts\tvmc.exe\__main__.py", line 4, in <module>
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\__init__.py", line 26, in <module>
    from ._ffi.base import TVMError, __version__, _RUNTIME_ONLY
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\_ffi\__init__.py", line 29, in <module>
    from .registry import register_object, register_func, register_extension
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\_ffi\registry.py", line 36, in <module>
    from ._ctypes.object import _register_object, _get_object_type_index
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\_ffi\_ctypes\object.py", line 21, in <module>
    from .types import ArgTypeCode, RETURN_SWITCH, C_TO_PY_ARG_SWITCH, _wrap_arg_func
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\_ffi\_ctypes\types.py", line 22, in <module>
    from ..runtime_ctypes import TVMByteArray, ArgTypeCode, Device
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\_ffi\runtime_ctypes.py", line 64, in <module>
    class DataType(ctypes.Structure):
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\_ffi\runtime_ctypes.py", line 88, in DataType
    np.dtype(np.float_): "float64",
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\__init__.py", line 413, in __getattr__
    raise AttributeError(
    AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead.. Did you mean: 'float16'?

    I install python 3.10, pytorch 2.6.0.

    I don't know what is doing next, can you help me fix this problem?

    Brs

    Thanks

  • Can you uninstall your current numpy (pip uninstall numpy) and do a pip install numpy==1.26.3 and let me know if it works?

  • thanks,

    I installed numpy 1.26.3, but after compile It still show:

    Package "onnx" is not installed. Hint: "pip install tlcpack[tvmc]".

    Can I intall which version of onnx?

  • onnx 1.16.1
    onnxoptimizer 0.3.13
    onnxruntime 1.19.0
    onnxsim 0.4.36

  • Can you guide me exactly command to install?

    pip install onnx==1.16.1 or pip install torch onnx==1.16.1?

  • pip install onnx==1.16.1 onnxoptimizer==0.3.13 onnxruntime==1.19.0 onnxsim==0.4.36

  • thanks, There is no error when I run the command: tvmc compile --target="c, ti-npu type=soft" --target-c-mcpu=c28 ./sine_model.onnx -o artifacts_c28/mod.a --cross-compiler="cl2000" --cross-compiler-options="$CL2000_OPTIONS"

    But I don't see any file generated (mod.a, tvmgen_default.h.....), where to find them? 

  • I am assuming you have given your <model_path> instead of ./sine_model.onnx and <output_directory> instead of artifacts_c28/mod.a the command. mod.a and tvmgen_default.h should be present in the output_dir that you have given. If you dont find them there, please do let nme know more details of what you find on your output screen

  • I don't see any file which is generated in folder Python in desktop,

  • Please remove the <> in the DEVICE_NAME variable, for you it should be just f2838x.

    Also, Do you have a ./sine_model.onnx, if not please provide the onnx path of your model. I am assuming you have cl2000 compiler installed.

  • Yes, I have the sine_model.onnx file in forder Python in my desktop of my PC, I also have cl2000 compiler through CCS12.7 

      

    my folder Python in desktop

    Nothing generated in artifacts_c28

  • Can you try

    $env:TINIE_COMPILE_DEBUG=1

    $env:TINPU_COMPILE_DEBUG=1

    and then rerun the command. This will not solve your problem, but it will give debug statements

  • I tried but nothing showed  here

  • I uninstall all the enviroment and package, Reinstall all again , then run the command 

    tvmc compile --target="c, ti-npu type=soft" .\sine_model.onnx --target-c-mcpu=c28 -o artifacts_c28/mod.a --cross-compiler="cl2000" --cross-compiler-options="--float_support=$env:C2000_DEVICE_FPU --abi=eabi -O3 --opt_for_speed=5 --c99 -v28 -ml -mt --gen_func_subsections -I$env:C2000_CGT_PATH\include -I$env:C2000WARE_PATH\driverlib\$env:C2000_DEVICE\driverlib -I$env:C2000WARE_PATH\device_support\$env:C2000_DEVICE\common\include -I."

    now I can generate some file .h and .c but still not have the mod.a file and there are warning and error below:

    WARNING:autotvm:One or more operators have not been tuned. Please tune your model for better performance. Use DEBUG logging level to see more details.
    Traceback (most recent call last):
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\Scripts\tvmc.exe\__main__.py", line 7, in <module>
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\driver\tvmc\main.py", line 131, in main
    sys.exit(_main(sys.argv[1:]))
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\driver\tvmc\main.py", line 119, in _main
    return args.func(args)
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\driver\tvmc\compiler.py", line 216, in drive_compile
    compile_model(
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\driver\tvmc\compiler.py", line 533, in compile_model
    package_path = tvmc_model.export_package(
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\driver\tvmc\model.py", line 352, in export_package
    package_path = self.export_classic_format(
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\driver\tvmc\model.py", line 287, in export_classic_format
    executor_factory.get_lib().export_library(
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\runtime\module.py", line 636, in export_library
    return fcompile(file_name, files, **kwargs)
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\contrib\cc.py", line 411, in _fcompile
    compile_func(outputs, objects + add_files, options=all_options, **kwargs)
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\contrib\cc.py", line 142, in create_static
    _windows_compile(obj_f, [src_f], options, compile_cmd=cc)
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\contrib\cc.py", line 474, in _windows_compile
    _linux_compile(output, objects, options, compile_cmd, cwd, ccache_env)
    File "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\contrib\cc.py", line 468, in _linux_compile
    raise RuntimeError(msg)
    RuntimeError: Compilation error:
    >> WARNING: object file specified, but linking not enabled
    [tinie_soft.cc]
    "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\Lib\site-packages\tvm\3rdparty\tinie-api/soft/src/tinie_soft.cc", line 68: fatal error: cannot open source file "soft/inc/tinie_soft.h"
    1 catastrophic error detected in the compilation of "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\Lib\site-packages\tvm\3rdparty\tinie-api/soft/src/tinie_soft.cc".
    Compilation terminated.

    >> Compilation failure

    Command line: cl2000 -c -o tinie_soft.obj C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\3rdparty\tinie-api/soft/src/tinie_soft.cc --float_support=fpu64 --abi=eabi -O3 --opt_for_speed=5 --c99 -v28 -ml -mt --gen_func_subsections -IC:\ti\ccs1270\ccs\tools\compiler\ti-cgt-c2000_22.6.1.LTS\include -IC:\ti\c2000\C2000Ware_MotorControl_SDK_5_03_00_00\c2000ware\driverlib\f2838x\driverlib -IC:\ti\c2000\C2000Ware_MotorControl_SDK_5_03_00_00\c2000ware\device_support\f2838x\common\include -I. -IC:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\3rdparty\tinie-api -IC:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\lib\site-packages\tvm\standalone_crt\include

  • For once could you try with C2000Ware 5.04 instead of motor control sdk 5.03? Remember to set the C2000ware_path environment variable again

  • i tried the C2000Ware 5.04 but it is still the same error above

  • the main problem here:

    >> WARNING: object file specified, but linking not enabled
    [tinie_soft.cc]
    "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\Lib\site-packages\tvm\3rdparty\tinie-api/soft/src/tinie_soft.cc", line 68: fatal error: cannot open source file "soft/inc/tinie_soft.h"
    1 catastrophic error detected in the compilation of "C:\Users\Phong Doi khong\AppData\Local\Programs\Python\Python310\Lib\site-packages\tvm\3rdparty\tinie-api/soft/src/tinie_soft.cc".
    Compilation terminated.

    >> Compilation failure

    --> Can you suggest a solution for that?

  • Long, there is a current limitation which struggles when there is a space in any of the paths. I see that since your username has a space, the error occurs.

    One simple suggestion is to have a python environment (venv/pyenv) created in "C:\ti" where you reinstall the neural network compiler, onnx etc

    This should mostly solve your problem

  • thanks, That make it works

  • thanks, That make it works

  • thanks, That make it works

  • thanks, That make it works

  • thanks, That make it works