1616# under the License.
1717
1818import os
19- import pathlib
2019import sys
2120import pytest
2221import numpy as np
23- import logging
2422
2523import tvm .testing
2624from tvm import te
2725from tvm import relay
2826from tvm .relay .backend import Executor , Runtime
29- from tvm .contrib import utils , ndk
30- from tvm .contrib .hexagon .build import HexagonLauncher
3127import tvm .contrib .hexagon as hexagon
3228
3329from .conftest import requires_hexagon_toolchain
3430
31+ aot_target_kind = tvm .testing .parameter (
32+ "c" ,
33+ "llvm -keys=hexagon -link-params=0 -mattr=+hvxv68,+hvx-length128b,+hvx-qfloat,-hvx-ieee-fp -mcpu=hexagonv68 -mtriple=hexagon" ,
34+ )
35+
3536
3637@requires_hexagon_toolchain
3738def test_add (hexagon_session ):
@@ -270,8 +271,18 @@ def _workaround_create_aot_shared():
270271 )
271272
272273
274+ def get_target_and_session (target_kind : str ):
275+ if target_kind == "c" :
276+ target_hexagon = tvm .target .hexagon ("v68" )
277+ session_key = "hexagon-rpc"
278+ elif target_kind .startswith ("llvm" ):
279+ target_hexagon = target_kind
280+ session_key = "cpu-rpc"
281+ return target_hexagon , session_key
282+
283+
273284@requires_hexagon_toolchain
274- def test_aot_executor (hexagon_session ):
285+ def test_aot_executor (hexagon_launcher , aot_target_kind ):
275286 dtype = "float32"
276287 input_shape = (1 , 128 , 128 , 3 )
277288 w_shape = (5 , 5 , 3 , 8 )
@@ -290,7 +301,7 @@ def test_aot_executor(hexagon_session):
290301 relay_mod = tvm .IRModule .from_expr (f )
291302 relay_mod = relay .transform .InferType ()(relay_mod )
292303
293- target_hexagon = tvm . target . hexagon ( "v68" )
304+ target_hexagon , session_key = get_target_and_session ( aot_target_kind )
294305
295306 weight_data = np .random .rand (w_shape [0 ], w_shape [1 ], w_shape [2 ], w_shape [3 ]).astype (dtype = dtype )
296307 input_data = np .random .rand (
@@ -304,11 +315,13 @@ def test_aot_executor(hexagon_session):
304315 lowered = tvm .relay .build (
305316 relay_mod ,
306317 params = params ,
307- target = tvm .target .Target (target_hexagon , host = "c" ),
318+ target = tvm .target .Target (target_hexagon , host = aot_target_kind ),
308319 runtime = Runtime ("cpp" ),
309320 executor = Executor ("aot" , {"unpacked-api" : False , "interface-api" : "packed" }),
310321 )
311322
323+ hexagon_session = hexagon_launcher .start_session (name = session_key )
324+ hexagon_session .__enter__ ()
312325 aot_mod = hexagon_session .get_executor_from_factory (lowered )
313326 aot_mod .set_input (** inputs )
314327 aot_mod .run ()
@@ -332,7 +345,7 @@ def test_aot_executor(hexagon_session):
332345
333346
334347@requires_hexagon_toolchain
335- def test_aot_executor_multiple_conv2d (hexagon_session ):
348+ def test_aot_executor_multiple_conv2d (hexagon_launcher , aot_target_kind ):
336349 dtype = "float32"
337350 input_shape = (1 , 8 , 8 , 3 )
338351 w1_shape = (5 , 5 , 3 , 1 )
@@ -362,7 +375,7 @@ def test_aot_executor_multiple_conv2d(hexagon_session):
362375 relay_mod = tvm .IRModule .from_expr (f )
363376 relay_mod = relay .transform .InferType ()(relay_mod )
364377
365- target_hexagon = tvm . target . hexagon ( "v68" )
378+ target_hexagon , session_key = get_target_and_session ( aot_target_kind )
366379
367380 weight1_data = np .random .rand (w1_shape [0 ], w1_shape [1 ], w1_shape [2 ], w1_shape [3 ]).astype (
368381 dtype = dtype
@@ -381,11 +394,13 @@ def test_aot_executor_multiple_conv2d(hexagon_session):
381394 lowered = tvm .relay .build (
382395 relay_mod ,
383396 params = params ,
384- target = tvm .target .Target (target_hexagon , host = "c" ),
397+ target = tvm .target .Target (target_hexagon , host = aot_target_kind ),
385398 runtime = Runtime ("cpp" ),
386399 executor = Executor ("aot" , {"unpacked-api" : False , "interface-api" : "packed" }),
387400 )
388401
402+ hexagon_session = hexagon_launcher .start_session (name = session_key )
403+ hexagon_session .__enter__ ()
389404 aot_mod = hexagon_session .get_executor_from_factory (lowered )
390405 aot_mod .set_input (** inputs )
391406 aot_mod .run ()
0 commit comments