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
20 #include "sequence_generator.h"
22 int generate_sequence(long nb_sequences, THByteTensor *output) {
23 long nb_images_per_sequence = 5;
29 int c, k, i, j, st0, st1, st2, st3, st4;
31 THByteTensor_resize5d(output, nb_sequences, nb_images_per_sequence, depth, height, width);
33 st0 = THByteTensor_stride(output, 0);
34 st1 = THByteTensor_stride(output, 1);
35 st2 = THByteTensor_stride(output, 2);
36 st3 = THByteTensor_stride(output, 3);
37 st4 = THByteTensor_stride(output, 4);
40 THByteTensor_storage(output)->data + THByteTensor_storageOffset(output);
42 for(s = 0; s < nb_sequences; s++) {
43 unsigned char result[nb_images_per_sequence * depth * width * height];
44 unsigned char *r = result;
45 fl_generate_sequences(1, nb_images_per_sequence, width, height, result);
46 for(k = 0; k < nb_images_per_sequence; k++) {
47 for(c = 0; c < depth; c++) {
48 for(i = 0; i < height; i++) {
50 + s * st0 + k * st1 + c * st2 + i * st3;
51 for(j = 0; j < width; j++) {
52 *b = (unsigned char) (*r);