Skip to content
Merged
Show file tree
Hide file tree
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
30 changes: 15 additions & 15 deletions qmb/_hamiltonian_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ void apply_within_kernel(
std::int64_t low = 0;
std::int64_t high = result_batch_size - 1;
std::int64_t mid = 0;
auto compare = array_less<std::uint8_t, n_qubytes>();
auto less = array_less<std::uint8_t, n_qubytes>();
while (low <= high) {
mid = (low + high) / 2;
if (compare(current_configs, result_configs[mid])) {
if (less(current_configs, result_configs[mid])) {
high = mid - 1;
} else if (compare(result_configs[mid], current_configs)) {
} else if (less(result_configs[mid], current_configs)) {
low = mid + 1;
} else {
success = true;
Expand Down Expand Up @@ -256,11 +256,11 @@ auto apply_within_interface(
return result_psi;
}

template<typename T, typename Compare = std::less<T>>
template<typename T, typename Less = std::less<T>>
void add_into_heap(T* heap, std::int64_t heap_size, const T& value) {
auto compare = Compare();
auto less = Less();
std::int64_t index = 0;
if (compare(value, heap[index])) {
if (less(value, heap[index])) {
} else {
while (true) {
// Calculate the indices of the left and right children
Expand All @@ -271,8 +271,8 @@ void add_into_heap(T* heap, std::int64_t heap_size, const T& value) {
if (left_present) {
if (right_present) {
// Both left and right children are present
if (compare(value, heap[left])) {
if (compare(value, heap[right])) {
if (less(value, heap[left])) {
if (less(value, heap[right])) {
// Both children are greater than the value, break
break;
} else {
Expand All @@ -281,12 +281,12 @@ void add_into_heap(T* heap, std::int64_t heap_size, const T& value) {
index = right;
}
} else {
if (compare(value, heap[right])) {
if (less(value, heap[right])) {
// The right child is greater than the value
heap[index] = heap[left];
index = left;
} else {
if (compare(heap[left], heap[right])) {
if (less(heap[left], heap[right])) {
heap[index] = heap[left];
index = left;
} else {
Expand All @@ -297,7 +297,7 @@ void add_into_heap(T* heap, std::int64_t heap_size, const T& value) {
}
} else {
// Only the left child is present
if (compare(value, heap[left])) {
if (less(value, heap[left])) {
break;
} else {
heap[index] = heap[left];
Expand All @@ -307,7 +307,7 @@ void add_into_heap(T* heap, std::int64_t heap_size, const T& value) {
} else {
if (right_present) {
// Only the right child is present
if (compare(value, heap[right])) {
if (less(value, heap[right])) {
break;
} else {
heap[index] = heap[right];
Expand Down Expand Up @@ -370,12 +370,12 @@ void find_relative_kernel(
std::int64_t low = 0;
std::int64_t high = exclude_size - 1;
std::int64_t mid = 0;
auto compare = array_less<std::uint8_t, n_qubytes>();
auto less = array_less<std::uint8_t, n_qubytes>();
while (low <= high) {
mid = (low + high) / 2;
if (compare(current_configs, exclude_configs[mid])) {
if (less(current_configs, exclude_configs[mid])) {
high = mid - 1;
} else if (compare(exclude_configs[mid], current_configs)) {
} else if (less(exclude_configs[mid], current_configs)) {
low = mid + 1;
} else {
success = false;
Expand Down
50 changes: 25 additions & 25 deletions qmb/_hamiltonian_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ __device__ void apply_within_kernel(
std::int64_t low = 0;
std::int64_t high = result_batch_size - 1;
std::int64_t mid = 0;
auto compare = array_less<std::uint8_t, n_qubytes>();
auto less = array_less<std::uint8_t, n_qubytes>();
while (low <= high) {
mid = (low + high) / 2;
if (compare(current_configs, result_configs[mid])) {
if (less(current_configs, result_configs[mid])) {
high = mid - 1;
} else if (compare(result_configs[mid], current_configs)) {
} else if (less(result_configs[mid], current_configs)) {
low = mid + 1;
} else {
success = true;
Expand Down Expand Up @@ -309,14 +309,14 @@ __device__ void mutex_unlock(int* mutex1, int* mutex2) {
_mutex_unlock(mutex2);
}

template<typename T, typename Compare = thrust::less<T>>
template<typename T, typename Less = thrust::less<T>>
__device__ void add_into_heap(T* heap, int* mutex, std::int64_t heap_size, const T& value) {
auto compare = Compare();
auto less = Less();
std::int64_t index = 0;
if (compare(value, heap[index])) {
if (less(value, heap[index])) {
} else {
mutex_lock(&mutex[index]);
if (compare(value, heap[index])) {
if (less(value, heap[index])) {
mutex_unlock(&mutex[index]);
} else {
while (true) {
Expand All @@ -329,14 +329,14 @@ __device__ void add_into_heap(T* heap, int* mutex, std::int64_t heap_size, const
if (left_present) {
if (right_present) {
// Both left and right children are present
if (compare(value, heap[left])) {
if (compare(value, heap[right])) {
if (less(value, heap[left])) {
if (less(value, heap[right])) {
// Both children are greater than the value, break
break;
} else {
// The left child is greater than the value, treat it as if only the right child is present
mutex_lock(&mutex[right]);
if (compare(value, heap[right])) {
if (less(value, heap[right])) {
mutex_unlock(&mutex[right]);
break;
} else {
Expand All @@ -346,10 +346,10 @@ __device__ void add_into_heap(T* heap, int* mutex, std::int64_t heap_size, const
}
}
} else {
if (compare(value, heap[right])) {
if (less(value, heap[right])) {
// The right child is greater than the value, treat it as if only the left child is present
mutex_lock(&mutex[left]);
if (compare(value, heap[left])) {
if (less(value, heap[left])) {
mutex_unlock(&mutex[left]);
break;
} else {
Expand All @@ -359,8 +359,8 @@ __device__ void add_into_heap(T* heap, int* mutex, std::int64_t heap_size, const
}
} else {
mutex_lock(&mutex[left], &mutex[right]);
if (compare(heap[left], heap[right])) {
if (compare(value, heap[left])) {
if (less(heap[left], heap[right])) {
if (less(value, heap[left])) {
mutex_unlock(&mutex[left], &mutex[right]);
break;
} else {
Expand All @@ -369,7 +369,7 @@ __device__ void add_into_heap(T* heap, int* mutex, std::int64_t heap_size, const
index = left;
}
} else {
if (compare(value, heap[right])) {
if (less(value, heap[right])) {
mutex_unlock(&mutex[left], &mutex[right]);
break;
} else {
Expand All @@ -382,11 +382,11 @@ __device__ void add_into_heap(T* heap, int* mutex, std::int64_t heap_size, const
}
} else {
// Only the left child is present
if (compare(value, heap[left])) {
if (less(value, heap[left])) {
break;
} else {
mutex_lock(&mutex[left]);
if (compare(value, heap[left])) {
if (less(value, heap[left])) {
mutex_unlock(&mutex[left]);
break;
} else {
Expand All @@ -399,11 +399,11 @@ __device__ void add_into_heap(T* heap, int* mutex, std::int64_t heap_size, const
} else {
if (right_present) {
// Only the right child is present
if (compare(value, heap[right])) {
if (less(value, heap[right])) {
break;
} else {
mutex_lock(&mutex[right]);
if (compare(value, heap[right])) {
if (less(value, heap[right])) {
mutex_unlock(&mutex[right]);
break;
} else {
Expand Down Expand Up @@ -473,12 +473,12 @@ __device__ void find_relative_kernel(
std::int64_t low = 0;
std::int64_t high = exclude_size - 1;
std::int64_t mid = 0;
auto compare = array_less<std::uint8_t, n_qubytes>();
auto less = array_less<std::uint8_t, n_qubytes>();
while (low <= high) {
mid = (low + high) / 2;
if (compare(current_configs, exclude_configs[mid])) {
if (less(current_configs, exclude_configs[mid])) {
high = mid - 1;
} else if (compare(exclude_configs[mid], current_configs)) {
} else if (less(exclude_configs[mid], current_configs)) {
low = mid + 1;
} else {
success = false;
Expand Down Expand Up @@ -704,12 +704,12 @@ __device__ void single_relative_kernel(
std::int64_t low = 0;
std::int64_t high = exclude_size - 1;
std::int64_t mid = 0;
auto compare = array_less<std::uint8_t, n_qubytes>();
auto less = array_less<std::uint8_t, n_qubytes>();
while (low <= high) {
mid = (low + high) / 2;
if (compare(current_configs, exclude_configs[mid])) {
if (less(current_configs, exclude_configs[mid])) {
high = mid - 1;
} else if (compare(exclude_configs[mid], current_configs)) {
} else if (less(exclude_configs[mid], current_configs)) {
low = mid + 1;
} else {
success = false;
Expand Down
Loading