Sha256: 0e3bf5d2fc179875c4b23807cb1a5eba1dbde8245dac176ba404fe5b2f6a7fed
Contents?: true
Size: 797 Bytes
Versions: 20
Compression:
Stored size: 797 Bytes
Contents
// First naive implementation % c_dtype = dtype_to_c_type(dtype) __kernel void log_softmax_<%= dtype %>(const int N, const __global <%= c_dtype %>* A, __global <%= c_dtype %>* C) { // Get the index of the current element to be processed const int globalRow = get_global_id(0); // Row ID of C (0..M) // Compute a single element (loop over K) <%= c_dtype %> acc = 0.0f; <%= c_dtype %> max = <%= min_value_for(dtype) %>; for (int k=0; k<N; k++) { max = A[globalRow*N + k] > max ? A[globalRow*N + k] : max; } for (int k=0; k<N; k++) { acc += exp(A[globalRow*N + k] - max); } // Store the result for (int k=0; k < N; k++) { C[globalRow*N + k] = (A[globalRow*N + k] - max) - log(acc); } }
Version data entries
20 entries across 20 versions & 2 rubygems