OpenCL 1.2 no member Error in namespace cl - c++11

I am trying to write an openCL 1.2 program based off examples I have found online and I'm encountering an error. Has the library changed to use std::exception now similar to std::vector?
With the snippet below:
// Build the kernel
cl::Program program(context, sources);
try{
program.build({device});
} catch(cl::Error& e){
std::cerr << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device) << std::endl;
throw e;
}

I think you are using the command program.build wrong. It does not take the device list as input parameters, but rather a string of preprocessor options. Which device to use is already baked in the context object. Also it does return the error code. Try it like this:
int error = program.build("-cl-fast-relaxed-math");
if(error) std::cerr << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device) << std::endl;
Here the example "-cl-fast-relaxed-math" is an option to switch off sanity checks for floating-point.

Related

In Boost Property tree library, how I can handle file not found error in custom way (C++)

I want to read a json data from a file in C++ using boost libraries. Using property tree. I am new to programming, very new to c++ and its the first time i use boost library. I had some history in C many years ago. And i have a weeks experience in C++ using SFML library.
Below is my template code loads a file, reads data and if fails give an error. I want to change my error handling a bit different way.
1. if i cant open the mentioned file because it doesn't exist I want to create a blank file named accordingly. 2. But if some other error happens but the file exists I don't want to accidentally delete the file and create new one (erasing the data).
I guess it will be something like
catch (const std::exception& e)
{
if (e.type == std::exception::filenotfound()) //whatever function i need
{
boost::property_tree::write_json("./data.json", pt);
}
else
{
std::cout << e.what() << std::endl;
}
}
So I want to create the file only if it genuinely doesn't exist but if somehow corrupted, missing data i look for or some unimaginable other error happens I don't want to delete it. Here is my template (without the implementation of what i want)
#include <iostream>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
int main()
{
boost::property_tree::ptree pt;
try
{
boost::property_tree::read_json("./data.json", pt);
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
}
std::cout << pt.get<std::string>("test_name","default") << std::endl;
return 0;
}
How exactly I should write this code. I searched the internet for 2 hours but I couldn't find anything i want. (Or at least I didn't notice) And I am not experienced enough to decode original library documentations. They feel like encrypted to me so I look for samples instead.
https://stackoverflow.com/users/440558/some-programmer-dude has answered my question. Here is the exact coding:
try
{
// Trying to load the file
}
catch (const boost::property_tree::json_parser_error& e1)
{
//Here what i do if i cant find the file
}
If file doesnt exist it does something. But if file exists but if its in wrong format or doesnt have the approriate data it doesnt do anything.

error using directory_entry in boost filesystem

I'm starting to use the Boost library in my C++ programs using Code Blocks on Ubuntu.
I encounter a problem while manipulating files, the following code returns a segmentation fault :
#include <iostream>
#include <boost/filesystem.hpp>
using namespace std;
int main()
{
boost::filesystem::path my_file("/home/malinou/workspace/grunbaum2/grunbaum/Bases/config.txt");
cout << "my_file path : " << my_file.string() << endl;
cout << "my_file exists : " << boost::filesystem::exists(my_file.string()) << endl;
cout << "my_file path : " << my_file.string() << endl;
return 0;
}
I'm using gcc compiler with flags -lboost_system and -lboost_filesystem, and the console output is :
my_file path : /home/malinou/workspace/grunbaum2/grunbaum/Bases/config.txt
my_file exists : 1
Segmentation fault (core dumped)
Process returned 139 (0x8B) execution time : 0.093 s
Press ENTER to continue.
Any idea why my_file seems to cause a problem after calling the exists() function?
(P.S: The problem is the same when I call the is_regular_file() function instead of the exists() one.)
To finally answer my question, it seemed to be a linking error due to the IDE I used. I created a new project with the same files, and it worked perfectly...weird
Anyway, thanks for everyones' help!

Using OpenGL Vertex Buffer Objects with Dynamically linked OpenGL from Windows

I am working on setting up a basic OpenGL application by dynamically linking the opengl32.dll file pre-packaged with Windows (That part is non-optional). However I am having quite a lot of difficulty getting procedure addresses for the functions related to Vertex Buffer Objects.
My initial investigations have revealed that windows only exposes the OpenGL 1.1 specification at first, and wglGetProcAddress calls need to be used to get any functions more recent than that. So I modified my code to attempt that method as well. I am using glGenBuffers as my example case, and have attempted four different attempts to load it, and all fail. I have also used glGetString to check my version number which is reported as major version 4, so I doubt it lacks VBO support.
How should I be getting the proc addresses for these VBO functions?
A minimized example of the code I'm dealing with is here:
#include <iostream>
#include "windows.h"
using namespace std;
int main()
{
//Load openGL and get necessary functions
HINSTANCE hDLL = LoadLibrary("opengl32.dll");
PROC WINAPI(*winglGetProcAddress)(LPCSTR);
void(*genBuffers)(int, unsigned int*);
if(hDLL)
{
winglGetProcAddress = (PROC WINAPI(*)(LPCSTR))GetProcAddress(hDLL, "wglGetProcAddress");
if(winglGetProcAddress == NULL){cout << "wglGetProcAddress not found!" << endl; return 0;}
genBuffers = (void(*)(int, unsigned int*))GetProcAddress(hDLL, "glGenBuffers");
if(genBuffers == NULL){genBuffers = (void(*)(int, unsigned int*))winglGetProcAddress("glGenBuffers");}
}
else
{cout << "This application requires Open GL support." << endl; return 0;}
//glGenBuffers not supported, fallback to glGenBuffersARB
if(genBuffers == NULL)
{
genBuffers = (void(*)(int, unsigned int*))GetProcAddress(hDLL, "glGenBuffersARB");
if(genBuffers == NULL){genBuffers = (void(*)(int, unsigned int*))winglGetProcAddress("glGenBuffersARB");}
if(genBuffers == NULL)
{cout << "Could not locate glGenBuffers or glGenBuffersARB in opengl32.dll." << endl; return 0;}
}
//get a Vertex Buffer Object
unsigned int a[1];
genBuffers(1, a);
//cleanup
if(!FreeLibrary(hDLL))
{cout << "Failed to free the opengl32.dll library." << endl;}
return 0;
}
When run, it loads the library and get's the wglGetProcAddress correctly, but then outputs the "Could not locate glGenBuffers or glGenBuffersARB in opengl32.dll." error, indicating it failed to get either "glGenBuffers" or "glGenBuffersARB" using either "GetProcAddress" or "wglGetProcAddress".
Alternatively, if this does mean I do not have VBO support, will a driver update help, or is it even possible to get it supported? I'd really rather not use deprecated immediate mode calls.
I am running this in Code::Blocks, on Windows XP, Intel Core i5, with an NVIDIA GeForce GTX 460.

UpdateDriverForPlugAndPlayDevices error is telling me I'm *not* doing something that I am

I'm working on a means of installing a driver. Because of the multiple platforms on which this must work, I'm shelling-out to both devcon and dpinst to do the work of driver install/update/removal when needed. While testing, I'm having problems with the shelling out to devcon. To isolate, I wrote a small app to do what devcon does in update see here, using the devcon source from the WinDDK for reference. I'm having some problems with UpdateDriverForPlugAndPlayDevices() from Setup API (actually part of Newdev.dll) see here. The source code is here:
#include <iostream>
#include <Windows.h>
#include <newdev.h>
int main(int argc, char** argv) {
// Go through the same steps as does dev con for this update crap
char infFile[MAX_PATH];
if(3 > argc) {
std::cerr << "an INF and HW ID must be specified" << std::endl;
return 1;
}
DWORD result(GetFullPathName(argv[1], MAX_PATH, infFile, NULL));
if((result >= MAX_PATH) || (0 == result)) {
std::cerr << "path is too long for buffer" << std::endl;
return 1;
}
if(GetFileAttributes(infFile) == -1) {
std::cerr << "file doesn't exist" << std::endl;
return 1;
}
BOOL reboot(FALSE);
if(!UpdateDriverForPlugAndPlayDevices(NULL, argv[2], infFile, INSTALLFLAG_FORCE, &reboot)) {
std::cerr << "Failed to install the driver. Code: "
<< GetLastError()
<< std::endl;
return 2;
}
if(reboot) {
std::cout << "A reboot is needed to complete driver install"
<< std::endl;
}
return 0;
}
The program fails when UpdateDriverForPlugAndPlayDevices() returns false. This then prints the error code, returned by GetLastError(), so I'd know what went wrong. The error code returned: 259. According to this resource says this is ERROR_NO_MORE_ITEMS. According to the link for UpdateDriverForPlugAndPlayDevices(), this function returns this error code when, "The function found a match for the HardwareId value, but the specified driver was not a better match than the current driver and the caller did not specify the INSTALLFLAG_FORCE flag." You'll notice from my code that I did specify this flag.
I do not know where to go from here. Can someone please identify from this code what it is I'm missing? This just has the "feel" of something simple, but I'm totally missing it.
Thank you,
Andy
The problem appeared to be not with the code but with the INF file. Interesting that the documentation for the function said that using that flag will force the install but didn't when the INF file didn't "list" any device classes in the models section. This is how I was able to install eventually. I added the correct device class to the models section in the INF.
EDIT Sep. 17, 2020
It was requested by someone just today (of the edit) to add an example from the INF. It's been 8 years since I had this issue and I no longer work for this team. However, as best as I can recall, and drawing heavily upon the docs for INF Models Section and INF Manufacturers Section, I hope this helps.
Essentially, the class is specified by the Models Section and the model is specified by the Manufacturer Section.
[Manufacturer]
%MfgName%=Standard,NTamd64
[Standard.NTamd64]
%DeviceString%=<class path or GUID>\<device>
[Strings]
MfgName=ACME
DeviceString="Device Type"

In Boost.Test, how to obtain the name of current test?

In Boost.Test, how can I obtain the name of the current auto test case?
Example:
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(MyTest)
{
std::cerr << "Starting " << test_name << std::endl;
// lots of code here
std::cerr << "Ending " << test_name << std::endl;
}
In the example, I want the variable test_name to contain "MyTest".
There is an undocumented* function that may be called for that purpose. The following line will flush the name of the current test to cerr:
#include <boost/test/framework.hpp>
...
std::cerr << boost::unit_test::framework::current_test_case().p_name
<< std::endl;
Note however that using this API does not flush the parameters in case of parametrized tests.
You might also be interested in the test checkpoints** (which seems to be what you want to do.)
#include <boost/test/included/unit_test.hpp>
...
BOOST_AUTO_TEST_CASE(MyTest)
{
BOOST_TEST_CHECKPOINT("Starting");
// lots of code here
BOOST_TEST_CHECKPOINT("Ending");
}
EDIT
* The current_test_case() function is now documented, see the official Boost documentation.
** BOOST_TEST_CHECKPOINT was previously called BOOST_CHECKPOINT. See the Boost changelog (1.35.0).
A different question about suite names gives a way to extract the name rather than just printing it:
auto test_name = std::string(boost::unit_test::framework::current_test_case().p_name)

Resources