Value Clipping

106 字
1 分钟
Value Clipping

问题#

答案#

#include <cuda_runtime.h>
__global__ void clip_kernel(const float* input, float* output, float lo, float hi, int N) {
int idx = blockDim.x * blockIdx.x + threadIdx.x;
if (idx >= N) return;
if (input[idx] >= lo && input[idx] <= hi) {
output[idx] = input[idx];
} else if (input[idx] < lo) {
output[idx] = lo;
} else {
output[idx] = hi;
}
}
// input, output are device pointers
extern "C" void solve(const float* input, float* output, float lo, float hi, int N) {
int threadsPerBlock = 256;
int blocksPerGrid = (N + threadsPerBlock - 1) / threadsPerBlock;
clip_kernel<<<blocksPerGrid, threadsPerBlock>>>(input, output, lo, hi, N);
cudaDeviceSynchronize();
}
Value Clipping
https://dongyanzhang.com/posts/leetgpu/value-clipping/
作者
阿东阿言
发布于
2026-07-14
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
阿东阿言
I share my notes | projects | experience here...
公告
欢迎来到阿东阿言的博客
音乐
封面

音乐

暂未播放

0:000:00
暂无歌词
分类
标签
站点统计
文章
25
分类
3
标签
5
总字数
11,186
运行时长
0
最后活动
0 天前
站点信息
构建平台
Local
博客版本
v1.0.0
文章许可
CC BY-NC-SA 4.0