cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
stzog
Explorer
Explorer
508 Views
Registered: ‎02-07-2020

Software emulation of compute unit(s) exited unexpectedly

Hi to all!

Based on hello world example i created a sobel edge detection  project with 3 kernels that i call in host.

The build is ok but in sw emulation run i get the following.

INFO: [SW-EM 09-0] Unable to find emconfig.json. Using default device.
Found Platform
Platform Name: Xilinx
INFO: Reading ./binary_container_1.xclbin
Loading: './binary_container_1.xclbin'
INFO: [SW-EM 09-0] Unable to find emconfig.json. Using default device.
Trying to program device[0]: xilinx_zcu102_base_202010_1
Device[0]: program successful!
Software emulation of compute unit(s) exited unexpectedly

My host code is...

#include "xcl2.hpp"
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include<stdlib.h>
#include <vector>
#include <errno.h>
#include <math.h>
#include <string.h>
#include "Image.h"

#define DATA_SIZE 4096
int size = DATA_SIZE;


int main(int argc, char **argv) {
    if (argc != 2) {
        std::cout << "Usage: " << argv[0] << " <XCLBIN File>" << std::endl;
        return EXIT_FAILURE;
    }

    std::string binaryFile = argv[1];
    size_t vector_size_bytes = sizeof(int) * DATA_SIZE;
    cl_int err;
    cl::Context context;
    cl::Program program;
    cl::Kernel krnl_sob;
    cl::Kernel krnl_sob1;
    cl::Kernel krnl_sob2;
    cl::CommandQueue q;



      std::vector<unsigned char, aligned_allocator<unsigned char>> source_in1(DATA_SIZE);
      std::vector<unsigned char, aligned_allocator<unsigned char>> source_in2(DATA_SIZE);

      std::vector<unsigned char, aligned_allocator<unsigned char>> source_sw_results(DATA_SIZE);
      std::vector<unsigned char, aligned_allocator<unsigned char>> source_sw_results2(DATA_SIZE);
      std::vector<unsigned char, aligned_allocator<unsigned char>> source_sw_results3(DATA_SIZE);



     for (int i = 0; i < DATA_SIZE; i++) {
         source_sw_results[i] = source_in1[i];
         }


    auto devices = xcl::get_xil_devices();

    auto fileBuf = xcl::read_binary_file(binaryFile);
    cl::Program::Binaries bins{{fileBuf.data(), fileBuf.size()}};
    int valid_device = 0;
    for (unsigned int i = 0; i < devices.size(); i++) {
        auto device = devices[i];
        // Creating Context and Command Queue for selected Device
        OCL_CHECK(err, context = cl::Context(device, NULL, NULL, NULL, &err));
        OCL_CHECK(err,
                  q = cl::CommandQueue(
                      context, device, CL_QUEUE_PROFILING_ENABLE, &err));
        std::cout << "Trying to program device[" << i
                  << "]: " << device.getInfo<CL_DEVICE_NAME>() << std::endl;
        cl::Program program(context, {device}, bins, NULL, &err);
        if (err != CL_SUCCESS) {
            std::cout << "Failed to program device[" << i
                      << "] with xclbin file!\n";
        } else {
            std::cout << "Device[" << i << "]: program successful!\n";
            OCL_CHECK(err, krnl_sob = cl::Kernel(program, "grayconvert", &err));
            OCL_CHECK(err, krnl_sob1=cl::Kernel(program, "imgscan", &err));
            OCL_CHECK(err, krnl_sob1=cl::Kernel(program, "borderscan", &err));


            valid_device++;
            break; // we break because we found a valid device
        }
    }
    if (valid_device == 0) {
        std::cout << "Failed to program any device found, exit!\n";
        exit(EXIT_FAILURE);
    }
    
    source_in1={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};

    // Allocate Buffer in Global Memory
  // Buffers are allocated using CL_MEM_USE_HOST_PTR for efficient memory and
  // Device-to-host communication
  OCL_CHECK(err, cl::Buffer buffer_in1(
                     context, CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
                     vector_size_bytes, source_in1.data(), &err));

  OCL_CHECK(err, cl::Buffer buffer_output(
                     context, CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY,
  
  OCL_CHECK(err, err = krnl_sob.setArg(0, buffer_in1));
  //OCL_CHECK(err, err = krnl_sob.setArg(1, buffer_in2));
  OCL_CHECK(err, err = krnl_sob.setArg(1, buffer_output));
  OCL_CHECK(err, err = krnl_sob.setArg(2, size));

OCL_CHECK(err, err = q.enqueueMigrateMemObjects({buffer_in1},
                                                  0 /* 0 means from host*/));

// Launch the Kernel
  // to always use enqueueTask() for invoking HLS kernel
  OCL_CHECK(err, err = q.enqueueTask(krnl_sob));

  // Copy Result from Device Global Memory to Host Local Memory
  OCL_CHECK(err, err = q.enqueueMigrateMemObjects({buffer_output},
                                                  CL_MIGRATE_MEM_OBJECT_HOST));

  q.finish();

  // Creating  Kernel Object and setting args
  OCL_CHECK(err, cl::Buffer buffer_in2(
                       context, CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
                       vector_size_bytes, source_sw_results.data(), &err));
  
    OCL_CHECK(err, cl::Buffer buffer_output2(
                       context, CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY,
                       vector_size_bytes, source_sw_results2.data(), &err));
  //cl::Kernel krnl_sob1(program, "imgscan");

  OCL_CHECK(err, err = krnl_sob1.setArg(0, buffer_in2));
  OCL_CHECK(err, err = krnl_sob1.setArg(1, buffer_output2));
  OCL_CHECK(err, err = krnl_sob1.setArg(2, size));

OCL_CHECK(err, err = q.enqueueMigrateMemObjects({buffer_in2},
                                                  0 /* 0 means from host*/));
// Launch the Kernel

    OCL_CHECK(err, err = q.enqueueTask(krnl_sob1));

    // Copy Result from Device Global Memory to Host Local Memory
  OCL_CHECK(err, err = q.enqueueMigrateMemObjects({buffer_output2},
                                                  CL_MIGRATE_MEM_OBJECT_HOST));

  q.finish();


  // Creating  Kernel Object and setting args
 //OCL_CHECK(err, cl::Kernel krnl_sob2(program, "borderscan", &err));
  OCL_CHECK(err, cl::Buffer buffer_in3(
                       context, CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
                       vector_size_bytes, source_sw_results2.data(), &err));
  
    OCL_CHECK(err, cl::Buffer buffer_output3(
                       context, CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY,
                       vector_size_bytes, source_sw_results3.data(), &err));


//int size = DATA_SIZE;
  OCL_CHECK(err, err = krnl_sob2.setArg(0, buffer_in3));
  OCL_CHECK(err, err = krnl_sob2.setArg(1, buffer_output3));
  OCL_CHECK(err, err = krnl_sob2.setArg(2, size));

OCL_CHECK(err, err = q.enqueueMigrateMemObjects({buffer_in3},
                                                  0 /* 0 means from host*/));
// Launch the Kernel

    OCL_CHECK(err, err = q.enqueueTask(krnl_sob2));

    // Copy Result from Device Global Memory to Host Local Memory
  OCL_CHECK(err, err = q.enqueueMigrateMemObjects({buffer_output3},
                                                  CL_MIGRATE_MEM_OBJECT_HOST));

  q.finish();


    bool match = true;


    std::cout << "TEST " << (match ? "PASSED" : "FAILED") << std::endl;

    return (match ? EXIT_SUCCESS : EXIT_FAILURE);

}

Thanks in advance for any piece of advice!

0 Kudos
3 Replies
graces
Moderator
Moderator
478 Views
Registered: ‎07-16-2008

I noticed this message.

INFO: [SW-EM 09-0] Unable to find emconfig.json. Using default device.

How did you launch sw_emu? If from command line mode, you need to run 'emconfigutil' command to generate emulation configuration file emconfig.json for the target platform. The emconfig.json file must be in the same directory as the host executable.

-----------------------------------------------------------------------------------------------------------------------
Don’t forget to reply, kudo, and accept as solution.
If starting with Versal take a look at our Versal Design Process Hub and our Versal Blogs.
-----------------------------------------------------------------------------------------------------------------------
0 Kudos
stzog
Explorer
Explorer
454 Views
Registered: ‎02-07-2020

@graces 

Hi!

I use Vitis GUI to build and run sw emulation,not command line mode.

How to do this via GUI?

0 Kudos
stzog
Explorer
Explorer
422 Views
Registered: ‎02-07-2020

@graces 

Is this error crucial for sw emulation run?

Moreover in my project the emconfig.json file exists on Emulation-SW folder.

 

0 Kudos