示例#1
0
static bool testCalcDepth(int imageWidth, int imageHeight, int featureWidth, int featureHeight, int maximumDisplacement)
{
	float* leftImage = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (leftImage == NULL)
	{
		allocationFailed();
	}
	float* rightImage = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (rightImage == NULL)
	{
		free(leftImage);
		allocationFailed();
	}

	fillRandomFloat(leftImage, imageWidth * imageHeight);
	fillRandomFloat(rightImage, imageWidth * imageHeight);

	float* depthNaive = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (depthNaive == NULL)
	{
		free(leftImage);
		free(rightImage);
		allocationFailed();
	}
	float* depthOptimized = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (depthOptimized == NULL)
	{
		free(leftImage);
		free(rightImage);
		free(depthNaive);
		allocationFailed();
	}

	calcDepthNaive(depthNaive, leftImage, rightImage, imageWidth, imageHeight, featureWidth, featureHeight, maximumDisplacement, NULL);
	calcDepthOptimized(depthOptimized, leftImage, rightImage, imageWidth, imageHeight, featureWidth, featureHeight, maximumDisplacement);

	for (size_t i = 0; i < imageWidth * imageHeight; i++)
	{
		if (!floatsWithinTolerance(depthNaive[i], depthOptimized[i]))
		{
			free(leftImage);
			free(rightImage);
			free(depthNaive);
			free(depthOptimized);
			return false;
		}
	}
	free(leftImage);
	free(rightImage);
	free(depthNaive);
	free(depthOptimized);
	return true;
}
示例#2
0
static bool benchmarkMatrix(int imageWidth, int imageHeight, int featureWidth, int featureHeight, int maximumDisplacement)
{
	float* left = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (left == NULL)
	{
		allocationFailed();
	}

	float* right = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (right == NULL)
	{
		free(left);
		allocationFailed();
	}

	fillRandomFloat(left, imageWidth * imageHeight);
	fillRandomFloat(right, imageWidth * imageHeight);

	float* depthNaive = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (depthNaive == NULL)
	{
		free(left);
		free(right);
		allocationFailed();
	}

	float* depthOptimized = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (depthOptimized == NULL)
	{
		free(left);
		free(right);
		free(depthNaive);
		allocationFailed();
	}

	double speedup;
	uint64_t startTSC, endTSC;

	// Get total clock cycles for optimised
	startTSC = __rdtsc();
	calcDepthOptimized(depthOptimized, left, right, imageWidth, imageHeight, featureWidth, featureHeight, maximumDisplacement);
	endTSC = __rdtsc();
	double optimizedTSC = endTSC - startTSC;

	// Get total clock cycles for naive
	startTSC = __rdtsc();
	calcDepthNaive(depthNaive, left, right, imageWidth, imageHeight, featureWidth, featureHeight, maximumDisplacement);
	endTSC = __rdtsc();
	double naiveTSC = endTSC - startTSC;

	// Speedup is just naive / optimised
	speedup = naiveTSC / optimizedTSC;
	printf("%.4f Speedup Ratio\r\n", speedup);

	for (size_t i = 0; i < imageWidth * imageHeight; i++)
	{
		if (!floatsWithinTolerance(depthNaive[i], depthOptimized[i]))
		{
			free(left);
			free(right);
			free(depthNaive);
			free(depthOptimized);
			return false;
		}
	}

	free(left);
	free(right);
	free(depthNaive);
	free(depthOptimized);

	return true;
}
示例#3
0
static bool testMatrix(int imageWidth, int imageHeight, int featureWidth, int featureHeight, int maximumDisplacement)
{
	float* left = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (left == NULL)
	{
		allocationFailed();
	}
	float* right = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (right == NULL)
	{
		free(left);
		allocationFailed();
	}
	fillRandomFloat(left, imageWidth * imageHeight);
	fillRandomFloat(right, imageWidth * imageHeight);

	float* depthNaive = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (depthNaive == NULL)
	{
		free(left);
		free(right);
		allocationFailed();
	}

	float* depthOptimized = (float*)malloc(sizeof(float)* imageWidth * imageHeight);
	if (depthOptimized == NULL)
	{
		free(left);
		free(right);
		free(depthNaive);
		allocationFailed();
	}

	size_t floatOps = 0;

	calcDepthNaive(depthNaive, left, right, imageWidth, imageHeight, featureWidth, featureHeight, maximumDisplacement, &floatOps);
	calcDepthOptimized(depthOptimized, left, right, imageWidth, imageHeight, featureWidth, featureHeight, maximumDisplacement);

	int result = true;
	for (size_t i = 0; i < imageWidth * imageHeight; i++)
	{
		if (!floatsWithinTolerance(depthNaive[i], depthOptimized[i]))
		{
		    result = false;
		}
	}

	if (true || !result) {
	    printf("Left image: \n");
	    printFloatImg(left, imageWidth, imageHeight);
	    printf("Right iamge: \n");
	    printFloatImg(right, imageWidth, imageHeight);
	    printf("Expected: \n");
	    printFloatImg(depthNaive, imageWidth, imageHeight);
	    printf("Actual: \n");
	    printFloatImg(depthOptimized, imageWidth, imageHeight);
	}

	free(left);
	free(right);
	free(depthNaive);
	free(depthOptimized);

	return result;
}