File: tile.cl

package info (click to toggle)
tiny-dnn 1.0.0a3%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,760 kB
  • sloc: cpp: 16,471; ansic: 11,829; lisp: 3,682; python: 3,422; makefile: 206
file content (39 lines) | stat: -rw-r--r-- 1,720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef __OPENCL_VERSION__
#include "header.cl"
#endif


__kernel void TEMPLATE(tile,Dtype)(const int_tp nthreads, __global const Dtype* bottom_data,
                                   const int_tp tile_size, const int_tp num_tiles,
                                   const int_tp bottom_tile_axis,
                                   __global Dtype* top_data) {
  for (int_tp index = get_global_id(0); index < nthreads;
      index += get_global_size(0)) {
    const int_tp d = index % tile_size;
    const int_tp b = (index / tile_size / num_tiles) % bottom_tile_axis;
    const int_tp n = index / tile_size / num_tiles / bottom_tile_axis;
    const int_tp bottom_index = (n * bottom_tile_axis + b) * tile_size + d;
    top_data[index] = bottom_data[bottom_index];
  }
}


__kernel void TEMPLATE(tile_backward,Dtype)(const int_tp nthreads,
                                            __global const Dtype* top_diff,
                                            const int_tp tile_size,
                                            const int_tp num_tiles,
                                            const int_tp bottom_tile_axis,
                                            __global Dtype* bottom_diff) {
  for (int_tp index = get_global_id(0); index < nthreads;
      index += get_global_size(0)) {
    const int_tp d = index % tile_size;
    const int_tp b = (index / tile_size) % bottom_tile_axis;
    const int_tp n = index / tile_size / bottom_tile_axis;
    bottom_diff[index] = 0;
    int_tp top_index = (n * num_tiles * bottom_tile_axis + b) * tile_size + d;
    for (int_tp t = 0; t < num_tiles; ++t) {
      bottom_diff[index] += top_diff[top_index];
      top_index += bottom_tile_axis * tile_size;
    }
  }
}