ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

random crash

Open Subarukun opened this issue 9 years ago • 12 comments

Hi, we have implemented Alexnet for ARM-NEON to run it on raspberrypi 3 using the v17.06 armcompute library. When we feed the input data continuously after some 40-50 inputs system is hangingand sometimes showing segmentation fault .

This issue is very random and it occurs once for 5 runs. This issue is NOT observed with v17.05. Could you confirm this and provide any suggestion/fix.

Thanks

Subarukun avatar Jul 06 '17 12:07 Subarukun

There is nothing we can do with so little information. Have you tried running our version of AlexNet ? We've successfully run it on a selection of devices and haven't observed any issue.

AnthonyBarbier avatar Jul 06 '17 12:07 AnthonyBarbier

I have used ComputeLibrary-master/tests/model_objects/AlexNet.h and used a wrapper as below , then created alexnet app .

main()
{
using NEAlexNetModel = model_objects::AlexNet<ITensor,
      Tensor,
      SubTensor,
      NEAccessor,
      NEActivationLayer,
      NEConvolutionLayer,
      NEFullyConnectedLayer,
      NENormalizationLayer,
      NEPoolingLayer,
      NESoftmaxLayer>;

    NEAlexNetModel network{};
    network.init_weights(1,false);
    network.build();
    network.allocate();
    network.fill();
    int counter=0;
    unsigned int output;
    while(1)
    {
		network.run();
		output = network.get_classifications();
		printf("frame:%d Alexnet output %d\n",counter++,output);
    }

}

I have written a fill() function in AlexNet,h for filling the weights and input ,returned the output (unsigned int)classified_labels[0] from the get_classifications function in AlexNet.h.

When I run the code for same image input ,we are getting the classified output as zero randomly ,rest all the cases output is fine.

Attaching screen shot of the output. Please let me know if you need any further info 20170710_151323

Note: 1)We have built the library with cppthreads enabled and openmp disabled.This test setup was run on raspberrypi3 . 2)Same setup is running fine with proper outputs and no random zeros when we built the library with cppthreads and openmp both disabled .

Subarukun avatar Jul 11 '17 09:07 Subarukun

Hello @Subarukun, Do you still have this issue? If yes can you please provide us with the filling function that you wrote so that we can have a look? Thank you in advance.

GeorgeARM avatar Jul 12 '17 13:07 GeorgeARM

Yes issue is still present for rpi3.Below is the tensor filling code.

   void fill_tensor(int layer)
	{
		float *ptr;
		int i;
		FILE *fp;
		char filename[500];
		sprintf(filename,"taps/tap_%d.bin",layer*2);
		fp = fopen(filename,"rb");
		ptr = (float*)w[layer]->buffer();
		i=0;
		while(!feof(fp))
		{
			fread(ptr,sizeof(float),1,fp);
			//printf("a[%d] = %f\n",i,*ptr);
			ptr++;
			i++;
		}
		printf("total size :%d read size:%d\n",w[layer]->info()->total_size()/4,i);
		sprintf(filename,"taps/tap_%d.bin",layer*2+1);
		fp = fopen(filename,"rb");
		ptr = (float*)b[layer]->buffer();
		i=0;
		while(!feof(fp))
		{
			fread(ptr,sizeof(float),1,fp);
			//printf("a[%d] = %f\n",i,*ptr);
			ptr++;
			i++;
		}
		fclose(fp);
		printf("total size :%d read size:%d\n",b[layer]->info()->total_size()/4,i);
		
	}
	void fill()
	{
		fill_tensor(0);
		fill_tensor(1);
		fill_tensor(2);
		fill_tensor(3);
		fill_tensor(4);
		fill_tensor(5);
		fill_tensor(6);
		fill_tensor(7);
		
		FILE* fp = fopen("dog.rgb", "rb");
			//FILE* fp = fopen("laska.rgb", "rb");
		if (fp == 0)  {
			//printf("Unable to open file %s\n", fileName.c_str());
			printf("Unable to open file \n");
		}
		float* input1 =(float*)input.buffer();
		float *temp = (float *) malloc (227*227*3*sizeof (float));
		unsigned char c;
		for(int i=0; i<227*227*3; i++)
		{
			int retVal = fread(&c, 1, sizeof(unsigned char), fp);
			if(retVal != (size_t) 1)
			   printf("readData - File read Failed\n");
			
			temp[i]=(float) (c);
		}
		for(int j=0;j<227*227;j++)
		{		
			input1[0*227*227+j]=(float) (temp[j*3+0]);
			input1[1*227*227+j]=(float) (temp[j*3+1]);
			input1[2*227*227+j]=(float) (temp[j*3+2]);
		}	
		fclose(fp);		
		free(temp);
	}

tap0,tap2... correspond to weights and tap1,tap3... correspond to biases.

Subarukun avatar Jul 13 '17 05:07 Subarukun

You're not taking into account the padding of the buffer

You have an example of how to fill a tensor in the documentation

You can also have a look at the PPM loader which is provided with the examples

AnthonyBarbier avatar Jul 13 '17 09:07 AnthonyBarbier

Thanks for pointing out . There is no padding done for weights,bias,input.

I have confirmed the above statement by printing the w[0]->info()->total_size() for all the weights,biases and inputs after allocate .There is no padding for weights,bias,input tensor.

So padding couldn't be the issue . As I have already mentioned in the query when cpp_threads is disabled everything works fine.

Let me know if any more info needed

Subarukun avatar Jul 13 '17 10:07 Subarukun

I don't have a rpi3, but I've tried on a different device (Samsung Chromebook2) and it works fine for me: I ran the network in a loop for 10 000 iterations, there is no variation in memory from one iteration to the other. (It does require ~600MB of memory though)

Can you try with openmp=1 and cpptheads=0 ? Also, could you try to set a different number of threads to see if it changes anything ?

AnthonyBarbier avatar Jul 13 '17 17:07 AnthonyBarbier

Below are the observatrions for different permutations and combinations .

cpp disable openmp disable :: No issue until 200 iterations cpp enable openmp disable :: output does not match right from start. cpp enable openmp enable :: Issue is present but not that frequent as above. once in 200 cpp disable openmp enable :: No issue until 200 iterations

Subarukun avatar Jul 19 '17 12:07 Subarukun

we have proceeded with cpp disable openmp enable. The performance and stability seems to be ok. what will be the impact of disabling cppthreads? what is its intended purpose ? could you explain..

Subarukun avatar Jul 28 '17 11:07 Subarukun

We still haven't managed to reproduce the issue on our end, so not sure what it could be.

cppthreads and openmp are just two different ways of multi-threading the code: In cppthreads we're using a pool of threads whereas in the OpenMP scheduler we let OpenMP manage the pool of threads. That's the only difference between the two. When you compile with both cppthreads and openmp enabled by default cppthreads will be used (Unless you change the scheduler explicitly by calling Scheduler::set())

AnthonyBarbier avatar Jul 28 '17 13:07 AnthonyBarbier

Thanks for info.

Subarukun avatar Jul 31 '17 10:07 Subarukun

Issue has been resolved on raspberry pi with the latest release or arm compute library

Subarukun avatar Feb 12 '18 07:02 Subarukun