iree/tools/iree-e2e-matmul-test.c
static iree_status_t replay_event_call(iree_trace_replay_t* replay,
                                       yaml_document_t* document,
                                       yaml_node_t* event_node) {
  yaml_node_t* function_node = NULL;
  IREE_RETURN_IF_ERROR(iree_yaml_mapping_find(
      document, event_node, iree_make_cstring_view("function"),
      &function_node));
  iree_string_view_t function_name = iree_yaml_node_as_string(function_node);
  fprintf(stderr, "--- CALL[%.*s] ---\n", (int)function_name.size,
          function_name.data);

  iree_hal_allocator_t* device_allocator =
      iree_hal_device_allocator(replay->device);

  iree_vm_function_t function;
  iree_vm_list_t* input_list = NULL;
  IREE_RETURN_IF_ERROR(iree_trace_replay_event_call_prepare(
      replay, document, event_node, &function, &input_list));

  // Perform a deep copy of the input list to pass to the test function.
  // Rationale: the test function may mutate some of the input list elements,
  // e.g. input-output parameters. For instance, the accumulator input of a
  // linalg.matmul. We need to preserve the original test inputs to run the
  // reference matmul on and to use in test failure logs.
  iree_vm_list_t* copy_of_input_list = NULL;
  IREE_CHECK_OK(copy_list_of_buffer_views(device_allocator, input_list,
                                          &copy_of_input_list));

  // Invoke the function to produce the actual result.
  iree_vm_list_t* output_list = NULL;
  IREE_CHECK_OK(iree_vm_list_create(/*element_type=*/NULL,
                                    /*initial_capacity=*/8,
                                    replay->host_allocator, &output_list));
  IREE_CHECK_OK(iree_vm_invoke(
      replay->context, function, IREE_VM_INVOCATION_FLAG_NONE, /*policy=*/NULL,
      copy_of_input_list, output_list, replay->host_allocator));

  // Get the actual_result buffer from the output_list.
  iree_hal_buffer_view_t* actual_result;
  IREE_RETURN_IF_ERROR(
      iree_get_buffer_view_list_item(output_list, 0, &actual_result));

  // Allocate an expected_result buffer, with same shape as actual_result.
  iree_hal_buffer_view_t* expected_result;
  IREE_RETURN_IF_ERROR(
      allocate_buffer_like(device_allocator, actual_result, &expected_result));

  // Use the reference matmul implementation to fill expected_result
  IREE_RETURN_IF_ERROR(reference_matmul(input_list, expected_result));

  // Check that actual_result and expected_result agree.
  IREE_CHECK_OK(iree_check_matmul(input_list, actual_result, expected_result));

  // Clean up.
  iree_vm_list_release(input_list);
  iree_vm_list_release(copy_of_input_list);
  iree_vm_list_release(output_list);  // releases actual_result
  iree_hal_buffer_view_release(expected_result);

  return iree_ok_status();
}
// Special handler for function calls in a e2e matmul test trace.
// Assumes that all calls are to functions that take 3 inputs (lhs, rhs, acc)
// and return the result of a matmul (lhs*rhs+acc).
Special handler for function calls in a e2e matmul test trace.
Assumes that all calls are to functions that take 3 inputs (lhs, rhs, acc)
and return the result of a matmul (lhs*rhs+acc).
Special handler for function calls in a e2e matmul test trace . Assumes that all calls are to functions that take 3 inputs ( lhs rhs acc ) and return the result of a matmul ( lhs * rhs + acc ) .
static iree_status_t replay_event_call(iree_trace_replay_t* replay,
                                       yaml_document_t* document,
                                       yaml_node_t* event_node) {
  yaml_node_t* function_node = NULL;
  IREE_RETURN_IF_ERROR(iree_yaml_mapping_find(
      document, event_node, iree_make_cstring_view("function"),
      &function_node));
  iree_string_view_t function_name = iree_yaml_node_as_string(function_node);
  fprintf(stderr, "--- CALL[%.*s] ---\n", (int)function_name.size,
          function_name.data);
  iree_hal_allocator_t* device_allocator =
      iree_hal_device_allocator(replay->device);
  iree_vm_function_t function;
  iree_vm_list_t* input_list = NULL;
  IREE_RETURN_IF_ERROR(iree_trace_replay_event_call_prepare(
      replay, document, event_node, &function, &input_list));
  iree_vm_list_t* copy_of_input_list = NULL;
  IREE_CHECK_OK(copy_list_of_buffer_views(device_allocator, input_list,
                                          &copy_of_input_list));
  iree_vm_list_t* output_list = NULL;
  IREE_CHECK_OK(iree_vm_list_create(NULL,
                                    8,
                                    replay->host_allocator, &output_list));
  IREE_CHECK_OK(iree_vm_invoke(
      replay->context, function, IREE_VM_INVOCATION_FLAG_NONE, NULL,
      copy_of_input_list, output_list, replay->host_allocator));
  iree_hal_buffer_view_t* actual_result;
  IREE_RETURN_IF_ERROR(
      iree_get_buffer_view_list_item(output_list, 0, &actual_result));
  iree_hal_buffer_view_t* expected_result;
  IREE_RETURN_IF_ERROR(
      allocate_buffer_like(device_allocator, actual_result, &expected_result));
  IREE_RETURN_IF_ERROR(reference_matmul(input_list, expected_result));
  IREE_CHECK_OK(iree_check_matmul(input_list, actual_result, expected_result));
  iree_vm_list_release(input_list);
  iree_vm_list_release(copy_of_input_list);
  iree_vm_list_release(output_list);  
  iree_hal_buffer_view_release(expected_result);
  return iree_ok_status();
}
static iree_status_t replay_event_call ( iree_trace_replay_t * replay , yaml_document_t * document , yaml_node_t * event_node ) { yaml_node_t * function_node = NULL ; IREE_RETURN_IF_ERROR ( iree_yaml_mapping_find ( document , event_node , iree_make_cstring_view ( " " ) , & function_node ) ) ; iree_string_view_t function_name = iree_yaml_node_as_string ( function_node ) ; fprintf ( stderr , " \n " , ( int ) function_name . size , function_name . data ) ; iree_hal_allocator_t * device_allocator = iree_hal_device_allocator ( replay -> device ) ; iree_vm_function_t function ; iree_vm_list_t * input_list = NULL ; IREE_RETURN_IF_ERROR ( iree_trace_replay_event_call_prepare ( replay , document , event_node , & function , & input_list ) ) ; iree_vm_list_t * copy_of_input_list = NULL ; IREE_CHECK_OK ( copy_list_of_buffer_views ( device_allocator , input_list , & copy_of_input_list ) ) ; iree_vm_list_t * output_list = NULL ; IREE_CHECK_OK ( iree_vm_list_create ( NULL , 8 , replay -> host_allocator , & output_list ) ) ; IREE_CHECK_OK ( iree_vm_invoke ( replay -> context , function , IREE_VM_INVOCATION_FLAG_NONE , NULL , copy_of_input_list , output_list , replay -> host_allocator ) ) ; iree_hal_buffer_view_t * actual_result ; IREE_RETURN_IF_ERROR ( iree_get_buffer_view_list_item ( output_list , 0 , & actual_result ) ) ; iree_hal_buffer_view_t * expected_result ; IREE_RETURN_IF_ERROR ( allocate_buffer_like ( device_allocator , actual_result , & expected_result ) ) ; IREE_RETURN_IF_ERROR ( reference_matmul ( input_list , expected_result ) ) ; IREE_CHECK_OK ( iree_check_matmul ( input_list , actual_result , expected_result ) ) ; iree_vm_list_release ( input_list ) ; iree_vm_list_release ( copy_of_input_list ) ; iree_vm_list_release ( output_list ) ; iree_hal_buffer_view_release ( expected_result ) ; return iree_ok_status ( ) ; }
Special handler for function calls in a e2e matmul test trace.
Special handler for function calls in a e2e matmul test trace .
// Perform a deep copy of the input list to pass to the test function. // Rationale: the test function may mutate some of the input list elements, // e.g. input-output parameters. For instance, the accumulator input of a // linalg.matmul. We need to preserve the original test inputs to run the // reference matmul on and to use in test failure logs. // Invoke the function to produce the actual result. /*element_type=*/ /*initial_capacity=*/ /*policy=*/ // Get the actual_result buffer from the output_list. // Allocate an expected_result buffer, with same shape as actual_result. // Use the reference matmul implementation to fill expected_result // Check that actual_result and expected_result agree. // Clean up. // releases actual_result