 	CUDA_SAFE_CALL(cudaMalloc((void**) &device_MatrixCA.elements, m_size(MatrixCA)));
 	CUDA_SAFE_CALL(cudaMemcpy(device_MatrixCA.elements, MatrixCA.elements, m_size(MatrixCA), cudaMemcpyHostToDevice));
 
-	CUDA_SAFE_CALL(cudaMalloc((void**) &device_output_chunk.elements, m_size(output_chunk)));
-	CUDA_SAFE_CALL(cudaMemcpy(device_output_chunk.elements, output_chunk.elements, m_size(output_chunk), cudaMemcpyHostToDevice));
+	CUDA_SAFE_CALL(cudaMalloc((void**) &device_output_chunk_read.elements, m_size(output_chunk)));
+	CUDA_SAFE_CALL(cudaMemcpy(device_output_chunk_read.elements, output_chunk.elements, m_size(output_chunk), cudaMemcpyHostToDevice));
+
+	CUDA_SAFE_CALL(cudaMalloc((void**) &device_output_chunk_write.elements, m_size(output_chunk)));
+	CUDA_SAFE_CALL(cudaMemcpy(device_output_chunk_write.elements, output_chunk.elements, m_size(output_chunk), cudaMemcpyHostToDevice));
 
 	CUDA_SAFE_CALL(cudaMalloc((void**) &device_state_read.elements, m_size(state)));
 	CUDA_SAFE_CALL(cudaMemcpy(device_state_read.elements, state.elements, m_size(state), cudaMemcpyHostToDevice));

	       	 * CUDA IMPLEMENTATION
		 */

		MatrixMultiplyKernel<<<dimGridCA, dimBlockCA>>>(device_MatrixCA, device_state_read, device_output_chunk);

		cudaDeviceSynchronize();	
		cudaMemcpy(output_chunk.elements, device_output_chunk.elements, m_size(output_chunk), cudaMemcpyDeviceToHost);

		for(j = 0; j < blocksize; j++) {
			output[i+j] = m_get(output_chunk,j,0)/128;
		}
		MatrixMultiplyKernel<<<dimGridA, dimBlockA>>>(device_MatrixAp, device_state_read, device_state_write);
		device_tmp_state = device_state_read;
		device_state_read = device_state_write;
		device_state_write = device_tmp_state;
#else
		/*
	       	 * CPU IMPLEMENTATION

	blocksize = 100;

#if MODE == 1
	Matrix device_MatrixAp, device_MatrixCA, device_state_read, device_state_write, device_tmp_state, device_output_chunk_read, device_output_chunk_write, device_tmp_output_chunk;

	device_MatrixCA = m_new(blocksize, MatrixA.cols);
	device_output_chunk_read = m_new(blocksize,1);
	device_output_chunk_write = m_new(blocksize,1);
	device_MatrixAp = m_new(MatrixA.rows, MatrixA.cols); // BLOCKDIAGMATRIX
	device_state_read = m_new(2 * filters, 1);
	device_state_write = m_new(2 * filters, 1);
