common.cuh 1.6 KB
Newer Older
1 2 3 4
/**
 * \file dnn/src/cuda/warp_perspective/common.cuh
 * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
 *
5
 * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
6 7 8 9 10 11
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 */
#pragma once
12
#include "src/cuda/utils.cuh"
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

namespace megdnn {
namespace cuda {
namespace warp_perspective {

__device__ inline float sqr(float x)
{
    return x * x;
}

__device__ inline int mod(int i, int n)
{
    i %= n;
    i += (i < 0) * n;
    return i;
}

class ReplicateGetter {
    public:
        __device__ int operator()(int i, int n)
        {
            return min(max(i, 0), n-1);
        }
};

class ReflectGetter {
    public:
        __device__ int operator()(int i, int n)
        {
            n <<= 1;
            i = mod(i, n);
            return min(i, n-1-i);
        }
};

class Reflect101Getter {
    public:
        __device__ int operator()(int i, int n)
        {
            n = (n-1)<<1;
            i = mod(i, n);
            return min(i, n-i);
        }
};

class WrapGetter {
    public:
        __device__ int operator()(int i, int n)
        {
            i = mod(i, n);
            return i;
        }
};

67 68 69 70 71 72 73 74
class ConstGetter {
    public:
        __device__ int operator()(int i, int n)
        {
            return i;
        }
};

75 76 77 78 79 80
} // namespace warp_perspective
} // namespace cuda
} // namespace megdnn

// vim: syntax=cpp.doxygen