Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 0 additions & 163 deletions test/stdgpu/mutex.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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<stdgpu::mutex_array<>::reference>(_locks[_n_0]);
stdgpu::mutex_array<>::reference ref_1 = static_cast<stdgpu::mutex_array<>::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<int>(1);

stdgpu::for_each_index(thrust::device, 1, lock_multiple_functor_new_reference(locks, n_0, n_1, result));

int host_result;
copyDevice2HostArray<int>(result, 1, &host_result, MemoryCopy::NO_CHECK);

destroyDeviceArray<int>(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<stdgpu::mutex_array<>::reference>(_locks[_n]);
*_result = static_cast<std::uint8_t>(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<std::uint8_t>(1);

stdgpu::for_each_index(thrust::device, 1, lock_single_functor_new_reference(locks, n, result));

std::uint8_t host_result;
copyDevice2HostArray<std::uint8_t>(result, 1, &host_result, MemoryCopy::NO_CHECK);

destroyDeviceArray<std::uint8_t>(result);

return static_cast<bool>(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;
Expand Down