Path: blob/master/jcl/src/openj9.cuda/share/classes/com/ibm/cuda/CudaGrid.java
12927 views
/*[INCLUDE-IF Sidecar18-SE]*/1/*******************************************************************************2* Copyright (c) 2013, 2018 IBM Corp. and others3*4* This program and the accompanying materials are made available under5* the terms of the Eclipse Public License 2.0 which accompanies this6* distribution and is available at https://www.eclipse.org/legal/epl-2.0/7* or the Apache License, Version 2.0 which accompanies this distribution and8* is available at https://www.apache.org/licenses/LICENSE-2.0.9*10* This Source Code may also be made available under the following11* Secondary Licenses when the conditions for such availability set12* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU13* General Public License, version 2 with the GNU Classpath14* Exception [1] and GNU General Public License, version 2 with the15* OpenJDK Assembly Exception [2].16*17* [1] https://www.gnu.org/software/classpath/license.html18* [2] http://openjdk.java.net/legal/assembly-exception.html19*20* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception21*******************************************************************************/22package com.ibm.cuda;2324/**25* The {@code CudaGrid} class represents a kernel launch configuration.26*/27public final class CudaGrid {2829/**30* The size of the thread block in the x dimension.31*/32public final int blockDimX;3334/**35* The size of the thread block in the y dimension.36*/37public final int blockDimY;3839/**40* The size of the thread block in the z dimension.41*/42public final int blockDimZ;4344/**45* The size of the grid in the x dimension.46*/47public final int gridDimX;4849/**50* The size of the grid in the y dimension.51*/52public final int gridDimY;5354/**55* The size of the grid in the z dimension.56*/57public final int gridDimZ;5859/**60* The number of bytes of shared memory to allocate to each thread block.61*/62public final int sharedMemBytes;6364/**65* The stream on which the kernel should be queued66* (or null for the default stream).67*/68public final CudaStream stream;6970/**71* Creates a grid with the specified dimensions, with no shared memory72* on the default stream.73*74* @param gridDim75* the dimensions of the grid76* @param blockDim77* the dimensions of the thread block78*/79public CudaGrid(Dim3 gridDim, Dim3 blockDim) {80this(gridDim, blockDim, 0, null);81}8283/**84* Creates a grid with the specified dimensions with no shared memory85* on the specified stream.86*87* @param gridDim88* the dimensions of the grid89* @param blockDim90* the dimensions of the thread block91* @param stream92* the stream on which the kernel should be queued93* (or null for the default stream)94*/95public CudaGrid(Dim3 gridDim, Dim3 blockDim, CudaStream stream) {96this(gridDim, blockDim, 0, stream);97}9899/**100* Creates a grid with the specified dimensions and shared memory size101* on the default stream.102*103* @param gridDim104* the dimensions of the grid105* @param blockDim106* the dimensions of the thread block107* @param sharedMemBytes108* the number of bytes of shared memory to allocate to each thread block109*/110public CudaGrid(Dim3 gridDim, Dim3 blockDim, int sharedMemBytes) {111this(gridDim, blockDim, sharedMemBytes, null);112}113114/**115* Creates a grid with the specified dimensions and shared memory size116* on the specified stream.117*118* @param gridDim119* the dimensions of the grid120* @param blockDim121* the dimensions of the thread block122* @param sharedMemBytes123* the number of bytes of shared memory to allocate to each thread block124* @param stream125* the stream on which the kernel should be queued126* (or null for the default stream)127*/128public CudaGrid(Dim3 gridDim, Dim3 blockDim, int sharedMemBytes,129CudaStream stream) {130super();131this.blockDimX = blockDim.x;132this.blockDimY = blockDim.y;133this.blockDimZ = blockDim.z;134this.gridDimX = gridDim.x;135this.gridDimY = gridDim.y;136this.gridDimZ = gridDim.z;137this.sharedMemBytes = sharedMemBytes;138this.stream = stream;139}140141/**142* Creates a grid with the specified x dimensions with no shared memory143* on the default stream. The y and z dimensions are set to 1.144*145* @param gridDim146* the x dimension of the grid147* @param blockDim148* the x dimension of the thread block149*/150public CudaGrid(int gridDim, int blockDim) {151this(gridDim, blockDim, 0, null);152}153154/**155* Creates a grid with the specified x dimensions with no shared memory156* on the specified stream. The y and z dimensions are set to 1.157*158* @param gridDim159* the x dimension of the grid160* @param blockDim161* the x dimension of the thread block162* @param stream163* the stream on which the kernel should be queued164* (or null for the default stream)165*/166public CudaGrid(int gridDim, int blockDim, CudaStream stream) {167this(gridDim, blockDim, 0, stream);168}169170/**171* Creates a grid with the specified x dimensions and shared memory size172* on the default stream. The y and z dimensions are set to 1.173*174* @param gridDim175* the x dimension of the grid176* @param blockDim177* the x dimension of the thread block178* @param sharedMemBytes179* the number of bytes of shared memory to allocate to each thread block180*/181public CudaGrid(int gridDim, int blockDim, int sharedMemBytes) {182this(gridDim, blockDim, sharedMemBytes, null);183}184185/**186* Creates a grid with the specified x dimensions and shared memory size187* on the specified stream. The y and z dimensions are set to 1.188*189* @param gridDim190* the x dimension of the grid191* @param blockDim192* the x dimension of the thread block193* @param sharedMemBytes194* the number of bytes of shared memory to allocate to each thread block195* @param stream196* the stream on which the kernel should be queued197* (or null for the default stream)198*/199public CudaGrid(int gridDim, int blockDim, int sharedMemBytes,200CudaStream stream) {201super();202this.blockDimX = blockDim;203this.blockDimY = 1;204this.blockDimZ = 1;205this.gridDimX = gridDim;206this.gridDimY = 1;207this.gridDimZ = 1;208this.sharedMemBytes = sharedMemBytes;209this.stream = stream;210}211}212213214