예제 #1
0
파일: vm_test.py 프로젝트: yashsehgal/iree
 def test_dynamic_shape_compile(self):
   m = create_simple_dynamic_abs_module()
   logging.info("module: %s", m)
   instance = rt.VmInstance()
   logging.info("instance: %s", instance)
   context = rt.VmContext(instance, modules=[self.hal_module, m])
   logging.info("context: %s", context)
예제 #2
0
 def test_dynamic_shape_compile(self):
     m = create_simple_dynamic_abs_module()
     print(m)
     instance = rt.VmInstance()
     print(instance)
     context = rt.VmContext(instance, modules=[self.hal_module, m])
     print(context)
예제 #3
0
파일: vm_test.py 프로젝트: yashsehgal/iree
 def test_static_module_context(self):
   m = create_simple_static_mul_module()
   logging.info("module: %s", m)
   instance = rt.VmInstance()
   logging.info("instance: %s", instance)
   context = rt.VmContext(instance, modules=[self.hal_module, m])
   logging.info("context: %s", context)
예제 #4
0
 def test_static_module_context(self):
     m = create_simple_static_mul_module()
     print(m)
     instance = rt.VmInstance()
     print(instance)
     context = rt.VmContext(instance, modules=[self.hal_module, m])
     print(context)
예제 #5
0
 def test_synchronous_dynamic_shape_invoke_function(self):
     m = create_simple_dynamic_abs_module()
     instance = rt.VmInstance()
     context = rt.VmContext(instance, modules=[self.hal_module, m])
     f = m.lookup_function("simple_mul")
     abi = context.create_function_abi(self.device, self.htf, f)
     print("INVOKING:", abi)
     arg0 = np.array([[-1., 2.], [3., -4.]], dtype=np.float32)
     inputs = abi.raw_pack_inputs((arg0, ))
     print("INPUTS:", inputs)
     allocated_results = abi.allocate_results(inputs, static_alloc=False)
     print("ALLOCATED RESULTS:", allocated_results)
     print("--- INVOKE:")
     context.invoke(f, inputs, allocated_results)
     print("--- DONE.")
     results = abi.raw_unpack_results(allocated_results)
     print("RESULTS:", results)
     np.testing.assert_allclose(results[0], [[1., 2.], [3., 4.]])
예제 #6
0
 def test_add_scalar(self):
     m = create_add_scalar_module()
     instance = rt.VmInstance()
     context = rt.VmContext(instance, modules=[self.hal_module, m])
     f = m.lookup_function("add_scalar")
     abi = context.create_function_abi(self.device, self.htf, f)
     print("INVOKING:", abi)
     arg0 = np.array([1., 2., 3., 4.], dtype=np.float32)
     arg1 = np.array([4., 5., 6., 7.], dtype=np.float32)
     inputs = abi.raw_pack_inputs((5, 6))
     print("INPUTS:", inputs)
     allocated_results = abi.allocate_results(inputs, static_alloc=False)
     print("ALLOCATED RESULTS:", allocated_results)
     print("--- INVOKE:")
     context.invoke(f, inputs, allocated_results)
     print("--- DONE.")
     results = abi.raw_unpack_results(allocated_results)
     print("RESULTS:", results)
     self.assertEqual(results[0], 11)
예제 #7
0
    def test_add_scalar(self):
        m = create_add_scalar_module()
        instance = rt.VmInstance()
        context = rt.VmContext(instance, modules=[self.hal_module, m])
        f = m.lookup_function("add_scalar")
        abi = context.create_function_abi(self.device, self.htf, f)
        logging.info("abi: %s", abi)

        inputs = abi.raw_pack_inputs((5, 6))
        logging.info("inputs: %s", inputs)

        allocated_results = abi.allocate_results(inputs, static_alloc=False)
        logging.info("allocated_results: %s", allocated_results)
        logging.info("Invoking...")
        context.invoke(f, inputs, allocated_results)
        logging.info("...done")

        results = abi.raw_unpack_results(allocated_results)
        logging.info("results: %s", results)
        self.assertEqual(results[0], 11)
예제 #8
0
    def test_synchronous_dynamic_shape_invoke_function(self):
        m = create_simple_dynamic_abs_module()
        instance = rt.VmInstance()
        context = rt.VmContext(instance, modules=[self.hal_module, m])
        f = m.lookup_function("simple_mul")
        abi = context.create_function_abi(self.device, self.htf, f)
        logging.info("abi: %s", abi)

        arg0 = np.array([[-1., 2.], [3., -4.]], dtype=np.float32)
        inputs = abi.raw_pack_inputs((arg0, ))
        logging.info("inputs: %s", inputs)

        allocated_results = abi.allocate_results(inputs, static_alloc=False)
        logging.info("allocated_results: %s", allocated_results)
        logging.info("Invoking...")
        context.invoke(f, inputs, allocated_results)
        logging.info("...done")

        results = abi.raw_unpack_results(allocated_results)
        logging.info("results: %s", results)
        np.testing.assert_allclose(results[0], [[1., 2.], [3., 4.]])
예제 #9
0
파일: vm_test.py 프로젝트: yashsehgal/iree
  def test_synchronous_invoke_function(self):
    m = create_simple_static_mul_module()
    instance = rt.VmInstance()
    context = rt.VmContext(instance, modules=[self.hal_module, m])
    f = m.lookup_function("simple_mul")
    abi = context.create_function_abi(self.device, self.htf, f)
    logging.info("abi: %s", abi)

    arg0 = np.array([1., 2., 3., 4.], dtype=np.float32)
    arg1 = np.array([4., 5., 6., 7.], dtype=np.float32)
    inputs = abi.pack_inputs(arg0, arg1)
    logging.info("Serialized inputs: %s", abi.serialize_vm_list(inputs))
    logging.info("inputs: %s", inputs)

    allocated_results = abi.allocate_results(inputs, static_alloc=False)
    logging.info("allocated_results: %s", allocated_results)
    logging.info("Invoking...")
    context.invoke(f, inputs, allocated_results)
    logging.info("...done")

    result = abi.unpack_results(allocated_results)
    logging.info("result: %s", result)
    np.testing.assert_allclose(result, [4., 10., 18., 28.])
예제 #10
0
파일: vm_test.py 프로젝트: yashsehgal/iree
 def test_dynamic_module_context(self):
   instance = rt.VmInstance()
   context = rt.VmContext(instance)
   m = create_simple_static_mul_module()
   context.register_modules([self.hal_module, m])
예제 #11
0
파일: vm_test.py 프로젝트: yashsehgal/iree
 def test_context_id(self):
   instance = rt.VmInstance()
   context1 = rt.VmContext(instance)
   context2 = rt.VmContext(instance)
   self.assertGreater(context2.context_id, context1.context_id)