You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/08/11 22:36:10 UTC

[GitHub] [tvm] mkatanbaf opened a new pull request, #12390: [MicroTVM] add heap-size to project options

mkatanbaf opened a new pull request, #12390:
URL: https://github.com/apache/tvm/pull/12390

   This PR adds heap-size to the microTVM project options. So far the heap size has been fixed (216KB) for all boards. Exposing it as a project option allows the user to modify the value based on the specific board's available memory.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] alanmacd commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
alanmacd commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r951750728


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -370,6 +397,12 @@ def _get_nrf_device_args(options):
         type="bool",
         help="Run on the FVP emulator instead of hardware.",
     ),
+    server.ProjectOption(
+        "heap_size",
+        optional=["generate_project"],
+        type="int",
+        help="Sets HEAP_SIZE for Zephyr board.",

Review Comment:
   Or maybe something more direct like "Sets the value for HEAP_SIZE passed to K_HEAP_DEFINE()" since K_HEAP_DEFINE is a zephyr macro.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] alanmacd commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
alanmacd commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r951750728


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -370,6 +397,12 @@ def _get_nrf_device_args(options):
         type="bool",
         help="Run on the FVP emulator instead of hardware.",
     ),
+    server.ProjectOption(
+        "heap_size",
+        optional=["generate_project"],
+        type="int",
+        help="Sets HEAP_SIZE for Zephyr board.",

Review Comment:
   Or maybe something more direct like "Sets the value for HEAP_SIZE passed to K_HEAP_DEFINE() to service TVM memory allocation requests" since K_HEAP_DEFINE is a zephyr macro.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] areusch commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
areusch commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r951717731


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -370,6 +397,12 @@ def _get_nrf_device_args(options):
         type="bool",
         help="Run on the FVP emulator instead of hardware.",
     ),
+    server.ProjectOption(
+        "heap_size",

Review Comment:
   nit: heap_size_bytes



##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -370,6 +397,12 @@ def _get_nrf_device_args(options):
         type="bool",
         help="Run on the FVP emulator instead of hardware.",
     ),
+    server.ProjectOption(
+        "heap_size",
+        optional=["generate_project"],
+        type="int",
+        help="Sets HEAP_SIZE for Zephyr board.",

Review Comment:
   since HEAP_SIZE isn't a Zephyr option, can you instead say something more like "Sets the size of the heap used to service TVM memory allocation requests"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12390:
URL: https://github.com/apache/tvm/pull/12390#issuecomment-1223453759

   @tvm-bot rerun


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] areusch commented on pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
areusch commented on PR #12390:
URL: https://github.com/apache/tvm/pull/12390#issuecomment-1224790066

   thanks @mkatanbaf !


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r948330866


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -195,6 +195,30 @@ def _get_device_args(options):
     )
 
 
+def _get_board_mem_size(options):
+    board_file_path = (
+        pathlib.Path(get_zephyr_base(options))
+        / "boards"
+        / "arm"
+        / options["zephyr_board"]
+        / (options["zephyr_board"] + ".yaml")
+    )
+    try:
+        with open(board_file_path) as f:
+            board_data = yaml.load(f, Loader=yaml.FullLoader)
+            return int(board_data["ram"]) * 1024
+    except:
+        _LOG.warning("Board memory information is not available.")
+    return None
+
+
+def _get_recommended_heap_size(options):
+    prop = BOARD_PROPERTIES[options["zephyr_board"]]
+    if "recommended_heap_size" in prop:
+        return prop["recommended_heap_size"]
+    return 216 * 1024

Review Comment:
   done



##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -589,6 +619,14 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec
 
                     cmake_f.write(line)
 
+                heap_size = _get_recommended_heap_size(options)
+                if options.get("heap_size"):
+                    board_mem_size = _get_board_mem_size(options)
+                    if board_mem_size is not None:
+                        assert options["heap_size"] < board_mem_size, "heap size is too large"

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mehrdadh commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r948262122


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -589,6 +619,14 @@ def generate_project(self, model_library_format_path, standalone_crt_dir, projec
 
                     cmake_f.write(line)
 
+                heap_size = _get_recommended_heap_size(options)
+                if options.get("heap_size"):
+                    board_mem_size = _get_board_mem_size(options)
+                    if board_mem_size is not None:
+                        assert options["heap_size"] < board_mem_size, "heap size is too large"

Review Comment:
   make error message more clear? `Heap size (options["heap_size"]) is larger than memory size (board_mem_size) on this board.`



##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -195,6 +195,30 @@ def _get_device_args(options):
     )
 
 
+def _get_board_mem_size(options):
+    board_file_path = (
+        pathlib.Path(get_zephyr_base(options))
+        / "boards"
+        / "arm"
+        / options["zephyr_board"]
+        / (options["zephyr_board"] + ".yaml")
+    )
+    try:
+        with open(board_file_path) as f:
+            board_data = yaml.load(f, Loader=yaml.FullLoader)
+            return int(board_data["ram"]) * 1024
+    except:
+        _LOG.warning("Board memory information is not available.")
+    return None
+
+
+def _get_recommended_heap_size(options):
+    prop = BOARD_PROPERTIES[options["zephyr_board"]]
+    if "recommended_heap_size" in prop:
+        return prop["recommended_heap_size"]
+    return 216 * 1024

Review Comment:
   change this value to a global constant with capital letters for better readability.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12390:
URL: https://github.com/apache/tvm/pull/12390#issuecomment-1217204442

   @tvm-bot rerun


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r951814458


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -370,6 +397,12 @@ def _get_nrf_device_args(options):
         type="bool",
         help="Run on the FVP emulator instead of hardware.",
     ),
+    server.ProjectOption(
+        "heap_size",

Review Comment:
   added the _BYTES suffix to all three.



##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -370,6 +397,12 @@ def _get_nrf_device_args(options):
         type="bool",
         help="Run on the FVP emulator instead of hardware.",
     ),
+    server.ProjectOption(
+        "heap_size",
+        optional=["generate_project"],
+        type="int",
+        help="Sets HEAP_SIZE for Zephyr board.",

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12390:
URL: https://github.com/apache/tvm/pull/12390#issuecomment-1219160129

   @tvm-bot rerun


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] PhilippvK commented on pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
PhilippvK commented on PR #12390:
URL: https://github.com/apache/tvm/pull/12390#issuecomment-1221571238

   @mkatanbaf I really like this feature. (Have implemented this for me as well a few days ago to support a STM32F4 board with limited RAM).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r952067644


##########
apps/microtvm/zephyr/template_project/boards.json:
##########
@@ -54,7 +54,8 @@
         "is_qemu": false,
         "fpu": true,
         "vid_hex": "0483",
-        "pid_hex": "374b"
+        "pid_hex": "374b",
+        "recommended_heap_size": 512000

Review Comment:
   done



##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -195,6 +195,33 @@ def _get_device_args(options):
     )
 
 
+def _get_board_mem_size(options):
+    board_file_path = (
+        pathlib.Path(get_zephyr_base(options))
+        / "boards"
+        / "arm"
+        / options["zephyr_board"]
+        / (options["zephyr_board"] + ".yaml")
+    )
+    try:
+        with open(board_file_path) as f:
+            board_data = yaml.load(f, Loader=yaml.FullLoader)
+            return int(board_data["ram"]) * 1024
+    except:
+        _LOG.warning("Board memory information is not available.")
+    return None
+
+
+DEFAULT_HEAP_SIZE_BYTES = 216 * 1024
+
+
+def _get_recommended_heap_size(options):

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] areusch merged pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
areusch merged PR #12390:
URL: https://github.com/apache/tvm/pull/12390


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] areusch commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
areusch commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r951887026


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -195,6 +195,33 @@ def _get_device_args(options):
     )
 
 
+def _get_board_mem_size(options):
+    board_file_path = (
+        pathlib.Path(get_zephyr_base(options))
+        / "boards"
+        / "arm"
+        / options["zephyr_board"]
+        / (options["zephyr_board"] + ".yaml")
+    )
+    try:
+        with open(board_file_path) as f:
+            board_data = yaml.load(f, Loader=yaml.FullLoader)
+            return int(board_data["ram"]) * 1024
+    except:
+        _LOG.warning("Board memory information is not available.")
+    return None
+
+
+DEFAULT_HEAP_SIZE_BYTES = 216 * 1024
+
+
+def _get_recommended_heap_size(options):

Review Comment:
   and here



##########
apps/microtvm/zephyr/template_project/boards.json:
##########
@@ -54,7 +54,8 @@
         "is_qemu": false,
         "fpu": true,
         "vid_hex": "0483",
-        "pid_hex": "374b"
+        "pid_hex": "374b",
+        "recommended_heap_size": 512000

Review Comment:
   i think this one also needs it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] alanmacd commented on a diff in pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
alanmacd commented on code in PR #12390:
URL: https://github.com/apache/tvm/pull/12390#discussion_r951752966


##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -370,6 +397,12 @@ def _get_nrf_device_args(options):
         type="bool",
         help="Run on the FVP emulator instead of hardware.",
     ),
+    server.ProjectOption(
+        "heap_size",

Review Comment:
   should HEAP_SIZE and DEFAULT_HEAP_SIZE also have _BYTES suffix?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [tvm] mkatanbaf commented on pull request #12390: [MicroTVM] add heap-size to project options

Posted by GitBox <gi...@apache.org>.
mkatanbaf commented on PR #12390:
URL: https://github.com/apache/tvm/pull/12390#issuecomment-1218517216

   @tvm-bot rerun


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org