Beispiel #1
0
END_TEST

START_TEST(test_ck_assert_uint_le)
{
  unsigned int x = 2;
  unsigned int y = 3;
  ck_assert_uint_le(x, y);
  ck_assert_uint_le(x, x);
  ck_assert_uint_le(y, x);
  #define LINENO_ck_assert_uint_le _STR(__LINE__)
}
Beispiel #2
0
static void
test_last_buffer_is_clipped (BT_TEST_ARGS)
{
  BT_TEST_START;
  GST_INFO ("-- arrange --");
  GstElement *p =
      gst_parse_launch
      ("buzztrax-test-audio-synth name=\"src\" ! fakesink async=false",
      NULL);
  BtTestAudioSynth *e =
      (BtTestAudioSynth *) gst_bin_get_by_name (GST_BIN (p), "src");
  GstBus *bus = gst_element_get_bus (p);

  GST_INFO ("-- act --");
  gst_element_set_state (p, GST_STATE_READY);
  gst_element_set_context (p, ctx);
  gst_element_set_state (p, GST_STATE_PAUSED);
  gst_element_get_state (p, NULL, NULL, GST_CLOCK_TIME_NONE);
  gst_element_seek (p, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
      GST_SEEK_TYPE_SET, G_GUINT64_CONSTANT (0),
      GST_SEEK_TYPE_SET, ticktime * 1.5);
  gst_element_set_state (p, GST_STATE_PLAYING);
  gst_element_get_state (p, NULL, NULL, GST_CLOCK_TIME_NONE);
  gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, GST_CLOCK_TIME_NONE);

  GST_INFO ("-- assert --");
  BufferFields *bf0 = get_buffer_info (e, 0);
  BufferFields *bf1 = get_buffer_info (e, 1);
  ck_assert_uint64_le (bf1->duration, bf0->duration / 2);
  ck_assert_uint_le (bf1->size, bf0->size / 2);

  GST_INFO ("-- cleanup --");
  gst_element_set_state (p, GST_STATE_NULL);
  gst_object_unref (e);
  gst_object_unref (p);
  BT_TEST_END;
}
}END_TEST

/**
 * Integer Factorization test
 */

START_TEST(test_integerfactorization){
	ga_factor_list fl;
	uint64_t       n;

	/**
	 * Attempt exact factorization for 2^64-1, no k-smoothness constraint.
	 * Expected PASS with 3*5*17*257*641*65537*6700417
	 */

	n = 18446744073709551615ULL;
	ck_assert_int_ne (gaIFactorize(n,         0,     0, &fl), 0);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    3ULL),  1);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    5ULL),  1);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                   17ULL),  1);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                  257ULL),  1);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                  641ULL),  1);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                65537ULL),  1);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,              6700417ULL),  1);
	ck_assert_uint_eq(gaIFLGetProduct(&fl), n);

	/**
	 * Attempt exact factorization for 2^64-1, 4096-smooth constraint.
	 * Expected FAIL, because 2^64-1 possesses prime factors in excess of 4096.
	 */

	n = 18446744073709551615ULL;
	ck_assert_int_eq (gaIFactorize(n,         0,  4096, &fl), 0);

	/**
	 * Attempt approximate factorization for 2^64-1, no k-smoothness constraint.
	 * Unlimited growth permitted.
	 * Expected PASS, since 2^64-1 rounds up to 2^64 and 2^64 trivially factorizes.
	 */

	n = 18446744073709551615ULL;
	ck_assert_int_ne (gaIFactorize(n,        -1,     0, &fl), 0);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    2ULL), 64);
	ck_assert_uint_eq(gaIFLGetGreatestFactor(&fl), 2);
	ck_assert_int_ne (gaIFLIsOverflowed(&fl), 0);

	/**
	 * Attempt exact factorization for 2196095973992233039, no k-smoothness constraint.
	 * 2196095973992233039 is a large, highly non-smooth number, with three enormous
	 * factors.
	 * Expected PASS *very quickly*, since it factorizes as 1299817*1299821*1299827
	 */

	n =  2196095973992233039ULL;
	ck_assert_int_ne (gaIFactorize(n,         0,     0, &fl), 0);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,              1299817ULL),  1);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,              1299821ULL),  1);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,              1299827ULL),  1);
	ck_assert_uint_eq(gaIFLGetGreatestFactor(&fl), 1299827);
	ck_assert_uint_eq(gaIFLGetProduct(&fl), n);

	/**
	 * Attempt approximate factorization for 2196095973992233039, 16-smooth constraint.
	 * 2196095973992233039 is a large, highly non-smooth number, with three enormous
	 * factors. It is not 64-smooth, so code paths that attempt approximate
	 * factorization within the growth limits (.005%) are exercised.
	 *
	 * Expected PASS *relatively quickly*.
	 */

	n =  2196095973992233039ULL;
	ck_assert_int_ne (gaIFactorize(n, n*1.00005,    16, &fl), 0);
	ck_assert_uint_ge(gaIFLGetProduct(&fl), n);
	ck_assert_uint_le(gaIFLGetProduct(&fl), n*1.00005);

	/**
	 * Attempt exact factorization of 7438473388800000000, 5-smooth constraint.
	 * It is a large, 5-smooth number. This should exercise the 5-smooth
	 * factorization path.
	 */

	n =  7438473388800000000ULL;
	ck_assert_int_ne (gaIFactorize(n,         0,     5, &fl), 0);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    2ULL), 14);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    3ULL), 19);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    5ULL),  8);
	ck_assert_uint_eq(gaIFLGetGreatestFactor(&fl), 5);
	ck_assert_uint_eq(gaIFLGetProduct(&fl), n);

	/**
	 * Attempt approximate factorization of 7438473388799999997, 2-smooth constraint.
	 * It is a large, non-smooth number. This should exercise the optimal 2-smooth
	 * factorizer in spite of the available, unlimited slack.
	 */

	n =  7438473388799999997ULL;
	ck_assert_int_ne (gaIFactorize(n,        -1,      2, &fl), 0);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    2ULL), 63);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    3ULL),  0);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    5ULL),  0);
	ck_assert_uint_eq(gaIFLGetGreatestFactor(&fl), 2);
	ck_assert_uint_eq(gaIFLGetProduct(&fl),  9223372036854775808ULL);

	/**
	 * Attempt approximate factorization of 7438473388799999997, 3-smooth constraint.
	 * It is a large, non-smooth number. This should exercise the optimal 3-smooth
	 * factorizer in spite of the available, unlimited slack.
	 */

	n =  7438473388799999997ULL;
	ck_assert_int_ne (gaIFactorize(n,        -1,      3, &fl), 0);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    2ULL), 31);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    3ULL), 20);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    5ULL),  0);
	ck_assert_uint_eq(gaIFLGetGreatestFactor(&fl), 3);
	ck_assert_uint_eq(gaIFLGetProduct(&fl),  7487812485248974848ULL);

	/**
	 * Attempt approximate factorization of 7438473388799999997, 5-smooth constraint.
	 * It is a large, non-smooth number, but 3 integers above it is a 5-smooth
	 * integer, 7438473388800000000. This should exercise the optimal 5-smooth
	 * factorizer in spite of the available, unlimited slack.
	 */

	n =  7438473388799999997ULL;
	ck_assert_int_ne (gaIFactorize(n,        -1,     5, &fl), 0);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    2ULL), 14);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    3ULL), 19);
	ck_assert_int_eq (gaIFLGetFactorPower(&fl,                    5ULL),  8);
	ck_assert_uint_eq(gaIFLGetGreatestFactor(&fl), 5);
	ck_assert_uint_eq(gaIFLGetProduct(&fl), 7438473388800000000ULL);

	/**
	 * Toughest challenge: Attempt very tight approximate factorization of
	 * 9876543210987654321 with .01% slack and 43-smooth constraint.
	 *
	 * This forces a bypass of the optimal 5-smooth factorizers and heavily
	 * exercises the nextI:, subfactorize:, primetest: and newX jumps and
	 * calculations.
	 *
	 * Expected PASS, "reasonably fast".
	 */

	n =  9876543210987654321ULL;
	ck_assert_int_ne (gaIFactorize(n, n*1.0001,    43, &fl), 0);
	ck_assert_uint_ge(gaIFLGetProduct(&fl), n);
	ck_assert_uint_le(gaIFLGetProduct(&fl), n*1.0001);
	ck_assert_uint_le(gaIFLGetGreatestFactor(&fl), 43);
}END_TEST
}END_TEST

START_TEST(test_scheduler){
	/* We use here the CUDA limits of a CC 3.0 GPU as an example. */
	uint64_t maxBTot  =       1024, maxBInd[] = {      1024,      1024,        64},
	         maxGTot  = 0xFFFFFFFF, maxGInd[] = {2147483647,     65535,     65535},
	         warpSize =         32;

	int                warpAxis;
	uint64_t           dims[3];
	ga_factor_list     factBS[3], factGS[3], factCS[3];
	unsigned long long intbBS[3], intbGS[3], intbCS[3];
	unsigned long long intaBS[3], intaGS[3], intaCS[3];

	/**
	 * NOTE: If you want to view befores-and-afters of scheduling, #define PRINT
	 *       to something non-0.
	 */
#define PRINT 0

	/**
	 *
	 * Testcase: (895,1147,923) job, warpSize on axis 0.
	 *
	 */

	{
		warpAxis       =          0;
		dims[0]        =        895;
		dims[1]        =       1141;
		dims[2]        =        923;
		dims[warpAxis] = (dims[warpAxis]+warpSize-1) / warpSize;

		/**
		 * Factorization job must be successful.
		 */

		ck_assert(gaIFactorize(warpAxis==0?warpSize:1,           0, maxBInd[0], factBS+0));
		ck_assert(gaIFactorize(warpAxis==1?warpSize:1,           0, maxBInd[1], factBS+1));
		ck_assert(gaIFactorize(warpAxis==2?warpSize:1,           0, maxBInd[2], factBS+2));
		ck_assert(gaIFactorize(                     1,           0, maxBInd[0], factGS+0));
		ck_assert(gaIFactorize(                     1,           0, maxBInd[1], factGS+1));
		ck_assert(gaIFactorize(                     1,           0, maxBInd[2], factGS+2));
		ck_assert(gaIFactorize(               dims[0], dims[0]*1.1, maxBInd[0], factCS+0));
		ck_assert(gaIFactorize(               dims[1], dims[1]*1.1, maxBInd[1], factCS+1));
		ck_assert(gaIFactorize(               dims[2], dims[2]*1.1, maxBInd[2], factCS+2));

		intbBS[0] = gaIFLGetProduct(factBS+0);
		intbBS[1] = gaIFLGetProduct(factBS+1);
		intbBS[2] = gaIFLGetProduct(factBS+2);
		intbGS[0] = gaIFLGetProduct(factGS+0);
		intbGS[1] = gaIFLGetProduct(factGS+1);
		intbGS[2] = gaIFLGetProduct(factGS+2);
		intbCS[0] = gaIFLGetProduct(factCS+0);
		intbCS[1] = gaIFLGetProduct(factCS+1);
		intbCS[2] = gaIFLGetProduct(factCS+2);

		/**
		 * Ensure that factorization only *increases* the size of the problem.
		 */

		ck_assert_uint_ge(intbCS[0], dims[0]);
		ck_assert_uint_ge(intbCS[1], dims[1]);
		ck_assert_uint_ge(intbCS[2], dims[2]);


		/**
		 * Run scheduler.
		 */

#if PRINT
		printf("Before:\n");
		printf("BS: (%6llu, %6llu, %6llu)\n", intbBS[0], intbBS[1], intbBS[2]);
		printf("GS: (%6llu, %6llu, %6llu)\n", intbGS[0], intbGS[1], intbGS[2]);
		printf("CS: (%6llu, %6llu, %6llu)\n", intbCS[0], intbCS[1], intbCS[2]);
#endif
		gaIFLSchedule(3, maxBTot, maxBInd, maxGTot, maxGInd, factBS, factGS, factCS);
		intaBS[0] = gaIFLGetProduct(factBS+0);
		intaBS[1] = gaIFLGetProduct(factBS+1);
		intaBS[2] = gaIFLGetProduct(factBS+2);
		intaGS[0] = gaIFLGetProduct(factGS+0);
		intaGS[1] = gaIFLGetProduct(factGS+1);
		intaGS[2] = gaIFLGetProduct(factGS+2);
		intaCS[0] = gaIFLGetProduct(factCS+0);
		intaCS[1] = gaIFLGetProduct(factCS+1);
		intaCS[2] = gaIFLGetProduct(factCS+2);
#if PRINT
		printf("After:\n");
		printf("BS: (%6llu, %6llu, %6llu)\n", intaBS[0], intaBS[1], intaBS[2]);
		printf("GS: (%6llu, %6llu, %6llu)\n", intaGS[0], intaGS[1], intaGS[2]);
		printf("CS: (%6llu, %6llu, %6llu)\n", intaCS[0], intaCS[1], intaCS[2]);
#endif

		/**
		 * Scheduling is only about moving factors between block/grid/chunk factor
		 * lists. Therefore, the three dimensions must not have changed size.
		 */

		ck_assert_uint_eq(intbBS[0]*intbGS[0]*intbCS[0], intaBS[0]*intaGS[0]*intaCS[0]);
		ck_assert_uint_eq(intbBS[1]*intbGS[1]*intbCS[1], intaBS[1]*intaGS[1]*intaCS[1]);
		ck_assert_uint_eq(intbBS[2]*intbGS[2]*intbCS[2], intaBS[2]*intaGS[2]*intaCS[2]);

		/**
		 * Verify that the individual limits and global limits on threads in a
		 * block and blocks in a grid are met.
		 */

		ck_assert_uint_le(intaBS[0],                     maxBInd[0]);
		ck_assert_uint_le(intaBS[1],                     maxBInd[1]);
		ck_assert_uint_le(intaBS[2],                     maxBInd[2]);
		ck_assert_uint_le(intaGS[0],                     maxGInd[0]);
		ck_assert_uint_le(intaGS[1],                     maxGInd[1]);
		ck_assert_uint_le(intaGS[2],                     maxGInd[2]);
		ck_assert_uint_le(intaBS[0]*intaBS[1]*intaBS[2], maxBTot);
		ck_assert_uint_le(intaGS[0]*intaGS[1]*intaGS[2], maxGTot);
	}


	/**
	 *
	 * Testcase: (1,1,121632959) job, warpSize on axis 2.
	 *
	 */

	{
		warpAxis       =         2;
		dims[0]        =         1;
		dims[1]        =         1;
		dims[2]        = 121632959;
		dims[warpAxis] = (dims[warpAxis]+warpSize-1) / warpSize;

		/**
		 * Factorization job must be successful.
		 */

		ck_assert(gaIFactorize(warpAxis==0?warpSize:1,           0, maxBInd[0], factBS+0));
		ck_assert(gaIFactorize(warpAxis==1?warpSize:1,           0, maxBInd[1], factBS+1));
		ck_assert(gaIFactorize(warpAxis==2?warpSize:1,           0, maxBInd[2], factBS+2));
		ck_assert(gaIFactorize(                     1,           0, maxBInd[0], factGS+0));
		ck_assert(gaIFactorize(                     1,           0, maxBInd[1], factGS+1));
		ck_assert(gaIFactorize(                     1,           0, maxBInd[2], factGS+2));
		ck_assert(gaIFactorize(               dims[0], dims[0]*1.1, maxBInd[0], factCS+0));
		ck_assert(gaIFactorize(               dims[1], dims[1]*1.1, maxBInd[1], factCS+1));
		ck_assert(gaIFactorize(               dims[2], dims[2]*1.1, maxBInd[2], factCS+2));

		intbBS[0] = gaIFLGetProduct(factBS+0);
		intbBS[1] = gaIFLGetProduct(factBS+1);
		intbBS[2] = gaIFLGetProduct(factBS+2);
		intbGS[0] = gaIFLGetProduct(factGS+0);
		intbGS[1] = gaIFLGetProduct(factGS+1);
		intbGS[2] = gaIFLGetProduct(factGS+2);
		intbCS[0] = gaIFLGetProduct(factCS+0);
		intbCS[1] = gaIFLGetProduct(factCS+1);
		intbCS[2] = gaIFLGetProduct(factCS+2);

		/**
		 * Ensure that factorization only *increases* the size of the problem.
		 */

		ck_assert_uint_ge(intbCS[0], dims[0]);
		ck_assert_uint_ge(intbCS[1], dims[1]);
		ck_assert_uint_ge(intbCS[2], dims[2]);


		/**
		 * Run scheduler.
		 */

#if PRINT
		printf("Before:\n");
		printf("BS: (%6llu, %6llu, %6llu)\n", intbBS[0], intbBS[1], intbBS[2]);
		printf("GS: (%6llu, %6llu, %6llu)\n", intbGS[0], intbGS[1], intbGS[2]);
		printf("CS: (%6llu, %6llu, %6llu)\n", intbCS[0], intbCS[1], intbCS[2]);
#endif
		gaIFLSchedule(3, maxBTot, maxBInd, maxGTot, maxGInd, factBS, factGS, factCS);
		intaBS[0] = gaIFLGetProduct(factBS+0);
		intaBS[1] = gaIFLGetProduct(factBS+1);
		intaBS[2] = gaIFLGetProduct(factBS+2);
		intaGS[0] = gaIFLGetProduct(factGS+0);
		intaGS[1] = gaIFLGetProduct(factGS+1);
		intaGS[2] = gaIFLGetProduct(factGS+2);
		intaCS[0] = gaIFLGetProduct(factCS+0);
		intaCS[1] = gaIFLGetProduct(factCS+1);
		intaCS[2] = gaIFLGetProduct(factCS+2);
#if PRINT
		printf("After:\n");
		printf("BS: (%6llu, %6llu, %6llu)\n", intaBS[0], intaBS[1], intaBS[2]);
		printf("GS: (%6llu, %6llu, %6llu)\n", intaGS[0], intaGS[1], intaGS[2]);
		printf("CS: (%6llu, %6llu, %6llu)\n", intaCS[0], intaCS[1], intaCS[2]);
#endif

		/**
		 * Scheduling is only about moving factors between block/grid/chunk factor
		 * lists. Therefore, the three dimensions must not have changed size.
		 */

		ck_assert_uint_eq(intbBS[0]*intbGS[0]*intbCS[0], intaBS[0]*intaGS[0]*intaCS[0]);
		ck_assert_uint_eq(intbBS[1]*intbGS[1]*intbCS[1], intaBS[1]*intaGS[1]*intaCS[1]);
		ck_assert_uint_eq(intbBS[2]*intbGS[2]*intbCS[2], intaBS[2]*intaGS[2]*intaCS[2]);

		/**
		 * Verify that the individual limits and global limits on threads in a
		 * block and blocks in a grid are met.
		 */

		ck_assert_uint_le(intaBS[0],                     maxBInd[0]);
		ck_assert_uint_le(intaBS[1],                     maxBInd[1]);
		ck_assert_uint_le(intaBS[2],                     maxBInd[2]);
		ck_assert_uint_le(intaGS[0],                     maxGInd[0]);
		ck_assert_uint_le(intaGS[1],                     maxGInd[1]);
		ck_assert_uint_le(intaGS[2],                     maxGInd[2]);
		ck_assert_uint_le(intaBS[0]*intaBS[1]*intaBS[2], maxBTot);
		ck_assert_uint_le(intaGS[0]*intaGS[1]*intaGS[2], maxGTot);
	}
}END_TEST