Skip to content

Commit 57705fc

Browse files
committed
Minor fixed
1 parent 297f0cf commit 57705fc

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ For some examples on Python interface, see tests/python.
2222
- **Python Interface**: Seamless integration via Boost.Python
2323
- **Clean Architecture**: Modular design, maintainable and extensible
2424
- **CI/CD**: Automated testing with GTest and GitHub Actions
25+
- **CUDA implementation**: Full end-to-end CUDA implementation for better HW utilization (optimization in progress)
2526

2627
## Tech Stack
2728

src/backend/module/activation_functions/cuda/activations.cu

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ namespace cuda_impl {
330330

331331
// TODO: use some static struct here to prevent this guy from keeping on re-allocating memory
332332
ftype* maxValues;
333-
const tensorSize_t nMaxValues = nStrides;
334-
cudaErrchk(cudaMalloc(&maxValues, nMaxValues * sizeof(ftype)));
333+
cudaErrchk(cudaMalloc(&maxValues, nStrides * sizeof(ftype)));
335334

336335
static const auto warpSizeT2 = 2 * DeviceProperties::getWarpSize(); // TODO: can this be a problem in a multi-GPU setting?
337336
if(stride <= warpSizeT2) {
@@ -340,7 +339,7 @@ namespace cuda_impl {
340339
const int threadsPerBlock = 256;
341340
const int blocks = (in.getSize() + threadsPerBlock - 1) / threadsPerBlock;
342341

343-
if(stride == 2) {
342+
if(stride <= 2) {
344343
findMaxKernelOneWarp<1> <<<blocks, threadsPerBlock, threadsPerBlock * sizeof(ftype)>>>(maxValues, in.getData(), stride, in.getSize());
345344
}
346345
else if(stride <= 4) {

src/backend/shared/cuda/common_softmax.cuh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,17 @@ namespace cuda_impl {
6868
static __global__ void findMaxKernelOneWarp(ftype* const res, const ftype* const input, const tensorSize_t stride, const tensorSize_t size) {
6969
assert(blockDim.x % 32 == 0);
7070

71-
int gid = blockIdx.x * blockDim.x + threadIdx.x;
72-
if(gid >= size)
73-
return;
74-
75-
int tid = threadIdx.x;
71+
const int tid = threadIdx.x;
72+
const int gid = blockIdx.x * blockDim.x + threadIdx.x;
73+
const bool isNotPadded = gid < size;
7674
extern __shared__ ftype smem[];
77-
smem[tid] = input[gid];
75+
smem[tid] = isNotPadded ? input[gid] : -INFINITY;
7876
__syncthreads();
7977

78+
if(!isNotPadded) {
79+
return;
80+
}
81+
8082
volatile ftype* const start = smem + (tid / stride) * stride;
8183
const int offset = gid % stride;
8284
warpMaxReduce<maxoffset>(start, stride, offset);

0 commit comments

Comments
 (0)