6 Example of FFI extension I started from:
8 https://github.com/pytorch/extension-ffi.git
10 There is this tutorial
12 https://github.com/pytorch/tutorials/blob/master/Creating%20Extensions%20using%20FFI.md
14 And TH's Tensor definition are here in my install:
16 anaconda3/lib/python3.5/site-packages/torch/lib/include/TH/generic/THTensor.h
22 int generate_sequence(THByteTensor *output) {
23 long nb_sequences = 1;
24 long nb_images_per_sequence = 5;
30 int c, k, i, j, st0, st1, st2, st3, st4;
32 THByteTensor_resize5d(output, nb_sequences, nb_images_per_sequence, depth, height, width);
34 st0 = THByteTensor_stride(output, 0);
35 st1 = THByteTensor_stride(output, 1);
36 st2 = THByteTensor_stride(output, 2);
37 st3 = THByteTensor_stride(output, 3);
38 st4 = THByteTensor_stride(output, 4);
41 THByteTensor_storage(output)->data + THByteTensor_storageOffset(output);
43 for(s = 0; s < nb_sequences; s++) {
44 unsigned char result[nb_images_per_sequence * depth * width * height];
45 unsigned char *r = result;
46 fl_generate_sequences(1, nb_images_per_sequence, width, height, result);
47 for(k = 0; k < nb_images_per_sequence; k++) {
48 for(c = 0; c < depth; c++) {
49 for(i = 0; i < height; i++) {
51 + s * st0 + k * st1 + c * st2 + i * st3;
52 for(j = 0; j < width; j++) {
53 *b = (unsigned char) (*r);