I’m trying to create own map over unordered_map, but I’m having problems when compiling this using nvcc.
//foo.h
#include <iostream>
#include <tr1/unordered_map>
using std::string;
using std::tr1::unordered_map;
class MyMap: public unordered_map< string, int > {
public:
void myAdd( string, int );
void myRemove( string );
private:
int adds, removes;
};
//foo.cc
#include <foo.h>
void MyMap::myAdd( string key, int value)
{
operator[]( key ) = value;
adds++; // Just to have some reason to make own function
}
void MyMap::myRemove( string key)
{
erase( find( key ) );
removes++; // Just to have some reason to make own function
}
//test.cu or test.cc
#include <foo.h>
using std::cout;
using std::endl;
int main( void )
{
MyMap myMap;
myMap.myAdd("test0", 0);
myMap.myAdd("test1", 1);
myMap.myAdd("test2", 2);
myMap.myRemove("test1");
cout << myMap.size() << endl;
}
if the last one is named test.cc I have no problem compiling
$ nvcc -I. test.cc foo.cc -o test.out
I would like to call cuda kernel from the same function where I’m using this container, so I have named the file as test.cu.
I’m expecting that nvcc would splits the code to device and host codes and this all should be still compiled with g++, but I’m getting this error
$ nvcc -I. test.cu foo.cc -o b.out
/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/tr1/hashtable(1041): error: too few template parameters -- does not match previous declaration
detected during:
instantiation of class "std::tr1::hashtable<Key, Value, Allocator, ExtractKey, Equal, H1, H2, H, RehashPolicy, cache_hash_code, constant_iterators, unique_keys> [with Key=std::string, Value=std::pair<const std::string, int>, Allocator=std::allocator<std::pair<const std::string, int>>, ExtractKey=Internal::extract1st<std::pair<const std::string, int>>, Equal=std::equal_to<std::string>, H1=std::tr1::hash<std::string>, H2=Internal::mod_range_hashing, H=Internal::default_ranged_hash, RehashPolicy=Internal::prime_rehash_policy, cache_hash_code=false, constant_iterators=false, unique_keys=true]"
/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/tr1/unordered_map(58): here
instantiation of class "std::tr1::unordered_map<Key, T, Hash, Pred, Alloc, cache_hash_code> [with Key=std::string, T=int, Hash=std::tr1::hash<std::string>, Pred=std::equal_to<std::string>, Alloc=std::allocator<std::pair<const std::string, int>>, cache_hash_code=false]"
./foo.h(8): here
1 error detected in the compilation of "/tmp/tmpxft_0000401a_00000000-4_test.cpp1.ii"
.
The basic system info:
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2009 NVIDIA Corporation
Built on Thu_Apr__9_05:05:52_PDT_2009
Cuda compilation tools, release 2.2, V0.2.1221
$ g++ --version
g++ (GCC) 4.1.2 (Gentoo 4.1.2 p1.0.2)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ uname -a
Linux noname 2.6.25-gentoo-r7 #5 SMP Wed Dec 10 00:37:51 JST 2008 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 6000+ AuthenticAMD GNU/Linux
Any ideas and comments are appreciated.