messages
listlengths
2
230
[ { "role": "user", "content": "Implement a fused matrix addition and scaling kernel.\n\nYour implementation should:\n1. Compute C = (A + B) * scale for square matrices\n2. Use a 2D grid/block layout similar to the seed matrix multiplication kernel\n3. Support any square matrix dimensions\n4. Properly handle ...
[ { "role": "user", "content": "Implement a fused set-union-and-scale kernel that:\n1. Computes the union of two sorted integer arrays A and B\n2. Scales each unique element by a given factor\n\nThe algorithm should:\n- Merge elements from arrays A and B in sorted order\n- Keep duplicates (like thrust::set_un...
[ { "role": "user", "content": "Implement a CUDA kernel that applies an exponential growth transformation and value clamping to each element.\n\nThe kernel should:\n1. For each element, compute a growth value using: growth = weight * (2.0 * exp(-(input[i] - mu)^2 / sigma^2) - 1.0)\n2. Add the growth to the co...
[ { "role": "user", "content": "Implement a row-wise minimum finder kernel that finds both the minimum value\nand its column index for each row in a 2D float array.\n\nYour implementation should:\n1. Use CUB's BlockReduce with ArgMin reducer to find column-wise minima\n2. Launch with one block per row (2D gri...
[ { "role": "user", "content": "Implement a broadcast addition operation that adds two tensors with different shapes.\n\nGiven two tensors:\n- x: shape [x_dim0, 1] (column vector)\n- y: shape [y_dim0, dim1] (2D matrix)\n- output: shape [x_dim0, dim1]\n\nThe operation broadcasts x along dimension 1 and broadca...
[ { "role": "user", "content": "Implement a CUDA kernel that counts the number of pairwise absolute differences\nbetween two arrays that exceed a given threshold.\n\nFor arrays A and B of size n, compute the count of indices i where |A[i] - B[i]| > threshold.\n\nYour implementation should:\n1. Use grid stride...
[ { "role": "user", "content": "Compute a matrix of pairwise squared Euclidean distances between two sets of 2D points.\n\nGiven M points in set A and N points in set B, compute an MxN distance matrix\nwhere each element (i,j) contains the squared Euclidean distance:\n\n distances[i * N + j] = (A[i].x - B[j]...
[ { "role": "user", "content": "Implement a vector addition with scaling kernel. The kernel should add two input vectors element-wise and multiply the result by a scalar factor.\n\nYour function signature is in include/solution_header.h.\n\nRequirements:\n1. Use a 1D grid with configurable block size (e.g., 2...
[ { "role": "user", "content": "Implement a partitioned prefix sum with chunk index mapping.\n\nYour implementation should:\n1. Compute prefix sum (cumulative sum) on the input array: prefix_sum[i] = sum(input[0..i])\n2. For each element, compute which chunk it belongs to: chunk_ids[i] = i / chunk_size\n3. Us...
[ { "role": "user", "content": "Implement scaled dot-product attention, a core operation in transformer models.\n\nYour implementation should:\n1. Compute attention scores: scores[query_row][key_col] = scale * dot(Q[query_row], K[key_col])\n2. Compute softmax: attn[query_row][key_col] = exp(scores[query_row][...
[ { "role": "user", "content": "Implement a CUDA kernel that computes the row-wise minimum of a matrix.\n\nGiven an M x N matrix, compute an output array of size M where each element\noutput[i] is the minimum value in row i of the input matrix.\n\nYour function signature is in include/solution_header.h.\n\n##...
[ { "role": "user", "content": "Implement a cumulative maximum computation with position tracking.\n\nGiven a sequence of floating-point numbers, compute the cumulative maximum\nfrom the beginning up to each position, along with the index where each\ncumulative maximum was first attained.\n\nFor input [x0, x1...
[ { "role": "user", "content": "Implement a conditional vector addition kernel with threshold counting.\n\nYour kernel should:\n1. Add two double-precision vectors element-wise: C[i] = A[i] + B[i]\n2. Use atomicAdd to count how many results exceed a given threshold\n3. Store the count in a counter variable\n\...
[ { "role": "user", "content": "Implement a kernel that raises each element of a matrix to a power equal to its row index.\n\nFor a matrix with M rows and N columns:\n- Row 0 remains unchanged\n- Row 1: elements raised to power 2 (x^2)\n- Row 2: elements raised to power 3 (x^3)\n- ... \n- Row i: elements rais...
[ { "role": "user", "content": "Implement an indexed complex number negation kernel.\n\nFor each index i in the indices array, negate a complex number from the input\narray and write it to the gains array at position indices[i]. Both gains and\ninput store complex numbers as interleaved [real, imag] pairs.\n\...
[ { "role": "user", "content": "Implement a CUDA kernel that applies a position-dependent Gaussian weight to each element of a 2D square matrix.\n\nThe weight for element (i, j) is computed as:\n weight = exp(-((i - center_y)^2 + (j - center_x)^2) / sigma^2)\n\nThe output[i][j] = input[i][j] * weight\n\nYour...
[ { "role": "user", "content": "Implement a fused element-wise scaling and reduction using CUDA dynamic parallelism.\n\nYour kernel should:\n1. Scale each element of the input array by multiplying by the scale factor\n2. Compute the sum of all scaled elements using recursive reduction with dynamic parallelism...
[ { "role": "user", "content": "Implement a kernel that computes per-label RGB statistics with spatial weighting.\n\nFor each pixel in an image, given its label, you need to compute:\n- Weighted sum of RGB values for pixels belonging to each label\n- Count of pixels per label\n\nThe spatial weight for a pixel...
[ { "role": "user", "content": "Implement a batched vector operation that scales each element by a per-element scale factor, then applies sigmoid activation.\n\nYour kernel should:\n1. Launch with one block per batch element\n2. Each thread computes: output[b][i] = sigmoid(input[b][i] * scale[i])\n3. Use thre...
[ { "role": "user", "content": "Implement a sigmoid activation kernel for half-precision (FP16) data.\n\nCompute the element-wise sigmoid function: output[i] = 1.0f / (1.0f + exp(-input[i]))\n\nRequirements:\n1. Use CUDA half-precision (half) data types from cuda_fp16.h\n2. Launch an appropriate grid of threa...
[ { "role": "user", "content": "Implement a selective sigmoid activation kernel that applies the sigmoid function\nonly to array elements within specified bounding regions.\n\nFor each input array element:\n- If the element's index lies within ANY of the provided bounding boxes (defined by\n start and end in...
[ { "role": "user", "content": "Implement an FP16 (half precision) kernel that computes Euclidean distances\nfrom a query point to a set of 3D positions.\n\nYour implementation should:\n1. Read positions as half3 structs from device memory\n2. Compute Euclidean distance: sqrt((x-xq)^2 + (y-yq)^2 + (z-zq)^2)\n...
[ { "role": "user", "content": "Implement a 1D convolution kernel that uses FP16 (half-precision) arithmetic.\n\nThe kernel should:\n- Convolve an input signal with a symmetric mask/kernel\n- Use __half data type for accumulation (__hfma intrinsic)\n- Handle boundary conditions by treating out-of-bounds input...
[ { "role": "user", "content": "Implement a 2D max pooling operation for 4D tensors in NCHW format.\n\nYour kernel should:\n1. Process non-overlapping 2x2 windows across height and width dimensions\n2. Output both the maximum value per window AND the flattened index of that max element\n3. Handle batch dimens...
[ { "role": "user", "content": "Implement a scaled distance matrix kernel using FP16 (half precision).\n\nGiven two matrices A [m, k] and B [n, k], compute the L2 Euclidean distance\nbetween each row of A and each row of B, then scale each distance by a\ncorresponding weight from the weights vector [n]. The r...
[ { "role": "user", "content": "Implement matrix transpose using pitched memory.\n\nYour implementation should:\n1. Write a CUDA kernel that transposes a matrix: output[j][i] = input[i][j]\n2. Handle matrices allocated with cudaMallocPitch (non-contiguous row storage)\n3. Use pitch parameters to correctly ind...
[ { "role": "user", "content": "Implement a fused matrix multiplication-add-scale operation.\n\nCompute D = gamma * (alpha * (A * B) + beta * C), where A is MxN,\nB is NxP, C and D are MxP.\n\nYour implementation should:\n1. Use a 2D grid with 16x16 thread blocks for parallel computation\n2. Perform the matri...
[ { "role": "user", "content": "Implement an exponential element-wise operation with clipping for multi-channel data.\n\nYour implementation should:\n1. Apply exponential function: exp(intensity * input element)\n2. Clip each output value to [clip_min, clip_max]\n3. Process a 3D tensor with dimensions (height...
[ { "role": "user", "content": "Implement a tiled vector add-and-scale kernel using FP16 (half precision).\n\nThe kernel should perform element-wise addition of two half-precision arrays\nA and B, then multiply the result by a scale factor. The implementation should\nuse shared memory tiling to coalesce globa...
[ { "role": "user", "content": "Implement a batched 3D Euclidean distance computation kernel.\n\nFor each batch, compute the Euclidean distance between each query point\nand each point in the point cloud. Given:\n- points: shape [batch_size, num_points, 3] - 3D point cloud per batch\n- queries: shape [batch_s...
[ { "role": "user", "content": "Implement a fused matrix multiplication with row-wise scaling kernel using FP16 (half precision).\n\nYour implementation should:\n1. Compute C = A * B where A and B are n x n matrices\n2. Apply row-wise scaling: each row i of C is multiplied by scale[i]\n3. Use tiling with shar...
[ { "role": "user", "content": "Implement a function that captures a simple element-wise addition kernel into a CUDA graph,\ninstantiates the graph, and executes it using CUDA Graph APIs.\n\nYour implementation should:\n1. Create a CUDA stream\n2. Begin stream capture with cudaStreamBeginCapture using cudaStr...
[ { "role": "user", "content": "Implement a 2D grid bitonic sort that sorts each row of a 2D array independently in ascending order.\n\nYour implementation should:\n1. Use shared memory to perform bitonic sort on each row\n2. Launch one block per row, with threads handling pairwise comparisons\n3. Sort each r...
[ { "role": "user", "content": "Implement a matrix multiplication kernel with row-wise random scaling.\n\nYour implementation should:\n1. Compute C = A @ B (standard matrix multiplication) for matrices of size MxK, KxN, MxN\n2. Apply a unique random scale factor (0.5 to 1.5) to each row of the output matrix C...
[ { "role": "user", "content": "Implement a kernel that performs row-wise scaling on a matrix: for each row,\nthe kernel first finds the maximum absolute value in that row, then scales each\nelement by (1.0 - alpha / max_abs). This operation progressively reduces each\nelement based on its row's maximum value...
[ { "role": "user", "content": "Implement a 2D weighted averaging kernel for a grid of floating point values.\nThe kernel computes for each interior point:\noutput[i,j] = center_weight * input[i,j] + \n neighbor_weight * (input[i-1,j] + input[i+1,j] + input[i,j-1] + input[i,j+1])\nBoundary points...
[ { "role": "user", "content": "Implement a device-aware vector addition that dynamically selects an appropriate CUDA device.\n\nYour implementation should:\n1. Query all available CUDA devices using cudaGetDeviceCount and cudaGetDeviceProperties\n2. Select the first device with compute capability major versi...
[ { "role": "user", "content": "Implement a parallel dot product kernel using warp shuffle reduction.\n\nYour implementation should:\n1. Compute the dot product of two vectors: result = sum(a[i] * b[i]) for i in [0, n)\n2. Use warp shuffle operations (__shfl_xor or __shfl_xor_sync) for efficient intra-warp re...
[ { "role": "user", "content": "Implement a fused 2D max pooling with element-wise ReLU operation.\n\nThe kernel should:\n1. Perform max pooling over a sliding window (kernel_h x kernel_w)\n2. Apply ReLU activation to the pooled result: max(0, pooled_value)\n3. Use strided access: stride_h for rows, stride_w ...
[ { "role": "user", "content": "Implement a tiled matrix subtraction kernel that also extracts elements at specific monitor point positions.\n\nYour implementation should:\n1. Compute C = A - B for M x N matrices using shared memory tiling (32x32 blocks)\n2. Extract elements from C at monitor point positions ...
[ { "role": "user", "content": "Implement a vector sigmoid activation function kernel.\n\nYour implementation should:\n1. Compute sigmoid(x) = 1/(1 + exp(-x)) for each element\n2. Use GPU kernel with proper threadIdx/blockIdx indexing\n3. Include boundary checking for arbitrary vector sizes\n4. Handle FP32 in...
[ { "role": "user", "content": "Implement matrix element-wise addition: C = A + B.\n\nYour task:\n1. Launch a CUDA kernel that computes C[i] = A[i] + B[i] for all i\n2. Use 256 threads per block\n3. Calculate the number of blocks needed based on the matrix size\n4. Handle the case where total elements is not ...
[ { "role": "user", "content": "Implement an element-wise affine transformation kernel for matrices.\n\nYour implementation should:\n1. Apply y = x * scale + bias to each element in the matrix\n2. Accept transformation parameters via an AffineParams struct (scale, bias)\n3. Operate on FP32 matrices\n4. Handle...
[ { "role": "user", "content": "Implement an integer matrix multiplication kernel. The kernel should compute\nC = A * B where A is M x K, B is K x N, and C is M x N.\nYour function signature is in include/solution_header.h.\n\nImportant requirements:\n- Handle boundary conditions properly (threads may be laun...
[ { "role": "user", "content": "Implement a row-wise recursive reduction kernel for summing each row of a matrix.\n\nYour implementation should:\n1. Use recursive reduction pattern within each row (divide-and-conquer)\n2. Process each row independently using shared memory\n3. Support power-of-2 column sizes u...
[ { "role": "user", "content": "Implement a parallel multi-stream tree reduction kernel that sums all node values\nacross multiple independent trees distributed across multiple CUDA streams.\n\nYour implementation should:\n1. Process multiple trees in parallel across multiple CUDA streams\n2. For each tree, r...
[ { "role": "user", "content": "Implement a 3D stencil kernel that computes a weighted average for each interior point.\nYour function signature is in include/solution_header.h.\n\nFor each interior point (not on the boundary), compute:\n1. Average of its 6 neighbors: (up + down + left + right + front + back)...
[ { "role": "user", "content": "Implement a fused element-wise kernel that performs multiply-add-clip operation on vectors.\n\nGiven three input vectors A, B, C, and output vector D, compute:\nD[i] = clamp(A[i] * B[i] + C[i], min_val, max_val)\n\nWhere clamp(x, min_val, max_val) ensures min_val <= x <= max_va...
[ { "role": "user", "content": "Implement a CUDA kernel that computes squares of array elements and finds the maximum value atomically.\n\nYour implementation should:\n1. Launch a kernel that computes output[i] = input[i] * input[i] for all elements\n2. Use atomicMax to track the maximum squared value across ...
[ { "role": "user", "content": "Implement a normalized sum add kernel that computes the element-wise average \nof multiple input arrays.\n\nYour implementation should:\n1. Sum elements across multiple input arrays at each index\n2. Normalize (divide) the sum by the number of inputs to compute the average\n3. ...
[ { "role": "user", "content": "Implement a Swish activation function kernel.\n\nSwish is defined as: swish(x) = x * sigmoid(x) = x / (1 + exp(-x))\n\nYour kernel should:\n- Take an input array and produce an output array of the same size\n- Each element should compute: output[i] = input[i] / (1 + exp(-input[...
[ { "role": "user", "content": "Implement a pointer chain trace kernel that follows a sequence of index pointers.\n\nGiven an input array where each element contains an index to another element,\nyour kernel should trace through this pointer chain for a specified number of steps.\n\nFor each thread i:\n1. Sta...
[ { "role": "user", "content": "Implement a matrix normalization kernel that computes row-wise means \nand subtracts them from each element. For each row, compute the mean value\nof all elements in that row, then subtract this mean from each element.\n\nUse shared memory for efficient parallel reduction when ...
[ { "role": "user", "content": "Implement a weighted outer product accumulation kernel that computes:\n\nFor each output matrix element (i, j):\n output[i][j] = accumulated ? existing_value + sum(weights[k] * input[k][i] * input[k][j]) : sum(...)\n\nwhere:\n- output is an M x M matrix\n- input is N vectors, ...
[ { "role": "user", "content": "Implement a strided matrix transpose kernel that transposes a matrix with\narbitrary row stride.\n\nYour kernel should:\n1. Handle arbitrary input row stride (input_stride >= cols)\n2. Transpose a rows x cols matrix to cols x rows matrix\n3. Use thread indexing and boundary che...
[ { "role": "user", "content": "Implement an odd-even transposition sort kernel for half-precision (FP16) data.\n\nThe odd-even sort algorithm works by performing alternating odd and even passes:\n- Odd pass: Compare and swap elements at indices (0,1), (2,3), (4,5), ...\n- Even pass: Compare and swap elements...
[ { "role": "user", "content": "Implement a multi-statistic reduction kernel that computes four statistics\nin a single kernel pass: sum, sum of squares, minimum, and maximum.\n\nThe kernel should:\n1. Use shared memory for block-level reduction\n2. Combine two elements per thread (strided loop pattern)\n3. U...
[ { "role": "user", "content": "Implement a point cloud nearest neighbor distance kernel.\n\nYour implementation should:\n1. For each point in cloud A, find the nearest point in cloud B by Euclidean distance\n2. Store the index of the nearest point from cloud B for each point in cloud A\n3. Process 3D points ...
[ { "role": "user", "content": "Implement a batch element-wise scaling kernel that multiplies each element of a float array by a scalar.\nThe function signature is in include/solution_header.h.\n\nYour kernel should:\n- Process the input array in parallel using grid-stride loops\n- Use the same thread indexin...
[ { "role": "user", "content": "Implement a kernel that fills an array with ordinal values (0, 1, 2, ..., n-1).\n\nEach thread should write its global index to the output array.\nA common pattern for this uses blockIdx.x, blockDim.x, and threadIdx.x\nto compute the global thread index.\n\nThe function signatu...
[ { "role": "user", "content": "Implement a kernel that computes channel-wise sum and variance for a 3-channel\nimage using warp primitives. The kernel should process NHWC formatted data.\n\nRequirements:\n1. Use warp shuffle operations (__shfl_down_sync) for efficient reduction\n2. Compute both sum and varia...
[ { "role": "user", "content": "Implement a masked element scaling kernel that selectively multiplies matrix elements\nby a scale factor based on a binary mask.\n\nYour kernel should:\n1. Load input matrix elements and corresponding mask values\n2. Apply scaling only where mask is non-zero: output[i] = input[...
[ { "role": "user", "content": "Implement a matrix row sum kernel using FP16 (half-precision) data types.\n\nYour implementation should:\n1. Sum each row of the input matrix into a 1D output vector\n2. Use FP16 arithmetic for computations\n3. Use shared memory for efficient reduction (pattern similar to paral...
[ { "role": "user", "content": "Query CUDA device properties and compute derived capabilities.\n\nGiven a device index, implement query_device_capabilities() to populate\na DeviceCapabilities struct with:\n- global_memory_mb: Total global memory in megabytes (float)\n- compute_capability: Compute capability a...
[ { "role": "user", "content": "Implement an indexed parallel reduction with accumulator.\n\nYour implementation should:\n1. Read values from array A using an index mapping: A[index[i]]\n2. Perform a parallel reduction using shared memory (similar to File 1's reduce2)\n3. Each block writes its partial sum to ...
[ { "role": "user", "content": "Implement a kernel that performs element-wise addition on two float arrays while simultaneously\nadding two unsigned integer arrays (limbs) with carry propagation.\n\nFunction signature is in include/solution_header.h.\n\nRequirements:\n- For float arrays: compute result[i] = a...
[ { "role": "user", "content": "Implement a broadcast-threshold-reduce CUDA kernel that:\n1. Broadcasts a smaller input array (size N) into a larger output array (size M)\n2. Compares each element against a threshold\n3. Reduces the count of elements exceeding the threshold using shared memory\n4. Writes the ...
[ { "role": "user", "content": "Implement a multi-binned weighted reduction kernel.\n\nGiven an input array of values and bin indices, compute bin accumulations where each\nelement contributes to its primary bin with weight 1.0, and to adjacent bins (mod num_bins)\nwith weight 0.5. This tests atomic operation...
[ { "role": "user", "content": "Implement a kernel that computes the sum of values from a base data array using indexed offsets.\nFor each index i in [0, num_indices), read base_data[indices[i] * granularity] and sum all values.\n\nUse warp-level reduction primitives to efficiently accumulate the sum across t...
[ { "role": "user", "content": "Implement a fused CUDA kernel that performs element-wise matrix scaling followed by row-wise bias addition.\n\nYour kernel should:\n1. Scale each element of an m×n matrix by a scale parameter\n2. Add a bias vector of size m to each corresponding row of the scaled matrix\n3. For...
[ { "role": "user", "content": "Implement a conditional vector scalar operation kernel.\n\nFor each element in the input vector:\n- If the value is >= threshold, multiply by scale_factor\n- If the value is < threshold, add add_value\n\nThe kernel should:\n1. Use the standard threadIdx/blockIdx indexing patter...
[ { "role": "user", "content": "Implement a fused matrix multiplication and variance computation kernel.\n\nYour implementation should:\n1. Compute matrix multiplication: for each output element C[i,j], compute the dot product\n of row i of matrix A and row j of matrix B: C[i,j] = sum_k (A[i,k] * B[j,k])\n2...
[ { "role": "user", "content": "Implement a peer-to-peer memory copy between two CUDA devices with compute capability checking.\n\nYour implementation should:\n1. Query device properties for both device 0 and device 1 using cudaGetDeviceProperties\n2. Check that both devices have compute capability >= 7.0\n3....
[ { "role": "user", "content": "Implement a conditional element negation kernel that negates values in an input array \nonly when they exceed a threshold value. This kernel should efficiently handle \narbitrary array sizes using optimal launch configuration with 512 threads per block.\n\n## Environment Instru...
[ { "role": "user", "content": "Implement a tiled matrix multiplication kernel using shared memory.\n\nYour implementation should:\n1. Use 2D tiling to load matrix blocks into shared memory\n2. Process matrix multiplication in tiles of size `tile_size x tile_size`\n3. Handle matrices that are not evenly divis...
[ { "role": "user", "content": "Implement the Swish activation function kernel.\n\nSwish is defined as: swish(x) = x * sigmoid(x) = x / (1 + exp(-x))\n\nYour kernel should:\n1. Process all elements in parallel using a 1D grid-stride loop\n2. Handle input and output arrays on the GPU\n3. Use proper boundary ch...
[ { "role": "user", "content": "Implement matrix element-wise operations with scaling and sigmoid activation.\n\nYour implementation should provide three functions:\n1. matrixSigmoid: Apply sigmoid activation to each element of a matrix\n - For each element: output[i,j] = 1.0 / (1.0 + exp(-input[i,j]))\n\n2...
[ { "role": "user", "content": "Implement a kernel that finds the minimum value in each row of a 2D array.\n\nThe input is a [num_rows x num_cols] matrix stored in row-major order.\nThe output is a 1D array of size [num_rows] where output[row] = min(input[row, :]).\n\nYour kernel should:\n1. Process each row ...
[ { "role": "user", "content": "Implement a max pooling kernel that produces both pooled values and the indices of the max elements.\n\nYour implementation should:\n1. Process batches of 2D feature maps with multiple channels\n2. Support non-contiguous input tensors with arbitrary strides\n3. Compute the maxi...
[ { "role": "user", "content": "Implement a fused convolution-ReLU-scale operation using cuDNN.\n\nYour implementation should:\n1. Perform 2D convolution with NCHW layout\n2. Apply ReLU activation to convolution output\n3. Apply element-wise scaling per output channel\n4. Use cuDNN descriptors properly and av...
[ { "role": "user", "content": "Implement stochastic gradient descent with Gaussian noise injection.\n\nYour implementation should:\n1. Initialize curand states for parallel random number generation\n2. Apply SGD weight update: weight = weight - learning_rate * (gradient + noise)\n3. Generate noise ~ N(0, noi...
[ { "role": "user", "content": "Implement a weighted 1D stencil convolution with periodic boundary conditions.\n\nThe function computes: Output[i] = scale_factor * sum_{j=-radius to radius} input[i+j] * mask[j+radius]\n\nFor boundary positions where i-j or i+j is out of bounds, the indices wrap around\nusing ...
[ { "role": "user", "content": "Implement a barycentric interpolation kernel for triangle vertices.\n\nGiven an array of triangle vertices and random barycentric coordinates,\ncompute the interpolated point for each triangle using the formula:\n \n result = (1 - u - v) * v0 + u * v1 + v * v2\n\nwhere (u...
[ { "role": "user", "content": "Implement a weighted multi-channel pixel normalization kernel.\n\nGiven an input image with multiple channels (e.g., RGB), compute the weighted sum\nof pixel values across channels, then normalize the result to the [0, 1] range\nbased on a global maximum value. This is useful f...
[ { "role": "user", "content": "Implement a recursive parallel reduction to compute block sums.\n\nYour task is to implement `recursive_reduce` which:\n1. Partitions the input array into blocks of size `block_dim` (power of 2)\n2. Computes the sum of each partition using recursive reduction\n3. Writes each pa...
[ { "role": "user", "content": "Implement a function that sorts each row of a matrix independently using the odd-even sort algorithm.\n\nYour implementation should:\n1. Use a 2D grid configuration where each block processes one or more rows\n2. Apply odd-even sort within each row independently\n3. Coordinate ...
[ { "role": "user", "content": "Implement a multi-stage parallel reduction using ping-pong buffers and shared memory.\n\nThe function signature is:\n```cpp\nvoid ping_pong_reduction(\n const float* input,\n float* buffer1,\n float* buffer2,\n int size,\n int blockSize\n);\n```\n\nRequirements:\...
[ { "role": "user", "content": "Implement a stride-select sort kernel that selects every Nth element from an array\nand sorts those elements in ascending order.\n\nYour implementation should:\n1. Select elements from indices 0, stride, 2*stride, ... up to size\n2. Sort the selected elements using bitonic sort...
[ { "role": "user", "content": "Implement a 2D convolution kernel using shared memory tiling.\n\nYour implementation should:\n1. Use shared memory to load input tiles with padding for the kernel radius\n2. Load padding values (out-of-bounds) as zeros (replicate padding is not required)\n3. Compute convolution...
[ { "role": "user", "content": "Implement a fused bias addition followed by ReLU activation for a batched tensor.\n\nThe kernel should for each batch element compute:\n output[i, j] = ReLU(input[i, j] + bias[j])\n\nThis operation is a common pattern in neural networks where bias addition and ReLU\nare combin...
[ { "role": "user", "content": "Implement a histogram with collision detection kernel.\n\nGiven an input array of integers in the range [0, num_bins), count occurrences of each\nvalue and track how many times atomic operations on the same bin indicate simultaneous\nupdates (collisions).\n\nCollision detection...
[ { "role": "user", "content": "Implement a fused scaled vector addition kernel that computes:\n output[i] = input_a[i] + input_b[i] * scale_factor\n\nYour implementation should:\n- Use grid-striding loops to handle arbitrary input sizes efficiently\n- Ensure coalesced memory access patterns\n- Handle any nu...
[ { "role": "user", "content": "Implement a CUDA kernel that computes the dot product of packed 3D vectors.\n\nGiven two arrays containing packed 3D vectors (a and b), compute the dot\nproduct for each corresponding vector pair:\n\n result[i] = a[3*i] * b[3*i] + a[3*i+1] * b[3*i+1] + a[3*i+2] * b[3*i+2]\n\nR...
[ { "role": "user", "content": "Implement an adaptive variance-based pixel accumulation kernel for RGB color estimation.\n\nThe kernel processes a 2D image (width x height). For each pixel:\n1. Accumulate weighted random samples using a seed value\n2. Track luminance statistics (sum and sum of squares)\n3. Pe...
[ { "role": "user", "content": "Implement a matrix scaling kernel that computes C = alpha * A + beta * B.\n\nThe kernel should:\n- Use a 2D thread block configuration (32x16 threads per block)\n- Scale matrices of arbitrary dimensions (not restricted to powers of 2)\n- Apply proper boundary checking for edge ...
[ { "role": "user", "content": "Implement a matrix row-wise add and scale kernel.\n\nYour kernel should compute C[i][j] = scales[i] * (A[i][j] + B[i][j]) for all\nelements in the matrix, where each row has its own scaling factor.\n\nRequirements:\n1. Use 2D thread indexing with (block.x, block.y) and (thread....
[ { "role": "user", "content": "Implement a fused vector addition with scaling kernel.\n\nYour kernel should compute C[i] = scale * (A[i] + B[i]) for all elements.\n\nRequirements:\n1. Use 1D grid of thread blocks (blockIdx.x and threadIdx.x)\n2. Use 256 threads per block\n3. Include boundary checking (idx < ...
[ { "role": "user", "content": "Implement a histogram kernel using shared memory for efficient bin counting.\n\nYour implementation should:\n1. Use shared memory within each block for local histogram computation\n2. Use atomicAdd operations for thread-safe bin increments\n3. Use stride-based thread indexing (...
[ { "role": "user", "content": "Implement a matrix centering kernel that subtracts the column-wise mean from each element.\n\nFor an M x N matrix, compute the mean of each column and subtract it from all elements\nin that column. This combines reduction (computing column means) with element-wise operations\n(...
[ { "role": "user", "content": "Implement a fused scalar add-and-copy kernel for half-precision (FP16) data.\n\nYour implementation should:\n1. Add a scalar value to each element of the input array (FP16)\n2. Store results in a separate output array (not in-place)\n3. Use proper thread indexing with boundary ...