I am using the CUB device function just like the example here (https://forums.developer.nvidia.com/t/cub-library/37675/2). I was able to compile the .cu source file in the above example using nvcc.
However, I wonder if it is possible to call CUB device function in .cpp source file and compile the .cpp source file (using nvcc or g++)? I know its possible for thrust, since the example here works for me.
Currently I simply move the main function into a new main.cpp file and include the cub header file in main.cpp, but I failed to compile it using nvcc or g++ because of the same errors, part of the error message:
/home/xx/cub/cub/block/specializations/../../block/../util_type.cuh:261:5: error: ‘__host__’ does not name a type; did you mean ‘__loff_t’?
__host__ __device__ __forceinline__ NullType& operator =(const T&) { return *this; }
^~~~~~~~
__loff_t
/home/xx/cub/cub/block/specializations/../../block/../util_type.cuh:316:19: error: ‘short4’ was not declared in this scope
__CUB_ALIGN_BYTES(short4, 8)
^
/home/xx/cub/cub/block/specializations/../../block/../util_type.cuh:314:52: error: ISO C++ forbids declaration of ‘__align__’ with no type [-fpermissive]
{ enum { ALIGN_BYTES = b }; typedef __align__(b) t Type; };
^
/home/xx/cub/cub/block/specializations/../../block/../util_type.cuh:545:9: error: ‘__host__’ does not name a type; did you mean ‘__loff_t’?
__host__ __device__ __forceinline__ CubVector operator+(const CubVector &other) const { \
^
/home/xx/cub/cub/block/specializations/../../block/../util_arch.cuh:64:38: error: ‘__host__’ does not name a type; did you mean ‘CUhostFn’?
#define CUB_RUNTIME_FUNCTION __host__ __device__
^
/home/xx/cub/cub/device/../iterator/arg_index_input_iterator.cuh:144:25: error: ‘__forceinline__’ does not name a type; did you mean ‘__thrust_forceinline__’?
__host__ __device__ __forceinline__ ArgIndexInputIterator(
^~~~~~~~~~~~~~~
__thrust_forceinline__
/home/xx/cub/cub/device/device_reduce.cuh:148:12: error: ‘cudaError_t’ does not name a type; did you mean ‘cudaError_enum’?
static cudaError_t Reduce(
^~~~~~~~~~~
cudaError_enum
Here are my source files:
device.h
#pragma once
#include <cub/cub.cuh>
void scan_on_device();
device.cu
#include "device.h"
void scan_on_device()
{
// Declare, allocate, and initialize device pointers for input and output
int num_items = 7;
int *d_in;
int h_in[] = {8, 6, 7, 5, 3, 0, 9};
int sz = sizeof(h_in)/sizeof(h_in[0]);
int *d_out; // e.g., [ , , , , , , ]
cudaMalloc(&d_in, sz*sizeof(h_in[0]));
cudaMalloc(&d_out, sz*sizeof(h_in[0]));
cudaMemcpy(d_in, h_in, sz*sizeof(h_in[0]), cudaMemcpyHostToDevice);
printf("\nInput:\n");
for (int i = 0; i < sz; i++) printf("%d ", h_in[I]);
// Determine temporary device storage requirements
void *d_temp_storage = NULL;
size_t temp_storage_bytes = 0;
cub::DeviceScan::InclusiveSum(d_temp_storage, temp_storage_bytes, d_in, d_out, num_items);
// Allocate temporary storage
cudaMalloc(&d_temp_storage, temp_storage_bytes);
// Run inclusive prefix sum
cub::DeviceScan::InclusiveSum(d_temp_storage, temp_storage_bytes, d_in, d_out, num_items);
// d_out s<-- [8, 14, 21, 26, 29, 29, 38]
cudaMemcpy(h_in, d_out, sz*sizeof(h_in[0]), cudaMemcpyDeviceToHost);
printf("\nOutput:\n");
for (int i = 0; i < sz; i++) printf("%d ", h_in[i]);
printf("\n");
}
host.cpp
#include "device.h"
#include <cub/cub.cuh>
int main(void)
{
scan_on_device();
return 0;
}
I tried to compile them in three steps:
nvcc -O2 -c device.cu -I/home/xx/cub
g++ -O2 -c host.cpp -I/usr/local/cuda/include/ -I/home/xx/cub
g++ -o tester device.o host.o -L/usr/local/cuda/lib64 -lcudart
The first step went well, but the second step gives the above errors. Any ideas are appreciated. Maybe I mess up some links (to cuda or cub)?
The cub header library (e.g. cub.cuh) contains CUDA C++ code. Such code cannot be compiled by an ordinary host compiler like g++. You will get compile errors if you try to do so.
However your project doesn't require cub.cuh to be in your device.h header file, nor does it require cub.cuh to be compiled by g++. The only thing needed in your device.h header file is the function prototype for scan_on_device().
Therefore if you include the cub header file in the function implementation file device.cu, and remove it elsewhere in your project, your code will compile.
Related
I'm trying to write a function that embeds the Octave interpreter in C++, as described here https://octave.org/doc/v4.0.1/Standalone-Programs.html .
I'm trying to do this from a program that I'm writing in Eclipse, and trying to compile with GCC on Linux. I want to be able to call an external script, as in the second example in the link.
My code so far looks like this.....
#include <iostream>
#include <oct.h>
#include <octave.h>
#include <parse.h>
#include <interpreter.h>
using namespace std;
class OctaveInt {
public:
void callOctave (double, int, string);
OctaveInt(string path );
private:
octave::interpreter interpreter;
};
// Member functions including constructor..
OctaveInt::OctaveInt(string path)
{
// Constructor - initialises engine and sets path
int status = interpreter.execute();
octave_value_list p;
p(0) = path;
octave_value_list o1 = octave::feval ("addpath", p);
}
void OctaveInt::callOctave(double params, int size, string name) {
std::cout << "Hello World" << std::endl;
int n = 2;
octave_value_list in;
octave_value_list p;
for (octave_idx_type i=0; i < size; i++)
in(i) = octave_value(params[i]);
octave_value_list out = octave::feval (name, in);
std::cout << "Output is ";
std::cout << out(0).int_value();
}
int main() {
double params[] = {100, 2, 3, 4, 5, 6};
int size = 6;
string path = "/home/arwel/eclipseWorkspace_new/octaveCaller/src/";
OctaveInt octI(path);
octI.callOctave(params, size, "myFunction");
return 0;
}
When I try to compile however, I get a series of errors.....
Invoking: GCC C++ Compiler
g++ -std=c++0x -I/usr/include/octave-5.2.0/octave/ -I/usr/share/octave/5.2.0/etc/tests -I/usr/lib/x86_64-redhat-linux6E -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/octaveCaller.d" -MT"src/octaveCaller.o" -o "src/octaveCaller.o" "../src/octaveCaller.cpp"
../src/octaveCaller.cpp: In constructor ‘OctaveInt::OctaveInt(std::string)’:
../src/octaveCaller.cpp:31:6: warning: unused variable ‘status’ [-Wunused-variable]
int status = interpreter.execute();
^
../src/octaveCaller.cpp: In member function ‘void OctaveInt::callOctave(double, int, std::string)’:
../src/octaveCaller.cpp:48:32: error: invalid types ‘double[octave_idx_type {aka long int}]’ for array subscript
in(i) = octave_value(params[i]);
^
../src/octaveCaller.cpp:42:6: warning: unused variable ‘n’ [-Wunused-variable]
int n = 2;
^
../src/octaveCaller.cpp: In function ‘int main()’:
../src/octaveCaller.cpp:65:44: error: no matching function for call to ‘OctaveInt::callOctave(double [6], int&, const char [11])’
octI.callOctave(params, size, "myFunction");
^
../src/octaveCaller.cpp:65:44: note: candidate is:
../src/octaveCaller.cpp:38:6: note: void OctaveInt::callOctave(double, int, std::string)
void OctaveInt::callOctave(double params, int size, string name) {
^
../src/octaveCaller.cpp:38:6: note: no known conversion for argument 1 from ‘double [6]’ to ‘double’
make: *** [src/octaveCaller.o] Error 1
"make all" terminated with exit code 2. Build might be incomplete.
12:41:36 Build Failed. 3 errors, 2 warnings. (took 1s.927ms)
So it looks like I have some problems with types of variables (??).
I don't really know much C++, so I'm undoubtedly doing some basic C++ mistake. Can someone give me a hand to figure out what I'm doing wrong?
I am currently porting some code from Matlab to Octave. Some of the functions of the Matlab code use the Piotr's Computer Vision Matlab Toolbox (here) that includes some mex files.
In Matlab, everything is working like a charm but when I run my codes with Octave, it throws this error:
error: 'imResampleMex' undefined near line 50 column 5
However all the internal paths within the toolbox should be good. I figured out that the way Matlab and Octave handle mex files is different and tried to build one of the mex files from the C++ function within Octave like this:
mkoctfile --mex imResampleMex.cpp
It fails and throws the following error messages related to the C++ wrappers function:
In file included from imResampleMex.cpp:6:0:
wrappers.hpp:21:24: error: 'wrCalloc' declared as an 'inline' variable
inline void* wrCalloc( size_t num, size_t size ) { return calloc(num,size);
^
wrappers.hpp:21:24: error: 'size_t' was not declared in this scope
wrappers.hpp:21:36: error: 'size_t' was not declared in this scope
inline void* wrCalloc( size_t num, size_t size ) { return calloc(num,size);
^
wrappers.hpp:21:48: error: expression list treated as compound expression in initializer [-fpermissive]
inline void* wrCalloc( size_t num, size_t size ) { return calloc(num,size);
^
wrappers.hpp:21:50: error: expected ',' or ';' before '{' token
inline void* wrCalloc( size_t num, size_t size ) { return calloc(num,size);
^
wrappers.hpp:22:24: error: 'wrMalloc' declared as an 'inline' variable
inline void* wrMalloc( size_t size ) { return malloc(size); }
^
wrappers.hpp:22:24: error: 'size_t' was not declared in this scope
wrappers.hpp:22:38: error: expected ',' or ';' before '{' token
inline void* wrMalloc( size_t size ) { return malloc(size); }
^
wrappers.hpp: In function 'void wrFree(void*)':
wrappers.hpp:23:44: error: 'free' was not declared in this scope
inline void wrFree( void * ptr ) { free(ptr); }
^
wrappers.hpp: At global scope:
wrappers.hpp:28:17: error: 'size_t' was not declared in this scope
void* alMalloc( size_t size, int alignment ) {
^
wrappers.hpp:28:30: error: expected primary-expression before 'int'
void* alMalloc( size_t size, int alignment ) {
^
wrappers.hpp:28:44: error: expression list treated as compound expression in initializer [-fpermissive]
void* alMalloc( size_t size, int alignment ) {
^
wrappers.hpp:28:46: error: expected ',' or ';' before '{' token
void* alMalloc( size_t size, int alignment ) {
^
imResampleMex.cpp: In function 'void resampleCoef(int, int, int&, int*&, int*&, T*&, int*, int)':
imResampleMex.cpp:21:39: error: 'alMalloc' cannot be used as a function
wts = (T*)alMalloc(nMax*sizeof(T),16);
^
imResampleMex.cpp:22:43: error: 'alMalloc' cannot be used as a function
yas = (int*)alMalloc(nMax*sizeof(int),16);
^
imResampleMex.cpp:23:43: error: 'alMalloc' cannot be used as a function
ybs = (int*)alMalloc(nMax*sizeof(int),16);
^
imResampleMex.cpp: In function 'void resample(T*, T*, int, int, int, int, int, T)':
imResampleMex.cpp:48:43: error: 'alMalloc' cannot be used as a function
T *C = (T*) alMalloc((ha+4)*sizeof(T),16); for(y=ha; y<ha+4; y++) C[y]=0;
^
warning: mkoctfile: building exited with failure status
The wrappers.hpp file is looking like this:
#ifndef _WRAPPERS_HPP_
#define _WRAPPERS_HPP_
#ifdef MATLAB_MEX_FILE
// wrapper functions if compiling from Matlab
#include "mex.h"
inline void wrError(const char *errormsg) { mexErrMsgTxt(errormsg); }
inline void* wrCalloc( size_t num, size_t size ) { return mxCalloc(num,size); }
inline void* wrMalloc( size_t size ) { return mxMalloc(size); }
inline void wrFree( void * ptr ) { mxFree(ptr); }
#else
// wrapper functions if compiling from C/C++
inline void wrError(const char *errormsg) { throw errormsg; }
inline void* wrCalloc( size_t num, size_t size ) { return calloc(num,size); }
inline void* wrMalloc( size_t size ) { return malloc(size); }
inline void wrFree( void * ptr ) { free(ptr); }
#endif
// platform independent aligned memory allocation (see also alFree)
void* alMalloc( size_t size, int alignment ) {
const size_t pSize = sizeof(void*), a = alignment-1;
void *raw = wrMalloc(size + a + pSize);
void *aligned = (void*) (((size_t) raw + pSize + a) & ~a);
*(void**) ((size_t) aligned-pSize) = raw;
return aligned;
}
// platform independent alignned memory de-allocation (see also alMalloc)
void alFree(void* aligned) {
void* raw = *(void**)((char*)aligned-sizeof(void*));
wrFree(raw);
}
#endif
I imagine I need to modify this file but my knowledge of C++ and of mex files being close to non-existent, I am struggling figuring a way out of this mountain of errors. I don't even have a clue whether I'm going in the right direction or not... Any help is welcome!
Edit 1:
I modified my wrappers.hpp file adding #include <stdlib.h> to it. A mex file is now created. However, when running the function calling the file, I now get the following error:
error: failed to install .mex file function 'imResampleMex'
error: called from
imResample at line 50 column 4
Here are the steps I used to solve the issue of creating the mex files from the Piotr's Computer Vision Matlab Toolbox for Octave (concerns the cpp files of the folder channels only).
The original mex files that come with the toolbox are built for Matlab and do not work with Octave. While building them from Octave a call is made to the file wrappers.hpp.
This file has to be modified by adding these two lines at the beginning of the file: #include <stdlib.h> and #include "mex.h".
For building the mex file, in the Octave prompt type (while being in the directory of the cpp file):
mkoctfile --mex -DMATLAB_MEX_FILE the_file.cpp
This way the Octave compatible mex file is created.
Edit 23/05/2017 - After receiving more questions from people having trouble generating these files I released the generated files on Github: https://github.com/Eskapp/Piotr_vision_extrafiles_Octave. Feel free to use them.
You'll need to add them manually to the Computer Vision toolbox.
This question already has an answer here:
External calls are not supported - CUDA
(1 answer)
Closed 7 years ago.
I am trying to understand how to decouple CUDA __device__ codes in separate header files.
I have three files.
File: 1: int2.cuh
#ifndef INT2_H_
#define INT2_H_
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
__global__ void kernel();
__device__ int k2(int k);
int launchKernel(int dim);
#endif /* INT2_H_ */
File 2: int2.cu
#include "int2.cuh"
#include "cstdio"
__global__ void kernel() {
int tid = threadIdx.x;
printf("%d\n", k2(tid));
}
__device__ int k2(int i) {
return i * i;
}
int launchKernel(int dim) {
kernel<<<1, dim>>>();
cudaDeviceReset();
return 0;
}
File 3: CUDASample.cu
include <stdio.h>
#include <stdlib.h>
#include "int2.cuh"
#include "iostream"
using namespace std;
static const int WORK_SIZE = 256;
__global__ void sampleCuda() {
int tid = threadIdx.x;
// printf("%d\n", k2(tid)); //Can not call k2
printf("%d\n", tid * tid);
}
int main(void) {
int var;
var = launchKernel(16);
kernel<<<1, 16>>>();
cudaDeviceReset();
sampleCuda<<<1, 16>>>();
cudaDeviceReset();
return 0;
}
The code works fine. I can call the sampleCuda() kernel (in same file), call the C function launchKernel() (in other file), and call kernel() directly (in other file).
However, I get the following error when calling the __device__ function from the sampleCuda() kernel. The same function is callable in kernel().
10:58:11 **** Incremental Build of configuration Debug for project CUDASample ****
make all
Building file: ../src/CUDASample.cu
Invoking: NVCC Compiler
/Developer/NVIDIA/CUDA-6.5/bin/nvcc -G -g -O0 -gencode arch=compute_20,code=sm_20 -odir "src" -M -o "src/CUDASample.d" "../src/CUDASample.cu"
/Developer/NVIDIA/CUDA-6.5/bin/nvcc -G -g -O0 --compile --relocatable-device-code=false -gencode arch=compute_20,code=compute_20 -gencode arch=compute_20,code=sm_20 -x cu -o "src/CUDASample.o" "../src/CUDASample.cu"
../src/CUDASample.cu(18): warning: variable "var" was set but never used
../src/CUDASample.cu(8): warning: variable "WORK_SIZE" was declared but never referenced
../src/CUDASample.cu(18): warning: variable "var" was set but never used
../src/CUDASample.cu(8): warning: variable "WORK_SIZE" was declared but never referenced
ptxas fatal : Unresolved extern function '_Z2k2i'
make: *** [src/CUDASample.o] Error 255
10:58:14 Build Finished (took 2s.388ms)
How do I call the __device__ function from the sampleCuda() kernel ?
The issue is that you defined a __device__ function in separate compilation unit from __global__ that calls it. You need to either explicitely enable relocatable device code mode by adding -dc flag or move your definition to the same unit.
From nvcc documentation:
--device-c|-dc Compile each .c/.cc/.cpp/.cxx/.cu input file into an object file that contains relocatable device code. It is equivalent to
--relocatable-device-code=true --compile.
See Separate Compilation and Linking of CUDA C++ Device Code for more information.
I have to compile program probcons but there are many errors. In readme autor writes program is compatible with gcc 4.3 but I have only 4.7.2. Is there any way to compile this old program? I don't believe that in program are errors because many bioinformatics servers are using it.
Most odd to me is this error:
Description Resource Path Location Type
expected ‘)’ before ‘size’ SafeVector.h /probcons line 27 C/C++ Problem
expected ‘)’ before ‘size’ SafeVector.h /probcons line 26 C/C++ Problem
In class SafeVector.h:
/////////////////////////////////////////////////////////////////
// SafeVector.h
//
// STL vector with array bounds checking. To enable bounds
// checking, #define ENABLE_CHECKS.
/////////////////////////////////////////////////////////////////
#ifndef SAFEVECTOR_H
#define SAFEVECTOR_H
#include <cassert>
#include <vector>
/////////////////////////////////////////////////////////////////
// SafeVector
//
// Class derived from the STL std::vector for bounds checking.
/////////////////////////////////////////////////////////////////
template<class TYPE>
class SafeVector : public std::vector<TYPE>{
public:
// miscellaneous constructors
SafeVector() : std::vector<TYPE>() {}
/*ERROR HERE*/ SafeVector(size_t size) : std::vector<TYPE>(size) {}
/*ERROR HERE*/ SafeVector(size_t size, const TYPE &value) : std::vector<TYPE>(size, value) {}
SafeVector(const SafeVector &source) : std::vector<TYPE>(source) {}
#ifdef ENABLE_CHECKS
// [] array bounds checking
TYPE &operator[](int index){
assert (index >= 0 && index < (int) size());
return std::vector<TYPE>::operator[] ((size_t) index);
}
// [] const array bounds checking
const TYPE &operator[] (int index) const {
assert (index >= 0 && index < (int) size());
return std::vector<TYPE>::operator[] ((size_t) index) ;
}
#endif
};
How it is possible that in older version of gcc wasn't need includes and std::prefix?
Try specifying the language standard for gcc. I suggest you try
-std=c++11
e.g g++ -std=c++11 -o out.exe myfile.cpp
first, I think it is most likely to compile it. If it doesn't work, try other choices.
How to add this depends on how the compilation is done, but one "quick&dirty" way is to add this is to find the makefile, find a line which specifies compiler flags variable CXXFLAGS and add that to it. Note: if it is a generated makefile, edits get overwritten if you run the generator again.
I'm relatively new to C & C++ and stuck at compiling (or should I say linking) for the whole 2 days. Anyone gives me an idea would be appreciated.
Error message and 3 code files are below. These are what I cut down to minimum from I'm actually working on so that you guys can take a better glimpse at.
Env: Ubuntu 10.10, Eclipse Indigo CDT, g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5
Error message:
**** Build of configuration Debug for project SceneRec2 ****
make all
Building file: ../src/AdaBoost.cpp
Invoking: GCC C++ Compiler
g++ -I"/home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Includes" -I/usr/src/linux-headers-2.6.35-30/arch/um/include/shared -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/AdaBoost.d" -MT"src/AdaBoost.d" -o "src/AdaBoost.o" "../src/AdaBoost.cpp"
Finished building: ../src/AdaBoost.cpp
Building file: ../src/AdaMain.cpp
Invoking: GCC C++ Compiler
g++ -I"/home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Includes" -I/usr/src/linux-headers-2.6.35-30/arch/um/include/shared -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/AdaMain.d" -MT"src/AdaMain.d" -o "src/AdaMain.o" "../src/AdaMain.cpp"
../src/AdaMain.cpp: In function ‘int main(int, char**)’:
../src/AdaMain.cpp:6: warning: deprecated conversion from string constant to ‘char*’
Finished building: ../src/AdaMain.cpp
Building target: SceneRec2
Invoking: GCC C++ Linker
g++ -o "SceneRec2" ./src/AdaBoost.o ./src/AdaMain.o
./src/AdaMain.o: In function `main':
/home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Debug/../src/AdaMain.cpp:5: undefined reference to `AdaBoost<double>::AdaBoost()'
/home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Debug/../src/AdaMain.cpp:6: undefined reference to `AdaBoost<double>::readFromFile(char*)'
/home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Debug/../src/AdaMain.cpp:8: undefined reference to `AdaBoost<double>::~AdaBoost()'
/home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Debug/../src/AdaMain.cpp:8: undefined reference to `AdaBoost<double>::~AdaBoost()'
collect2: ld returned 1 exit status
make: *** [SceneRec2] Error 1
**** Build Finished ****
Note-1. I receive the same result when I execute g++ on terminal.
Note-2. The path of .o files in the argument for linker should be correct (./src/###.o).
AdaBoost.h
#ifndef _ADABOOST_H
#define _ADABOOST_H
#include <iostream>
const double eps = 2.2204e-16;
template<class T>
class AdaBoost
{
int N; //Number of Instances
int D; //Number of Dimensions
int nL; //Number of Learners / Classifiers / Rules
T** fVectors;
int* labels;
void learnRule(int t, double* dist);
double genRule(int t, int* L, double* dist);
public:
//Default Constructor
AdaBoost();
//Constructor
AdaBoost(T** data, int* labels, int n, int d, int nL);
//Train function
void train();
//Test function
void test(double** data, double* pMap);
void test(double** data, double* pMap, int n);
int writeToFile(char* fName);
int readFromFile(char* fName);
//Destructor
~AdaBoost();
};
#endif
AdaBoost.cpp
#include "AdaBoost.h"
#include <fstream>
using namespace std;
template class AdaBoost<double> ;
template<class T>
int AdaBoost<T>::readFromFile(char* fName) {
ifstream inFile;
int temp;
int d, dir;
float thr, wt;
inFile.open(fName);
if (!inFile)
return 0;
inFile >> temp;
this->nL = temp;
int k = 0;
while (!inFile.eof() && k < nL) {
inFile >> d;
inFile >> thr;
inFile >> dir;
inFile >> wt;
k++;
}
inFile.close();
return 1;
}
AdaMain.cpp
#include "AdaBoost.h"
using namespace std;
int main(int argc, char** argv)
{
AdaBoost<double> rdClass;
rdClass.readFromFile("Naerer");
return 0;
}
If you are using explicit instantiation, you have to define the generic version of the member function before instantiating the class:
template<class T>
int AdaBoost<T>::readFromFile(char* fName) {
// ...
}
template class AdaBoost<double>;
However, if you don't have a specific or pressing reason to use explicit instantiation in the first place, go with the other recommendations and define the templates in the header.
You cannot separate template class definition and implementation in different compilation units. In other words, AdaBoost<T> complete implementation should be linked in the same compilation unit that main (where it is used) is.
This is typically fixed by either #including the .cpp file at the end of your .hpp file (if you want to maintain them separate), or just using only the .hpp file implementing the whole class there.
You have multiple problems.
First, you use the unconventional technique of explicit instantiation in a CPP file. As others have pointed out, convention (but nothing more) requires that you put the implementation in the .H file to allow for generic instantiation. You don't have to do this, but if you did, the readfile() error would go away. (As an alternative, put your AdaBoost<double> instantiation after the definition of AdaBoost::readfile.)
Next, you have declared, but not defined, your constructor and destructor. If you wish to use the compiler-provided constructor and destructor you should delete the declarations. If you wish to use your own constructor and dstructor, you should define them.
Best practice is to get rid of AdaBoost.cpp, and modify AdaBoost.h to include the implementation inline in the header. (Note that this best practice is for templated classes; other advice may apply to non-templated classes.)
You need to put the definition of template<class T>
int AdaBoost<T>::readFromFile(char* fName) into AdaBoost.h, and remove AdaBoost.cpp from your build.
It's best to put all template code into the header. C++ linkers are required to eliminate duplicate instantiations of template code so you won't get "multiply defined symbol" errors.
P.S. You should declare the function as template<class T>
int AdaBoost<T>::readFromFile(const char* fName) to get rid of the deprecated conversion from string constant to ‘char*’ warning. The function does not need to alter the filename.