Menu
  • HOME
  • TAGS

nvcc/CUDA 6.5 & c++11(future) - gcc 4.4.7

Tag: c++11,gcc,cuda,future

When I compile the following code containing the design C++11, I get errors - it does not compile. I've tried with different flags, but I haven't found a solution.

My setting: CUDA 6.5, gcc 4.4.7 I am not able to change the settings. How can I still make this work?

#include <stdio.h>
#include <vector>
#include "KD_tree.h"
#include "KD_tree.cpp"
#include <iostream>
#include <algorithm>
#include <cmath>
#include <future>
#define MYDEVICE 0

using namespace std;


int main()
{
    //do something..... 

    cudaDeviceProp devProp;
    cudaGetDeviceProperties(&devProp, MYDEVICE);
    printDevProp(devProp);
    int max_threads = devProp.warpSize;

   //do something else ... 

    return 0;
}

I've tried compiling with different flags:

nvcc -std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -o tree.out
In file included from cudaMain.cu:14:
simple_kd_tree.h:12:19: warning: extra tokens at end of #include directive
cudaMain.cu:19:18: error: future: No such file or directory


nvcc --std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -o tree.out
In file included from cudaMain.cu:14:
simple_kd_tree.h:12:19: warning: extra tokens at end of #include directive
cudaMain.cu:19:18: error: future: No such file or directory


nvcc --std=c++11 cudaMain.cu KD_tree.cpp -arch=sm_20 -c -o tree.out
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified

Do I have to split the c++ part? How would I do this exactly?

Best How To :

C++11 support is added officially in CUDA 7.0. And you need GCC version 4.7 or later to have C++11 support. See details here: http://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-compiler-new-features

std::move on a C++ class does not move all members?

c++,c++11,move

You create a variable foo Foo foo{"Hello",2.0f}; Then declare a vector std::vector<Foo> v; Then call push_back which invokes a copy of your Foo v.push_back(foo); std::cout << foo << std::endl; Then you std::move(foo), which invalidates your foo instance v.push_back(std::move(foo)); Trying to cout foo is now undefined behavior, as the internals are...

Is executing C++ code in comments with certain Unicode characters allowed, like in Java?

c++,c++11,unicode,comments

If I read this translation phase reference correctly, then the sequence // \u000d some code here is mapped in phase 1 to itself, i.e. the parser does not translate or expand \u000d. Instead the translation of such sequences happens in phase 5, which is after the comments are replaced by...

__cplusplus < 201402L return true in gcc even when I specified -std=c++14

c++,gcc,g++,c++14,predefined-macro

According to the GCC CPP manual (version 4.9.2 and 5.1.0): __cplusplus This macro is defined when the C++ compiler is in use. You can use __cplusplus to test whether a header is compiled by a C compiler or a C++ compiler. This macro is similar to __STDC_VERSION__, in that it...

Finding all keys that correspond to same value in std::unordered_map

c++,c++11,stl,c++14

I think the "obvious" way is excellent: it is simple, short and easy to read. Another option is to use stl algorithms. What you need is transform_if algorithm so you can say: std::transform_if(std::begin(theMap), std::end(theMap), std::back_inserter(arrKeys), check_value, get_value); but there is no such in stl. What I can suggest is: std::vector<int>...

Constructing priority_queue instance with Compare instance of different type

c++,gcc,constructor,containers

The below statement: priority_queue<int, deque<int>, less<int>> pq(greater<int>()); is actually parsed by the compiler as a declaration of pq function that returns an instance of priority_queue, and which takes a single parameter, being a pointer to a function that takes no arguments, and returns an instance of greater<int> type. This is...

Junk varchar entries in MSSQL database using ODBC

c++,sql-server,c++11,odbc

Thanks to @erg, here is the solution that worked for me: char mMessageText[100]; bool initConnection() { (...) // bind parameters SQLBindParameter(mSqlStatementHandle, 5, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, 100, 0, (SQLPOINTER)mMessageText, 100, NULL); (...) } bool fillDb() { (...) std::string lMessageText = "This text is longer than 15"; strcpy(mMessageText, lMessageText.c_str()); mMessageText[sizeof(mMessageText) - 1]...

I think assigning JsonValue values to JsonValues might be very slow, in comparison to having a Value be a key

c++,json,c++11

Assuming that you are using JsonCpp. What you would want to do is something like: b["features"] = std::move(a); This would move-assign the Value rather than copy-assigning it. Unfortunately, that class does not declare a move-assignment operator and one will not be implicitly generated. Fortunately, that class defines a swap function...

Call template function for the value of a pointer out of a template function, in C++

c++,templates,pointers,c++11

The whole body of your template function needs to compile for the types it's instantiated with, regardless of whether or not a branch will ever be taken. To get around this issue, you can define separate functions for when T is a pointer and when it's not. Using SFINAE: template...

Reordering vector of vectors based on input vector

c++,c++11,vector,stl,idioms

If you transpose the data, it's as easy as sorting the vectors by the index of the first element in them. This will be slower than your solution but may be more readable: void fix_order(std::vector<std::vector<std::string>>& data, const std::vector<std::string>& correct) { // setup index map, e.g. "first" --> 0 std::unordered_map<std::string, size_t>...

Simple thread/mutex test application is crashing

c++,multithreading,c++11,mutex,mingw-w64

workers.clear(); is not going to join all of the threads. Calling clear() will call the threads' deconstructors. std::thread::~thread will call std::terminate() if the thread is joinable(). Since you are calling clear() on the vector right after you create the vector the threads are still processing and are joinable. You have...

Call to implicitly-deleted copy constructor in LLVM(Porting code from windows to mac)

c++,osx,c++11,compiler-errors,llvm

This line of code is very ambiguous: for (auto it : _unhandledFiles)//ERROR HERE auto uses template argument deduction, so std::string s; std::string& sr = sr; auto x = sr; in the above code x is deduced to be of type std::string, not std::string&. So your loop is equivalent to: for...

Type function that returns a tuple of chosen types

c++,templates,c++11,metaprogramming

You can do this without recursion by simply expanding the parameter pack directly into a std::tuple: template<My_enum... Enums> struct Tuple { using type = std::tuple<typename Bind_type<Enums>::type...>; }; To answer your question more directly, you can declare a variadic primary template, then write two specializations: for when there are at least...

Implicit use of initializer_list

c++,c++11,initializer-list

Your program is not ill-formed because <vector> is guaranteed to include <initializer_list> (the same is true for all standard library containers) §23.3.1 [sequences.general] Header <vector> synopsis #include <initializer_list> ... Searching the standard for #include <initializer_list> reveals the header is included along with the following headers <utility> <string> <array> <deque> <forward_list>...

Same function with and without template

c++,c++11

The main reason to do something like this is to specialize void integerA(int x) to do something else. That is, if the programmer provides as input argument an int to member function abc::integerA then because of the C++ rules instead of instantiating the template member function the compiler would pick...

C++ error: deduced conflicting types for parameter 'T' string vs const char *

c++,string,templates,c++11,char

Well, std::string and const char* (<- this is what "pear" decays to when calling the function) are two different types you both want to deduce T from, just as the compiler says. To fix the issue, call the function with the correct type: searchInDequeFor(myDeque,std::string("pear")); ...

“Emulating” std::declval issues. Works (kind of) in g++, fails to compile in clang++

c++,c++11,decltype

Minimized to struct Meow {}; int main(){ decltype(Meow.purr()) d; } This is plainly invalid code, yet GCC 5.1 and trunk accept it. Not much to say about it other than "bug". Interestingly, both correctly rejects struct Meow {}; decltype(Meow.purr()) d; ...

How to check the values of a struct from an image/binary file?

c,gcc,binaryfiles

objdump parses object files (products of the compiler), which are relocatable (not executable) ELF files. At this stage, there is no such notion as the memory address these compiled pieces will run at. You have the following possibilities: Link your *.obj files into the final non-stripped (-g passed to compiler)...

Can't compile C++11 source using GCC 5.1 toolchain

c++,c++11,gcc5

You're not doing anything wrong. The library's source is missing an #include <memory>. This is simply an unfortunate error by the author of the library. It's surprisingly commonplace for people to rely on certain standard headers just so happening to include other standard headers on their particular implementation, without checking...

How to re-write templated function to handle type deduction

c++,templates,c++11

The problem is a mismatch between the type of the Map and the key types. But I would fix it not by correcting the order of the parameters std::map argument, but by changing the definition to be more generic. template <typename MapType, typename KeyType> void searchInMapByKey(const MapType & Map, KeyType...

How is shellcode generated from C? - With code example

python,c,gcc,assembly,shellcode

The problem with creating shellcode from C programs is not that you cannot control the assembly generated, nor something related with the code generation. The problem with creating shellcode from C programs is symbols resolution or relocation, call it whatever you like. You approach, for what I have understand, is...

Can I use STDIN for IPC?

c,gcc,ipc,stdin

You can use pipe for IPC. Now if you want to use STDIN_FILENO and STDOUT_FILENO it would look like this: #include <unistd.h> #include <stdio.h> int main(void) { char val = '!'; int filedes[2]; pipe(filedes); int proc = fork(); if (proc < 0) return -1; if (proc == 0) { close(1);...

How to match one of multiple alternative patterns with C++11 regex [duplicate]

c++,regex,c++11

It looks like regex is not fully implemented in gcc version 4.8.2 but rather in later versions of gcc (i.e., version > 4.9.0). https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53631 In gcc version 4.9.0 works ok LIVE DEMO So I guess you'll have to upgrade to newer version of gcc....

Why is initialization of enum class temporaries with arbitrary values allowed?

c++,c++11

Scoped enumeration types have an implicit underlying type of int, assuming no other underlying type is specified. All possible values of type int can be represented. 7.2p5: [...] For a scoped enumeration type, the underlying type is int if it is not explicitly specified. In both of these cases, the...

How can I convert an int to a string in C++11 without using to_string or stoi?

c++,string,c++11,gcc

Its not the fastest method but you can do this: #include <string> #include <sstream> #include <iostream> template<typename ValueType> std::string stringulate(ValueType v) { std::ostringstream oss; oss << v; return oss.str(); } int main() { std::cout << ("string value: " + stringulate(5.98)) << '\n'; } ...

Should checking loop conditions be counted towards total number of comparisons?

c++,algorithm,sorting,c++11

If you look at your inserstion sort As you already put count =1 because as for exits on exit condition of for loop. for same reason then it also make sense that when while loop cancels the count++ inside will not get executed but there was a comparison made. but...

C++ why does SFINAE fail with only a class template parameter?

c++,templates,c++11,sfinae

SFINAE comes to us from [temp.deduct]/8, emphasis mine: If a substitution results in an invalid type or expression, type deduction fails. An invalid type or expression is one that would be ill-formed, with a diagnostic required, if written using the substituted arguments. [ Note: If no diagnostic is required, the...

C++11 Allocation Requirement on Strings

c++,string,c++11,memory,standards

Section 21.4.1.5 of the 2011 standard states: The char-like objects in a basic_string object shall be stored contiguously. That is, for any basic_string object s, the identity &*(s.begin() + n) == &*s.begin() + n shall hold for all values of n such that 0 <= n < s.size(). The two...

Mapping const char * to duck-typed T at compile-time or run-time

c++,templates,c++11

Fatal allows you to trivially solve the compile time version of your problem using compile-time strings, type maps and type prefix trees. Let's first start with the headers we'll be using: // type_map so we can associated one type to another #include <fatal/type/map.h> // type_prefix_tree for efficient compile-time string lookups...

In c++11 what should happen first: raw string expansion or macros?

c++,c++11,preprocessor,rawstring

GCC and clang are right, VC++ is wrong. 2.2 Phases of translation [lex.phases]: [...] The source file is decomposed into preprocessing tokens (2.5) and sequences of white-space characters (including comments). Preprocessing directives are executed, [...] And 2.5 Preprocessing tokens [lex.pptoken] lists string-literals amongst the tokens. Consequently, parsing is required to...

Print addresses of all local variables in C

debugging,pointers,gcc,gdb,memory-address

There is no built-in command to do this. There is an open feature request in gdb bugzilla to have a way to show the meaning of all the known slots in the current stack frame, but nobody has ever implemented this. This can be done with a bit of gdb...

Scoping rules for struct variables in GCC

c,gcc,struct,clang,scoping

As others mentioned, you're reading an uninitialized local variable and that's undefined. So, anything is legit. Having said that, there is a particular reason for this behavior: gcc reuses variables on the stack as much as it can (i.e., as long as the generated code is provably correct). You can...

Atomic/not-atomic mix, any guarantees?

c++,multithreading,c++11,atomic

As long as your used memory order is at least acquire/release (which is the default), you are guaranteed to see all updates (not just the ones to atomic variables) the writing thread did before setting the flag to true as soon as you can read the write. So yes, this...

How can I simulate a nested function without lambda expressions in C++11?

c++,function,c++11,lambda,allegro

Simply put the image inside the visual_plot function and make it static: void visual_plot() { static Image img("sample.png"); x.draw(); // Problem. } This will initialize img the first time visual_plot is called, and only then. This will solve both the performance problem and the "it must be initialized after app.run()"...

Sorting vector of Pointers of Custom Class

c++,sorting,c++11,vector

The only error that I see is this>current_generation_.end() instead that ->. In addition you should consider declaring your compare fuction as accepting two const FPGA* instead that just FPGA*. This will force you to declare fitness() as const int fitness() const but it makes sense to have it const. Mind...

Native Code: cannot use typeid with -fno-rtti

c++,osx,gcc,android-ndk,vtk

To enable C++ in the NDK, add LOCAL_CPP_FEATURES := rtti exceptions and LOCAL_CPPFLAGS += --std=c++11 to the jni/Android.mk file. By default, the NDK supports only a C++-like language. Note that there's no underscore between CPP and FLAGS. Also, I've used += because this won't overwrite other flags such as -Wall....

C++ operator []

c++,c++11,operator-overloading

C++ does not easily allow distinction of appple[2] = X; y=apple[2]; The most common solution is to return a proxy object: struct AppleProxy { Security & obj; unsigned index; AppleProxy(Security &, unsigned) : ... {} operator double() // your getter { return obj.GetAt(index); } operator=(double rhs) { obj.SetAt(index, rhs); }...

How to have gcc warn about conversions from uint32_t to uint64_t?

c++,gcc,compiler-warnings

There is nothing wrong with that conversion because the a uint32_t being converted to a uint64_t will not alter the value: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wconversion-499 #include <iostream> #include <cstdint> int main(int argc, char *argv[]) { std::uint32_t i = 1; std::uint64_t j = 1; // warning: conversion to 'uint32_t {aka unsigned int}' from 'uint64_t...

syntax for calling a method on a member with multiple instances

c++11,inheritance,c++14

Just use a class name qualifier like you usually would: h.helper<int>::t.test(); It's bizarre syntax, to be sure, but it is no different from writing foo.Base::member to access a hidden base class member from a derived class instance....

No match for 'operator*' error

c++,c++11

As @101010 hints at: pay is a string, while hours_day is a float, and while some languages allow you to multiply strings with integers, c++11 (or any other flavor of c) doesn't, much less allow strings and floats to be multiplied together.

std::push_heap and std::pop_heap with MoveConstructible objects

c++,c++11,stl,heap,move-semantics

Never mark your copy constructor or move constructor as explicit. It isn't illegal. It is just unusual enough to be confusing. There is no benefit to it, and only downside. The explicit on your move constructor is the cause of this error....

fatal error: limits.h: No such file or directory

xcode,osx,gcc

Make sure you've installed the xcode command-line tools: xcode-select --install (Accept the pop-up dialog.) That will install system headers into standard locations expected by tools like gcc, e.g. /usr/include....

Calling variadic template function with no args failing

c++,c++11

You have to specify a version of the function without args: #include <iostream> template <typename... Args> void foo(Args&&... bargs, Args&&... aargs) { std::cout << "Hello with args" << std::endl; } void foo() { std::cout << "Hello without args" << std::endl; } int main() { foo<int, double>(1, 2.0, 3, 4.0); //OK...

Dereferencing a temporary unique_ptr

c++,c++11,unique-ptr

The unique_ptr will pass the ownership to another unique_ptr, but in your code there is nothing to capture the ownership from the returning pointer. In other words, It can not transfer the ownership, so it will be destructed. The proper way is: unique_ptr<A> rA = myFun(); // Pass the ownership...

Passing something as this argument discards qualifiers

c++,c++11

There are no operator[] of std::map which is const, you have to use at or find: template<> struct Record::getDispatcher<std::string> { static std::string impl(Record const& rec, std::string& const field) { return rec.fieldValues_.at(field); // throw if field is not in map. } }; or template<> struct Record::getDispatcher<std::string> { static std::string impl(Record const&...

Tell C++ that pointer data is 16 byte aligned

c++,gcc,sse,memory-alignment

The compiler isn't vectorizing the loop because it can't determine that the dynamically allocated pointers don't alias each other. A simple way to allow your sample code to be vectorized is to pass the --param vect-max-version-for-alias-checks=1000 option. This will allow the compiler to emit all the checks necessary to see...

Django MySQLClient pip compile failure on Linux

python,linux,django,gcc,pip

It looks like you're missing zlib; you'll want to install it: apt-get install zlib1g-dev I also suggest reading over the README and confirming you have all other dependencies met: https://github.com/dccmx/mysqldb/blob/master/README Also, I suggest using mysqlclient over MySQLdb as its a fork of MySQLdb and what Django recommends....

Why is the boolean value within a structure within a vector not being updated?

c++,c++11

This: auto student_to_check = *it; declares a local variable that is a copy of the structure in the vector. The iterator points to the structure in the vector, so you can use: auto student_to_check = it; and: student_to_check->disabled = true; or more simply the following to access anything in the...

ARM assembly cannot use immediate values and ADDS/ADCS together

gcc,assembly,arm,instructions

Somewhat ironically, by using UAL syntax to solve the first problem you've now hit pretty much the same thing, but the other way round and with a rather more cryptic symptom. The only Thumb encodings for (non-flag-setting) mov with an immediate operand are 32-bit ones, however Cortex-M0 doesn't support those,...

How to check which symbols on my shared library have non-position independent code (PIC)?

linux,gcc,debian,powerpc

To find which symbols made your elf non-PIC/PIE (Position Independent Code/Executable), use scanelf from pax-utils package (on ubuntu, install it with sudo apt-get install pax-utils): $ scanelf -qT /usr/local/lib/libluajit-5.1.so.2.1.0 | head -n 3 libluajit-5.1.so.2.1.0: buf_grow [0x7694] in (optimized out: previous lj_BC_MODVN) [0x7600] libluajit-5.1.so.2.1.0: buf_grow [0x769C] in (optimized out: previous lj_BC_MODVN)...