cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Explorer
Explorer
1,016 Views
Registered: ‎02-07-2020

Vitis sw-emulation error: expected unqualified-id

Jump to solution

Hi to all!

I receive the following error....on Vitis console.

ERROR: [v++ 200-70] Compilation errors found: In file included from /home/stavros/workspace/add_int/src/vadd.cpp:1:
/home/stavros/workspace/add_int/src/vadd.cpp:54:6: error: expected unqualified-id
     for (int i = 0, i < size, i += 1024;)
     ^
1 error generated.
ERROR: [v++ 60-300] Failed to build kernel(ip) vadd, see log for details: /home/stavros/workspace/add_int/Emulation-SW/binary_container_1.build/vadd/vadd/vivado_hls.log
ERROR: [v++ 60-599] Kernel compilation failed to complete
ERROR: [v++ 60-592] Failed to finish compilation
makefile:83: recipe for target 'binary_container_1.build/vadd.xo' failed
make: *** [binary_container_1.build/vadd.xo] Error 1

In vivado_hls_log the error is shown as....

ERROR: [HLS 200-70] Compilation errors found: In file included from /home/stavros/workspace/add_int/src/vadd.cpp:1:
/home/stavros/workspace/add_int/src/vadd.cpp:54:6: error: expected unqualified-id
     for (int i = 0, i < size, i += 1024;)
     ^
1 error generated.
Failed during preprocessing.
    while executing
"source vadd.tcl"
    ("uplevel" body line 1)
    invoked from within
"uplevel \#0 [list source $arg] "

INFO: [Common 17-206] Exiting vivado_hls at Thu Apr  9 17:34:54 2020...

Kernel code for adding two numbers is....

#include <vector>
#include <stdio.h>
#include <string.h>
#define BUFFER_SIZE 1024
#define DATA_SIZE 4096


extern "C"
{

void vadd(const  int *x, 
          const  int *y, 
          unsigned int *z);   
}


#pragma HLS INTERFACE m_axi port = x offset = slave bundle = gmem
#pragma HLS INTERFACE m_axi port = y offset = slave bundle = gmem
#pragma HLS INTERFACE m_axi port = z offset = slave bundle = gmem
#pragma HLS INTERFACE s_axilite port = x bundle = control
#pragma HLS INTERFACE s_axilite port = y bundle = control
#pragma HLS INTERFACE s_axilite port = z bundle = control
#pragma HLS INTERFACE s_axilite port = return bundle = control


    	for (int i = 0, i < size, i += BUFFER_SIZE;)
    	{
            int chunk_size = BUFFER_SIZE;

            int main(0)
            {
              int x;
              int y;
              int z;

              printf("Enter two numbers to add\n");
              scanf("%d%d", &x, &y);
              )
              z = (x + y);
              return 0;
              printf("Sum of the numbers = %d\n", z);
            }
 }

An ideas guys?

Thanks in advance

Regards

 

0 Kudos
1 Solution

Accepted Solutions
Highlighted
Explorer
Explorer
566 Views
Registered: ‎02-07-2020

@HRZ 

You are my man!!!

Thanks a lot!!!!!!!

View solution in original post

0 Kudos
17 Replies
Highlighted
Explorer
Explorer
945 Views
Registered: ‎02-07-2020

Any idea guys?

0 Kudos
Highlighted
Moderator
Moderator
892 Views
Registered: ‎07-16-2008

Syntax error of the for loop?

     for (int i = 0, i < size, i += 1024;)

 Check the comma and semicolon..

-------------------------------------------------------------------------
Don't forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
Highlighted
Explorer
Explorer
864 Views
Registered: ‎02-07-2020

Hi again!

I tried to correct the code.

Build sw-emulation runs without error.

When i run the simulation seems to complete fine except one error at the end...

Found Platform
Platform Name: Xilinx
INFO: Reading ../binary_container_1.xclbin
Loading: '../binary_container_1.xclbin'
Trying to program device[0]: xilinx_u200_xdma_201830_2
INFO: [HW-EM 01] Hardware emulation runs simulation underneath. Using a large data set will result in long simulation times. It is recommended that a small dataset is used for faster execution. The flow uses approximate models for DDR memory and interconnect and hence the performance data generated is approximate.
Device[0]: program successful!
XRT build version: 2.3.1301
Build hash: 192e706aea53163a04c574f9b3fe9ed76b6ca471
Build date: 2019-10-24 20:05:16
Git branch: 2019.2
PID: 31023
UID: 1000
[Wed Apr 15 15:52:07 2020]
HOST: stavros-FPGA
EXE: /home/stavros/workspace/giorgos/Emulation-HW/giorgos
[XRT] ERROR: bad kernel argument index 0
../src/host.cpp:98 Error calling err = krnl_vector_add.setArg(0, buffer_in1), error code is: -49
[XRT] WARNING: Profiling may contain incomplete information. Please ensure all OpenCL objects are released by your host code (e.g., clReleaseProgram()).
INFO::[ Vitis-EM 22 ] [Time elapsed: 0 minute(s) 14 seconds, Emulation time: 0.0246499 ms]

An help would be precious!

Thanks in advance

my host code is.....

#include "xcl2.hpp"
#include <algorithm>
#include <vector>
#define DATA_SIZE 4096





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::Kernel krnl_vector_add;
	cl::CommandQueue q;

	std::vector<int, aligned_allocator<int>> source_in1(DATA_SIZE);
	std::vector<int, aligned_allocator<int>> source_in2(DATA_SIZE);
	std::vector<int, aligned_allocator<int>> source_hw_results(DATA_SIZE);
	std::vector<int, aligned_allocator<int>> source_sw_results(DATA_SIZE);

	// OPENCL HOST CODE AREA START
	// get_xil_devices() is a utility API which will find the xilinx
	// platforms and will return list of devices connected to Xilinx platform
	auto devices = xcl::get_xil_devices();
	// read_binary_file() is a utility API which will load the binaryFile
	// and will return the pointer to file buffer.
	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_vector_add = cl::Kernel(program, "vadd", &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);
	}

	// 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_in2(context,
			CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
			vector_size_bytes,
			source_in2.data(),
			&err));
	OCL_CHECK(err,
		cl::Buffer buffer_output(context,
			CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY,
			vector_size_bytes,
			source_hw_results.data(),
			&err));

	int size = DATA_SIZE;
	OCL_CHECK(err, err = krnl_vector_add.setArg(0, buffer_in1));
	OCL_CHECK(err, err = krnl_vector_add.setArg(1, buffer_in2));
	OCL_CHECK(err, err = krnl_vector_add.setArg(2, buffer_output));
	OCL_CHECK(err, err = krnl_vector_add.setArg(3, size));

	// Copy input data to device global memory
	OCL_CHECK(err,
		err = q.enqueueMigrateMemObjects({buffer_in1, buffer_in2},
			0 /* 0 means from host*/));

	// Launch the Kernel
	// For HLS kernels global and local size is always (1,1,1). So, it is recommended
	// to always use enqueueTask() for invoking HLS kernel
	OCL_CHECK(err, err = q.enqueueTask(krnl_vector_add));

	// 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();
	// OPENCL HOST CODE AREA END

	
	bool match = true;

	std::cout << "TEST " << (match ? "PASSED" : "FAILED") << std::endl;
	return (match ? EXIT_SUCCESS : EXIT_FAILURE);
}

and kernel code....

#include <vector>
#include <stdio.h>

extern "C"
{
int vadd( )
	{
	unsigned char a;
	unsigned char b;
	unsigned char c;

#pragma HLS INTERFACE m_axi port = a offset = slave bundle = gmem
#pragma HLS INTERFACE m_axi port = b offset = slave bundle = gmem
#pragma HLS INTERFACE m_axi port = c offset = slave bundle = gmem
#pragma HLS INTERFACE s_axilite port = a bundle = control
#pragma HLS INTERFACE s_axilite port = b bundle = control
#pragma HLS INTERFACE s_axilite port = c bundle = control
//#pragma HLS INTERFACE s_axilite port = size bundle = control
#pragma HLS INTERFACE s_axilite port = return bundle = control

	c = a + b;

	return c;
	}

}

 

0 Kudos
Highlighted
Moderator
Moderator
839 Views
Registered: ‎07-16-2008
[XRT] ERROR: bad kernel argument index 0
../src/host.cpp:98 Error calling err = krnl_vector_add.setArg(0, buffer_in1), error code is: -49

The error points to the kernel argument.

It seems that you are referencing Vitis Accel Example - Hello World. However, you declared different kernel argument type and size.

https://github.com/Xilinx/Vitis_Accel_Examples/blob/master/hello_world/src/vadd.cpp 

-------------------------------------------------------------------------
Don't forget to reply, kudo, and accept as solution.
-------------------------------------------------------------------------
0 Kudos
Highlighted
Explorer
Explorer
819 Views
Registered: ‎02-07-2020

@graces 

Thanks a lot for your reply but i didn't managed to find the different kernel argument type and size...

Modified kernel code and new error....

 

Found Platform
Platform Name: Xilinx
INFO: Reading ../binary_container_1.xclbin
Loading: '../binary_container_1.xclbin'
Trying to program device[0]: xilinx_u200_xdma_201830_2
ERROR: S_AXI_CONTROL remap entry is absent in xmlbin
XRT build version: 2.3.1301
Build hash: 192e706aea53163a04c574f9b3fe9ed76b6ca471
Build date: 2019-10-24 20:05:16
Git branch: 2019.2
PID: 10670
UID: 1000
[Thu Apr 16 15:44:54 2020]
HOST: stavros-FPGA
EXE: /home/stavros/workspace/giorgos/Emulation-SW/giorgos
[XRT] ERROR: Failed to load xclbin.
Failed to program device[0] with xclbin file!
Failed to program any device found, exit!

with kernel code...

 

extern "C"
{
int vadd(){

		  int a = 2;
		  int b = 5;
		  int c;
		 int size;

		    c = a + b;
		    return c;
#pragma HLS INTERFACE s_axilite port=return bundle=control
#pragma HLS INTERFACE s_axilite port=size bundle=control
#pragma HLS INTERFACE s_axilite port=a bundle=control
#pragma HLS INTERFACE s_axilite port=b bundle=s_control
#pragma HLS INTERFACE s_axilite port=c bundle=s_control
#pragma HLS INTERFACE m_axi port=a offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=b offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=c offset=slave bundle=gmem

}


	}
0 Kudos
Highlighted
Explorer
Explorer
796 Views
Registered: ‎02-07-2020
Any idea guys?The code is so simple...Just two numbers add.
Something with the interfaces is wrong...
0 Kudos
Highlighted
Adventurer
Adventurer
747 Views
Registered: ‎03-01-2020

You don't have any kernel arguments. Your function deceleration should look like this:

int vadd(int a, int b, int c, int size)

 

0 Kudos
Explorer
Explorer
737 Views
Registered: ‎02-07-2020

Thanks for your reply.

Unfortunately i get the same error after the modification you pointed me...

extern "C"
{
int vadd(int a, int b, int c, int size){

			 a=2;
			 b=5;
		     c = a + b;

		    return c;

#pragma HLS INTERFACE s_axilite port=return bundle=control
#pragma HLS INTERFACE s_axilite port=size bundle=control
#pragma HLS INTERFACE s_axilite port=a bundle=control
#pragma HLS INTERFACE s_axilite port=b bundle=s_control
#pragma HLS INTERFACE s_axilite port=c bundle=s_control
#pragma HLS INTERFACE m_axi port=a offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=b offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=c offset=slave bundle=gmem
}
	}

error....

Found Platform
Platform Name: Xilinx
INFO: Reading ../binary_container_1.xclbin
Loading: '../binary_container_1.xclbin'
Trying to program device[0]: xilinx_u200_xdma_201830_2
ERROR: S_AXI_CONTROL remap entry is absent in xmlbin
XRT build version: 2.3.1301
Build hash: 192e706aea53163a04c574f9b3fe9ed76b6ca471
Build date: 2019-10-24 20:05:16
Git branch: 2019.2
PID: 5631
UID: 1000
[Mon Apr 20 12:37:12 2020]
HOST: stavros-FPGA
EXE: /home/stavros/workspace/giorgos/Emulation-SW/giorgos
[XRT] ERROR: Failed to load xclbin.
Failed to program device[0] with xclbin file!
Failed to program any device found, exit!
0 Kudos
Highlighted
Adventurer
Adventurer
731 Views
Registered: ‎03-01-2020

Try using the same "control" bundle for all the ports; i.e. use "control" instead of "s_control" for "b" and "c". Also maybe remove the "size" port completely; I didn't realize it is not actually used in your kernel.

0 Kudos
Highlighted
Explorer
Explorer
722 Views
Registered: ‎02-07-2020

Nothing changed unfortunately...

kernel code....

 

extern "C"
{
int vadd(int a, int b, int c){

			 a=2;
			 b=5;


		     c = a + b;

		    return c;


#pragma HLS INTERFACE s_axilite port=return bundle=control
#pragma HLS INTERFACE s_axilite port=a bundle=control
#pragma HLS INTERFACE s_axilite port=b bundle=control
#pragma HLS INTERFACE s_axilite port=c bundle=control
#pragma HLS INTERFACE m_axi port=a offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=b offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=c offset=slave bundle=gmem


}


	}

Hls log after build is flawless but after run i get the same error...

0 Kudos
Highlighted
Adventurer
Adventurer
717 Views
Registered: ‎03-01-2020

You probably should not have c both as an argument and as return. How about this?

extern "C"
{
int vadd(int a, int b, int *c){

#pragma HLS INTERFACE s_axilite port=return bundle=control
#pragma HLS INTERFACE s_axilite port=a bundle=control
#pragma HLS INTERFACE s_axilite port=b bundle=control
#pragma HLS INTERFACE s_axilite port=c bundle=control
#pragma HLS INTERFACE m_axi port=a offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=b offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=c offset=slave bundle=gmem

a=2;
b=5;

*c = a + b; } }

 

0 Kudos
Highlighted
Explorer
Explorer
711 Views
Registered: ‎02-07-2020

Well new error probably more specific generated.....

 

Found Platform
Platform Name: Xilinx
INFO: Reading ../binary_container_1.xclbin
Loading: '../binary_container_1.xclbin'
Trying to program device[0]: xilinx_u200_xdma_201830_2
Device[0]: program successful!
XRT build version: 2.3.1301
Build hash: 192e706aea53163a04c574f9b3fe9ed76b6ca471
Build date: 2019-10-24 20:05:16
Git branch: 2019.2
PID: 13361
UID: 1000
[Mon Apr 20 14:07:49 2020]
HOST: stavros-FPGA
EXE: /home/stavros/workspace/giorgos/Emulation-SW/giorgos
[XRT] ERROR: Invalid scalar argument size, expected 4 got 8
ERROR: clSetKernelArg() for kernel "vadd", argument index 0.
../src/host.cpp:85 Error calling err = krnl_vector_add.setArg(0, buffer_in1), error code is: -51
[XRT] WARNING: Profiling may contain incomplete information. Please ensure all OpenCL objects are released by your host code (e.g., clReleaseProgram()).

Host code again....

 

#include "xcl2.hpp"
#include <algorithm>
#include <vector>
#define DATA_SIZE 1



int size;
#pragma HLS INTERFACE s_axilite port = size bundle = control

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::Kernel krnl_vector_add;
	cl::CommandQueue q;

	std::vector<int, aligned_allocator<int>> source_in1(DATA_SIZE);
	std::vector<int, aligned_allocator<int>> source_in2(DATA_SIZE);
	std::vector<int, aligned_allocator<int>> source_hw_results(DATA_SIZE);
	std::vector<int, aligned_allocator<int>> source_sw_results(DATA_SIZE);

	// OPENCL HOST CODE AREA START
	// get_xil_devices() is a utility API which will find the xilinx
	// platforms and will return list of devices connected to Xilinx platform
	auto devices = xcl::get_xil_devices();
	// read_binary_file() is a utility API which will load the binaryFile
	// and will return the pointer to file buffer.
	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_vector_add = cl::Kernel(program, "vadd", &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);
	}

	// 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_in2(context,
			CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY,
			vector_size_bytes,
			source_in2.data(),
			&err));
	OCL_CHECK(err,
		cl::Buffer buffer_output(context,
			CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY,
			vector_size_bytes,
			source_hw_results.data(),
			&err));

	int size = DATA_SIZE;
	OCL_CHECK(err, err = krnl_vector_add.setArg(0, buffer_in1));
	OCL_CHECK(err, err = krnl_vector_add.setArg(1, buffer_in2));
	OCL_CHECK(err, err = krnl_vector_add.setArg(2, buffer_output));
	OCL_CHECK(err, err = krnl_vector_add.setArg(3, size));

	// Copy input data to device global memory
	OCL_CHECK(err,
		err = q.enqueueMigrateMemObjects({buffer_in1, buffer_in2},
			0 /* 0 means from host*/));

	// Launch the Kernel
	// For HLS kernels global and local size is always (1,1,1). So, it is recommended
	// to always use enqueueTask() for invoking HLS kernel
	OCL_CHECK(err, err = q.enqueueTask(krnl_vector_add));

	// 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();
	// OPENCL HOST CODE AREA END


	bool match = true;

	std::cout << "TEST " << (match ? "PASSED" : "FAILED") << std::endl;
	return (match ? EXIT_SUCCESS : EXIT_FAILURE);
}
0 Kudos
Highlighted
Adventurer
Adventurer
705 Views
Registered: ‎03-01-2020

Your OpenCL host code is clearly not made for the kernel you are using. I recommend reading up on OpenCL basics and checking Xilinx's examples and documentation more thoroughly to clearly understand how things work; after that, fixing the errors you are getting will become very easy.

0 Kudos
Highlighted
Explorer
Explorer
697 Views
Registered: ‎02-07-2020
Thanks a lot for your help!!!
Indeed ,The host code is from Hello World example slightly modified to suit my kernel...
0 Kudos
Highlighted
Explorer
Explorer
608 Views
Registered: ‎02-07-2020

@HRZ 

According to your instructions i managed to get the following result....

 Found Platform
Platform Name: Xilinx
INFO: Reading ../vadd.xclbin
Loading: '../vadd.xclbin'
Trying to program device[0]: xilinx_u200_xdma_201830_2
Device[0]: program successful!

Does this mean that run is ok??

If so where can i see the result of the two number addition, i implemented in kernel?

Regards!

0 Kudos
Highlighted
Adventurer
Adventurer
587 Views
Registered: ‎03-01-2020

Looking at the host code you posted previously, it seems you have removed the CPU verification part where the output of the kernel and the output of CPU computation are compared to see if they are the same. Either way, it seems your kernel code is running correctly now, but to see the output, you need to print the output in the host code after the kernel is executed. You just need to print buffer_output after the last "q.finish()" to see the output. 

0 Kudos
Highlighted
Explorer
Explorer
567 Views
Registered: ‎02-07-2020

@HRZ 

You are my man!!!

Thanks a lot!!!!!!!

View solution in original post

0 Kudos