CUDA Error : identifier is undefined

Hi,
I been struggling for hours to figure out what is wrong. It says the Class “Neuron” is undefined in SynapseH.cu, but it is included right at the top. I’m using VS2013, and a CUDA v7.5 Project. Is it the fact that their are “Neuron” object pointers in SynapseH.cu, along with “Synapse” object pointers in NeuronH.cu??

Here is the Error:
error : identifier “Neuron” is undefined in SynapseH.cu

Thank you for the help,
Andrew

SynapseH.cu :

#ifndef SYNAPSEH_CU
#define SYNAPSEH_CU

#include "cuda_runtime.h"
#include "NeuronH.cu"
using namespace std;

#ifndef CUDA_CALLABLE_MEMBER
#define CUDA_CALLABLE_MEMBER __host__ __device__
#endif

class Synapse
{
public:
	// Foward Prop.
	double _weight;
	// Back Prop.
	double _weightDelta;
	//
	Neuron* _outputNeuron;          // This is the Line where the Error occured
	Neuron* _inputNeuron;

	// Constructor
	CUDA_CALLABLE_MEMBER Synapse();
	// Destructor
	CUDA_CALLABLE_MEMBER ~Synapse();
};

#endif

NeuronH.cu :

#ifndef NEURONH_CU
#define NEURONH_CU

#include "cuda_runtime.h"
#include "SynapseH.cu"
#include "ActivationFuncsH.cu"
using namespace std;

#ifndef CUDA_CALLABLE_MEMBER
#define CUDA_CALLABLE_MEMBER __host__ __device__
#endif

class Neuron
{
public:
	typedef Synapse* SynapsePtr;
	// Ctr For Neuron in Network
	int _neuronCtr;
	// Output & Inputs Synapses
	Synapse* _outputSynapses;
	SynapsePtr* _inputSynapses = nullptr;
	int _outputSynapsesLen, _inputSynapsesLen;
	// Neuron Weights
	double m_bias;
	double _biasDelta;
	// Input
	double _input;
	// Output
	double m_output;
	// BackProp: Gradiant
	double _gradiant;
	// Ptr ActivationFunc

private:
	ActivationFunc* _actvFunc = nullptr;

public:

	// Constuctor
	CUDA_CALLABLE_MEMBER Neuron();
	// Destructor
	CUDA_CALLABLE_MEMBER ~Neuron();

	// Creates Construct
	CUDA_CALLABLE_MEMBER void createNeuron(int numNeuronsNextLayer);

	// Setters
	// Sets Output & Weighted Output (m_wtdOutput)
	CUDA_CALLABLE_MEMBER void setOutput(double output) { m_output = output; }
	// Ini. / Puts together _inputSynapse*[]
	CUDA_CALLABLE_MEMBER void iniInputSynapse(int numInputSynapse);
	// Save the Pointer to the ActivationFunc.
	CUDA_CALLABLE_MEMBER void Neuron::setActvFunc(ActivationFunc* actvFunc);

	// Gets the Output Multiplied by the Weights
	// <param name="NeuronIdx">The index of the Neuron at the Layer being Calc. 
        // Wants the Synapse info to put in its Input.</param>
	// <returns>Synapse Output from the NeuronIdx</returns>
	CUDA_CALLABLE_MEMBER double getSynapseOutput(int NeuronIdx);

	// BackProp: Calc Error
	CUDA_CALLABLE_MEMBER double calcError(double* target);
};

#endif
1 Like

Hi Andrew (a.k.a. supracharger),
I am new to CUDA & VisualStudio, but I see you including .cu files, but I was taught that .h files should be included and .cu files are linked.
But never mind that, the problem starts at the first line of NeuronH.cu.
When NeuronH.cu compiles it defines (line 2) NEURONH_CU, then includes (line 5) SynapseH.cu.
…When SynapseH.cu is included, at line 5 it tries to include NeuronH.cu, but since NEURONH_CU is defined nothing is included.
…Then in SynapsesH.cu (Line20) declares _outputNuron as a pointer to Neuron, which is not yet defined.

I believe the problem is that your definitions are dependent on each other.

It has been a while since I programmed in C++ so I don’t know how to get around the problem of dependent definitions.

I think you will have to create Parent Virtual classes for ‘synapase’ and ‘neuron’ without the dependency.
For now call these classes ‘SynapseVC’ and ‘NeuronVC’
Then your definitions (class statements) for for Neuron and Synapse would define variables to these Parent Virtual classes.
your Neuron class will inherent from NeuronVC and your Synapse class will inherent from SynapaseVC.

I suspect that you might be a Python programmer as the code you created might be valid there, but not here?

I hope this helps.

Chuck

OOPS I mis-spoke, please consider my use of the term ‘definitions’ incorrect, I should have used the term ‘decelerations’.

So the line should read:
… “I believe the problem is that your decelerations are dependent on each other.”

circular inclusion.

replace

#include "NeuronH.cu"

with:

class Neuron;

Thanks for the support guys!

Chuck, thank you for a good explaination to what is happening, and I’m not a Python coder, but going back to C++ from C# mainly.

episteme, thank you for the easier fix.

The file “NeuronH.cu” was suppose to be the header file since I can’t use the .h extension because it needs to run through the CUDA compiler. However, I figured out that .cuh extension is for a CUDA header file.

I found that using the quick class declaration with the include the header file worked best because I was getting empty class errors.
So:

class Neuron;
#include "Neuron.cuh"    // Changed Ext.
  • Andrew