openjij
Framework for the Ising model and QUBO.
Loading...
Searching...
No Matches
index.hpp
Go to the documentation of this file.
1// Copyright 2023 Jij Inc.
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef OPENJIJ_SYSTEM_GPU_CHIMERA_CUDA_INDEX_HPP__
16#define OPENJIJ_SYSTEM_GPU_CHIMERA_CUDA_INDEX_HPP__
17
18#ifdef USE_CUDA
19
20#include <cassert>
21#include <cstdint>
22#include <cstdlib>
23#include <cuda_runtime.h>
24
25namespace openjij {
26namespace system {
27
31struct ChimeraInfo {
32 std::size_t rows;
33 std::size_t cols;
34 std::size_t trotters;
35
39 constexpr static std::size_t chimera_unitsize = 8;
40};
41
42// for both cuda host and device (kernel)
43namespace chimera_cuda {
44
56__host__ __device__ __forceinline__ std::uint64_t
57glIdx_x(ChimeraInfo info, std::uint64_t r, std::uint64_t c, std::uint64_t i,
58 std::uint64_t t) {
59 assert(r < info.rows);
60 assert(c < info.cols);
61 assert(i < info.chimera_unitsize);
62 assert(t < info.trotters);
63 return info.chimera_unitsize * c + i;
64}
65
77__host__ __device__ __forceinline__ std::uint64_t
78glIdx_y(ChimeraInfo info, std::uint64_t r, std::uint64_t c, std::uint64_t i,
79 std::uint64_t t) {
80 assert(r < info.rows);
81 assert(c < info.cols);
82 assert(i < info.chimera_unitsize);
83 assert(t < info.trotters);
84 return r;
85}
86
98__host__ __device__ __forceinline__ std::uint64_t
99glIdx_z(ChimeraInfo info, std::uint64_t r, std::uint64_t c, std::uint64_t i,
100 std::uint64_t t) {
101 assert(r < info.rows);
102 assert(c < info.cols);
103 assert(i < info.chimera_unitsize);
104 assert(t < info.trotters);
105 return t;
106}
107
119__host__ __device__ __forceinline__ std::uint64_t
120glIdx(ChimeraInfo info, std::uint64_t r, std::uint64_t c, std::uint64_t i,
121 std::uint64_t t) {
122 return (info.chimera_unitsize * info.cols * info.rows) *
123 glIdx_z(info, r, c, i, t) +
124 (info.chimera_unitsize * info.cols) * glIdx_y(info, r, c, i, t) +
125 glIdx_x(info, r, c, i, t);
126}
127
139template <std::size_t block_row, std::size_t block_col, std::size_t block_trot>
140__host__ __device__ __forceinline__ std::uint64_t
141bkIdx(ChimeraInfo info, std::uint64_t b_r, std::uint64_t b_c, std::uint64_t i,
142 std::uint64_t b_t) {
143 return (info.chimera_unitsize * block_col * block_row) * b_t +
144 (info.chimera_unitsize * block_col) * b_r +
145 (info.chimera_unitsize) * b_c + i;
146}
147
159template <std::size_t block_row, std::size_t block_col, std::size_t block_trot>
160__host__ __device__ __forceinline__ std::uint64_t
161bkIdx_ext(ChimeraInfo info, std::int64_t b_r, std::int64_t b_c, std::int64_t i,
162 std::int64_t b_t) {
163 return bkIdx<block_row + 2, block_col + 2, block_trot + 2>(
164 info, b_r + 1, b_c + 1, i, b_t + 1);
165}
166
177__host__ __device__ __forceinline__ std::uint64_t
178glIdx(ChimeraInfo info, std::uint64_t r, std::uint64_t c, std::uint64_t i) {
179 return glIdx(info, r, c, i, 0);
180}
181
192__host__ __device__ __forceinline__ std::uint64_t
193idx_i(ChimeraInfo info, std::uint64_t x, std::uint64_t y, std::uint64_t z) {
194 return x % info.chimera_unitsize;
195}
196
207__host__ __device__ __forceinline__ std::uint64_t
208idx_c(ChimeraInfo info, std::uint64_t x, std::uint64_t y, std::uint64_t z) {
209 return x / info.chimera_unitsize;
210}
211
222__host__ __device__ __forceinline__ std::uint64_t
223idx_r(ChimeraInfo info, std::uint64_t x, std::uint64_t y, std::uint64_t z) {
224 return y;
225}
226
237__host__ __device__ __forceinline__ std::uint64_t
238idx_t(ChimeraInfo info, std::uint64_t x, std::uint64_t y, std::uint64_t z) {
239 return z;
240}
241
242} // namespace chimera_cuda
243} // namespace system
244} // namespace openjij
245
246#endif
247#endif
Definition algorithm.hpp:24