I am quite new to object oriented programming. Trying to modularize a code in a class format in order to make things easy to understand and make the code extendable. I am stuck with a below error:
Description Resource Path Location Type
make: *** [src/interface.o] Error 1 Emulation-SW /virtualization_proj C/C++ Problem
make: *** Waiting for unfinished jobs.... Emulation-SW /virtualization_proj C/C++ Problem
no matching function for call to ‘std::vector<std::vector<unsigned char, std::allocator<unsigned char> >, std::allocator<std::vector<unsigned char, std::allocator<unsigned char> > > >::push_back(<brace-enclosed initializer list>)’ interface.h /virtualization_proj/src line 58 C/C++ Problem
recipe for target 'src/interface.o' failed makefile /virtualization_proj/Emulation-SW line 57 C/C++ Problem
The error looks on the IDE as above: I would be really a great help if someone can help in resolving this error.
class INTERFACE{
public:
std::vector<cl::Device> devices;
cl::Device device;
std::vector<cl::Platform> platforms;
cl::Context context;
cl::CommandQueue q;
cl::Program::Binaries bins;
char *buf;
unsigned nb;
cl::Program program;
int push_xclbinFile_to_FPGA(){
bins.push_back({buf,nb}); // Push_back function is not getting recognized
devices.resize(1);
program= cl::Program(context, devices, bins);
return 1;
}
};
Edit
To make the question more clear, these lines work completely fine when I executing them from the main function as below. I hope this will clarify the question a little more.
Edit The main file code is as below:
int main(int argc, char* argv[]) {
// Compute the size of array in bytes
INTERFACE i_obj;
size_t size_in_bytes= i_obj.compute_size_in_bytes();
// Finding the device
int device_found= i_obj.finding_platform();
if(device_found==0){
std::cout<< "Device found successfully" << std::endl;
}
// Creating Context and Command Queue for selected device
cl::Context context(i_obj.devices);
cl::CommandQueue q(context, i_obj.device, CL_QUEUE_PROFILING_ENABLE);
i_obj.context= context;
i_obj.q= q;
VMGR *vm=new VMGR();
vm->initialize_mq(); // Creating the Queue1
while(1){
std::vector<std::string> numbers = vm->run();
int st=i_obj.buffer_values();
//setting input data
if (numbers.size()!=0){
if(numbers[2]=="SUB"){
//
// Read the xclbin file
int status_xclbin_read= i_obj.reading_the_xclbinFile(vm);
// Process the read Data
i_obj.bins.push_back({i_obj.buf,i_obj.nb});
(i_obj.devices).resize(1);
// Push the xclbin file into the FPGA
cl::Program program(i_obj.context, i_obj.devices, i_obj.bins);
// This call will get the kernel object from program. A kernel is an
// OpenCL function that is executed on the FPGA.
i_obj.krnl_vector_sub= cl::Kernel(program,"krnl_vsub");
int narg=0;
// set the kernel Arguments
i_obj.krnl_vector_sub.setArg(narg++,i_obj.buffer_a);
i_obj.krnl_vector_sub.setArg(narg++,i_obj.buffer_b);
i_obj.krnl_vector_sub.setArg(narg++,i_obj.buffer_result);
i_obj.krnl_vector_sub.setArg(narg++,api::DATA_SIZE);
//We then need to map our OpenCL buffers to get the pointers
i_obj.ptr_a = (int *) (i_obj.q).enqueueMapBuffer (i_obj.buffer_a , CL_TRUE , CL_MAP_WRITE , 0, size_in_bytes);
i_obj.ptr_b = (int *) (i_obj.q).enqueueMapBuffer (i_obj.buffer_b , CL_TRUE , CL_MAP_WRITE , 0, size_in_bytes);
i_obj.ptr_result = (int *) (i_obj.q).enqueueMapBuffer (i_obj.buffer_result , CL_TRUE , CL_MAP_READ , 0, size_in_bytes);
i_obj.bins.clear();
}
for(int i = 0 ; i< api::DATA_SIZE; i++){
i_obj.ptr_a[i] = stoi(numbers[0]);
i_obj.ptr_b[i] = stoi(numbers[1]);
}
// Data will be migrated to kernel space
(i_obj.q).enqueueMigrateMemObjects({i_obj.buffer_a,i_obj.buffer_b},0/* 0 means from host*/);
if(numbers[2]=="SUB"){
//Launch the Kernel
(i_obj.q).enqueueTask(i_obj.krnl_vector_sub);
}
// The result of the previous kernel execution will need to be retrieved in
// order to view the results. This call will transfer the data from FPGA to
// source_results vector
(i_obj.q).enqueueMigrateMemObjects({i_obj.buffer_result},CL_MIGRATE_MEM_OBJECT_HOST);
(i_obj.q).finish();
//Verify the result
for (int i = 0; i < api::DATA_SIZE; i++) {
std::cout << i_obj.ptr_result[i] <<std::endl;
}
(i_obj.q).enqueueUnmapMemObject(i_obj.buffer_a , i_obj.ptr_a);
(i_obj.q).enqueueUnmapMemObject(i_obj.buffer_b , i_obj.ptr_b);
(i_obj.q).enqueueUnmapMemObject(i_obj.buffer_result , i_obj.ptr_result);
(i_obj.q).finish();
/***********************Writing to the Shared Memory************/
//char *key1 = "/introduction5a";
std::ostringstream str1;
str1<< i_obj.ptr_result[0];
std::string data=str1.str();
std::cout <<"The data value="<<data<<std::endl;
char *intro= new char[data.length()+1];
strcpy(intro, data.c_str());
std::cout <<"The data value="<<intro <<std::endl;
int size= vm->create_and_write_shared_memory(api::key1, intro, strlen(intro));
std::cout<< size<< std::endl;
int y=0;
while(y==0){
y= vm->send_message_to_process_to_read_shared_memory();
}
int j=0;
while(j==0){
j= vm->receive_process_complete_message(); // This message is essential to avoid bugs
}
}
}
return 0;
}
buf
? Kindly provide a MVCE (minimum, verifiable, complete example). - lorrochar *buf;
-- If your goal is to make things maintainable, using pointers will go against that plan. Why notstd::string buf;
, or evenstd::vector<char> buf
;? - PaulMcKenzie