diff --git a/test/stdgpu/mutex.inc b/test/stdgpu/mutex.inc index e756e551d..50b048f9c 100644 --- a/test/stdgpu/mutex.inc +++ b/test/stdgpu/mutex.inc @@ -337,169 +337,6 @@ TEST_F(stdgpu_mutex, multiple_try_lock_both_locked) stdgpu::mutex_array<>::destroyDeviceObject(locks_check); } -class lock_multiple_functor_new_reference -{ -public: - lock_multiple_functor_new_reference(const stdgpu::mutex_array<>& locks, - const stdgpu::index_t n_0, - const stdgpu::index_t n_1, - int* result) - : _locks(locks) - , _n_0(n_0) - , _n_1(n_1) - , _result(result) - { - } - - STDGPU_DEVICE_ONLY void - operator()(STDGPU_MAYBE_UNUSED const stdgpu::index_t i) - { - stdgpu::mutex_array<>::reference ref_0 = static_cast::reference>(_locks[_n_0]); - stdgpu::mutex_array<>::reference ref_1 = static_cast::reference>(_locks[_n_1]); - *_result = stdgpu::try_lock(ref_0, ref_1); - } - -private: - stdgpu::mutex_array<> _locks; - stdgpu::index_t _n_0; - stdgpu::index_t _n_1; - int* _result; -}; - -int -lock_multiple_new_reference(const stdgpu::mutex_array<>& locks, const stdgpu::index_t n_0, const stdgpu::index_t n_1) -{ - int* result = createDeviceArray(1); - - stdgpu::for_each_index(thrust::device, 1, lock_multiple_functor_new_reference(locks, n_0, n_1, result)); - - int host_result; - copyDevice2HostArray(result, 1, &host_result, MemoryCopy::NO_CHECK); - - destroyDeviceArray(result); - - return host_result; -} - -class lock_single_functor_new_reference -{ -public: - lock_single_functor_new_reference(const stdgpu::mutex_array<>& locks, const stdgpu::index_t n, std::uint8_t* result) - : _locks(locks) - , _n(n) - , _result(result) - { - } - - STDGPU_DEVICE_ONLY void - operator()(STDGPU_MAYBE_UNUSED const stdgpu::index_t i) - { - stdgpu::mutex_array<>::reference ref = static_cast::reference>(_locks[_n]); - *_result = static_cast(ref.try_lock()); - } - -private: - stdgpu::mutex_array<> _locks; - stdgpu::index_t _n; - std::uint8_t* _result; -}; - -bool -lock_single_new_reference(const stdgpu::mutex_array<>& locks, const stdgpu::index_t n) -{ - std::uint8_t* result = createDeviceArray(1); - - stdgpu::for_each_index(thrust::device, 1, lock_single_functor_new_reference(locks, n, result)); - - std::uint8_t host_result; - copyDevice2HostArray(result, 1, &host_result, MemoryCopy::NO_CHECK); - - destroyDeviceArray(result); - - return static_cast(host_result); -} - -TEST_F(stdgpu_mutex, multiple_try_lock_both_unlocked_new_reference) -{ - const stdgpu::index_t n_0 = 21; - const stdgpu::index_t n_1 = 42; - - stdgpu::mutex_array<> locks_check = stdgpu::mutex_array<>::createDeviceObject(locks_size); - - ASSERT_TRUE(equal(locks, locks_check)); - - EXPECT_EQ(lock_multiple_new_reference(locks, n_0, n_1), -1); - - // Both mutexes should be locked now - ASSERT_TRUE(lock_single_new_reference(locks_check, n_0)); - ASSERT_TRUE(lock_single_new_reference(locks_check, n_1)); - EXPECT_TRUE(equal(locks, locks_check)); - - stdgpu::mutex_array<>::destroyDeviceObject(locks_check); -} - -TEST_F(stdgpu_mutex, multiple_try_lock_first_unlocked_second_locked_new_reference) -{ - const stdgpu::index_t n_0 = 21; - const stdgpu::index_t n_1 = 42; - - ASSERT_TRUE(lock_single_new_reference(locks, n_1)); - - stdgpu::mutex_array<> locks_check = stdgpu::mutex_array<>::createDeviceObject(locks_size); - ASSERT_TRUE(lock_single_new_reference(locks_check, n_1)); - - ASSERT_TRUE(equal(locks, locks_check)); - - EXPECT_EQ(lock_multiple_new_reference(locks, n_0, n_1), 1); - - // Nothing has changed - EXPECT_TRUE(equal(locks, locks_check)); - - stdgpu::mutex_array<>::destroyDeviceObject(locks_check); -} - -TEST_F(stdgpu_mutex, multiple_try_lock_first_locked_second_unlocked_new_reference) -{ - const stdgpu::index_t n_0 = 21; - const stdgpu::index_t n_1 = 42; - - ASSERT_TRUE(lock_single_new_reference(locks, n_0)); - - stdgpu::mutex_array<> locks_check = stdgpu::mutex_array<>::createDeviceObject(locks_size); - ASSERT_TRUE(lock_single_new_reference(locks_check, n_0)); - - ASSERT_TRUE(equal(locks, locks_check)); - - EXPECT_EQ(lock_multiple_new_reference(locks, n_0, n_1), 0); - - // Nothing has changed - EXPECT_TRUE(equal(locks, locks_check)); - - stdgpu::mutex_array<>::destroyDeviceObject(locks_check); -} - -TEST_F(stdgpu_mutex, multiple_try_lock_both_locked_new_reference) -{ - const stdgpu::index_t n_0 = 21; - const stdgpu::index_t n_1 = 42; - - ASSERT_TRUE(lock_single_new_reference(locks, n_0)); - ASSERT_TRUE(lock_single_new_reference(locks, n_1)); - - stdgpu::mutex_array<> locks_check = stdgpu::mutex_array<>::createDeviceObject(locks_size); - ASSERT_TRUE(lock_single_new_reference(locks_check, n_0)); - ASSERT_TRUE(lock_single_new_reference(locks_check, n_1)); - - ASSERT_TRUE(equal(locks, locks_check)); - - EXPECT_EQ(lock_multiple_new_reference(locks, n_0, n_1), 0); - - // Nothing has changed - EXPECT_TRUE(equal(locks, locks_check)); - - stdgpu::mutex_array<>::destroyDeviceObject(locks_check); -} - TEST_F(stdgpu_mutex, get_allocator) { const stdgpu::index_t N = 10000;