import torch
from torch._inductor.select_algorithm import extern_kernels
import triton
import triton.language as tl
from torch._inductor.runtime.triton_heuristics import grid
from torch._C import _cuda_getCurrentRawStream as get_raw_stream
from torch._inductor.runtime import triton_helpers
import torch.nn as nn
import torch.utils.data
import torch.nn.functional as F
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_poi_fused_index_0(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (x0 + 64 * x1), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_1(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 160
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x3 = xindex
    x1 = xindex // 4 % 10
    tmp0 = tl.load(in_out_ptr0 + x3, xmask)
    tmp1 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x3, tmp4, xmask)


@triton.jit
def triton_poi_fused_convolution_relu_2(in_out_ptr0, in_ptr0, xnumel,
    XBLOCK: tl.constexpr):
    xnumel = 40
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x2 = xindex
    x0 = xindex % 10
    tmp0 = tl.load(in_out_ptr0 + x2, xmask)
    tmp1 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp2 = tmp0 + tmp1
    tmp3 = tl.full([1], 0, tl.int32)
    tmp4 = triton_helpers.maximum(tmp3, tmp2)
    tl.store(in_out_ptr0 + x2, tmp4, xmask)


@triton.jit
def triton_poi_fused__to_copy_add_arange_mul_3(out_ptr0, xnumel, XBLOCK: tl
    .constexpr):
    xnumel = 4
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex
    tmp0 = x0
    tmp1 = tmp0.to(tl.float32)
    tmp2 = 0.25
    tmp3 = tmp1 * tmp2
    tmp4 = tmp3.to(tl.int32)
    tl.store(out_ptr0 + x0, tmp4, xmask)


@triton.jit
def triton_poi_fused_index_4(in_ptr0, out_ptr0, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x0 = xindex % 16
    x1 = xindex // 16
    x2 = xindex
    tmp0 = tl.load(in_ptr0 + (16 + x0 + 64 * x1), xmask)
    tl.store(out_ptr0 + x2, tmp0, xmask)


@triton.jit
def triton_poi_fused__unsafe_index_convolution_mul_sigmoid_5(in_ptr0,
    in_ptr1, in_ptr2, in_ptr3, in_ptr4, in_ptr5, in_ptr6, out_ptr0,
    out_ptr1, out_ptr2, out_ptr3, out_ptr4, xnumel, XBLOCK: tl.constexpr):
    xnumel = 64
    xoffset = tl.program_id(0) * XBLOCK
    xindex = xoffset + tl.arange(0, XBLOCK)[:]
    xmask = xindex < xnumel
    x1 = xindex // 4 % 4
    x0 = xindex % 4
    x2 = xindex // 16
    x3 = xindex
    tmp0 = tl.load(in_ptr0 + x1, xmask, eviction_policy='evict_last')
    tmp5 = tl.load(in_ptr0 + x0, xmask, eviction_policy='evict_last')
    tmp9 = tl.load(in_ptr1 + x2, xmask, eviction_policy='evict_last')
    tmp10 = tl.load(in_ptr2 + 0)
    tmp11 = tl.broadcast_to(tmp10, [XBLOCK])
    tmp13 = tl.load(in_ptr3 + x2, xmask, eviction_policy='evict_last')
    tmp14 = tl.load(in_ptr4 + 0)
    tmp15 = tl.broadcast_to(tmp14, [XBLOCK])
    tmp17 = tl.load(in_ptr5 + x3, xmask)
    tmp19 = tl.load(in_ptr6 + x3, xmask)
    tmp1 = tl.full([XBLOCK], 1, tl.int32)
    tmp2 = tmp0 + tmp1
    tmp3 = tmp0 < 0
    tl.where(tmp3, tmp2, tmp0)
    tmp6 = tmp5 + tmp1
    tmp7 = tmp5 < 0
    tl.where(tmp7, tmp6, tmp5)
    tmp12 = tmp9 + tmp11
    tmp16 = tmp13 + tmp15
    tmp18 = tl.sigmoid(tmp17)
    tmp20 = tl.sigmoid(tmp19)
    tmp21 = tl.sigmoid(tmp12)
    tmp22 = tl.sigmoid(tmp16)
    tmp23 = tmp21 * tmp22
    tmp24 = tmp23 * tmp18
    tmp25 = tmp24 * tmp20
    tl.store(out_ptr0 + x3, tmp12, xmask)
    tl.store(out_ptr1 + x3, tmp16, xmask)
    tl.store(out_ptr2 + x3, tmp18, xmask)
    tl.store(out_ptr3 + x3, tmp20, xmask)
    tl.store(out_ptr4 + x3, tmp25, xmask)


def call(args):
    (primals_1, primals_2, primals_3, primals_4, primals_5, primals_6,
        primals_7, primals_8, primals_9, primals_10, primals_11, primals_12,
        primals_13, primals_14, primals_15, primals_16, primals_17) = args
    args.clear()
    assert_size_stride(primals_1, (4, 4, 4, 4), (64, 16, 4, 1))
    assert_size_stride(primals_2, (10, 1, 5, 5), (25, 25, 5, 1))
    assert_size_stride(primals_3, (10,), (1,))
    assert_size_stride(primals_4, (10, 10, 5, 5), (250, 25, 5, 1))
    assert_size_stride(primals_5, (10,), (1,))
    assert_size_stride(primals_6, (10, 10, 5, 5), (250, 25, 5, 1))
    assert_size_stride(primals_7, (10,), (1,))
    assert_size_stride(primals_8, (1, 10, 5, 5), (250, 25, 5, 1))
    assert_size_stride(primals_9, (1,), (1,))
    assert_size_stride(primals_10, (10, 1, 5, 5), (25, 25, 5, 1))
    assert_size_stride(primals_11, (10,), (1,))
    assert_size_stride(primals_12, (10, 10, 5, 5), (250, 25, 5, 1))
    assert_size_stride(primals_13, (10,), (1,))
    assert_size_stride(primals_14, (10, 10, 5, 5), (250, 25, 5, 1))
    assert_size_stride(primals_15, (10,), (1,))
    assert_size_stride(primals_16, (1, 10, 5, 5), (250, 25, 5, 1))
    assert_size_stride(primals_17, (1,), (1,))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        get_raw_stream(0)
        triton_poi_fused_index_0[grid(64)](primals_1, buf0, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        buf1 = extern_kernels.convolution(buf0, primals_2, stride=(2, 2),
            padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf1, (4, 10, 2, 2), (40, 4, 2, 1))
        buf2 = buf1
        del buf1
        triton_poi_fused_convolution_relu_1[grid(160)](buf2, primals_3, 160,
            XBLOCK=128, num_warps=4, num_stages=1)
        del primals_3
        buf3 = extern_kernels.convolution(buf2, primals_4, stride=(2, 2),
            padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf3, (4, 10, 1, 1), (10, 1, 1, 1))
        buf4 = buf3
        del buf3
        triton_poi_fused_convolution_relu_2[grid(40)](buf4, primals_5, 40,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_5
        buf5 = extern_kernels.convolution(buf4, primals_6, stride=(2, 2),
            padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf5, (4, 10, 1, 1), (10, 1, 1, 1))
        buf6 = buf5
        del buf5
        triton_poi_fused_convolution_relu_2[grid(40)](buf6, primals_7, 40,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_7
        buf7 = extern_kernels.convolution(buf6, primals_8, stride=(1, 1),
            padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf7, (4, 1, 1, 1), (1, 1, 1, 1))
        buf8 = empty_strided_cuda((4,), (1,), torch.int64)
        triton_poi_fused__to_copy_add_arange_mul_3[grid(4)](buf8, 4, XBLOCK
            =4, num_warps=1, num_stages=1)
        buf10 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        triton_poi_fused_index_4[grid(64)](primals_1, buf10, 64, XBLOCK=64,
            num_warps=1, num_stages=1)
        del primals_1
        buf11 = extern_kernels.convolution(buf10, primals_10, stride=(2, 2),
            padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf11, (4, 10, 2, 2), (40, 4, 2, 1))
        buf12 = buf11
        del buf11
        triton_poi_fused_convolution_relu_1[grid(160)](buf12, primals_11, 
            160, XBLOCK=128, num_warps=4, num_stages=1)
        del primals_11
        buf13 = extern_kernels.convolution(buf12, primals_12, stride=(2, 2),
            padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf13, (4, 10, 1, 1), (10, 1, 1, 1))
        buf14 = buf13
        del buf13
        triton_poi_fused_convolution_relu_2[grid(40)](buf14, primals_13, 40,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_13
        buf15 = extern_kernels.convolution(buf14, primals_14, stride=(2, 2),
            padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf15, (4, 10, 1, 1), (10, 1, 1, 1))
        buf16 = buf15
        del buf15
        triton_poi_fused_convolution_relu_2[grid(40)](buf16, primals_15, 40,
            XBLOCK=64, num_warps=1, num_stages=1)
        del primals_15
        buf17 = extern_kernels.convolution(buf16, primals_16, stride=(1, 1),
            padding=(2, 2), dilation=(1, 1), transposed=False,
            output_padding=(0, 0), groups=1, bias=None)
        assert_size_stride(buf17, (4, 1, 1, 1), (1, 1, 1, 1))
        buf9 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        buf18 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        buf19 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        buf20 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        buf21 = empty_strided_cuda((4, 1, 4, 4), (16, 16, 4, 1), torch.float32)
        triton_poi_fused__unsafe_index_convolution_mul_sigmoid_5[grid(64)](buf8
            , buf7, primals_9, buf17, primals_17, buf0, buf10, buf9, buf18,
            buf19, buf20, buf21, 64, XBLOCK=64, num_warps=1, num_stages=1)
        del buf17
        del buf7
        del primals_17
        del primals_9
    return (buf21, primals_2, primals_4, primals_6, primals_8, primals_10,
        primals_12, primals_14, primals_16, buf0, buf2, buf4, buf6, buf8,
        buf9, buf10, buf12, buf14, buf16, buf18, buf19, buf20)


class FociDetector(nn.Module):

    def __init__(self, input_channels=3, input_size=17, ksize=5,
        hidden_channels=10):
        super(FociDetector, self).__init__()
        self.conv1 = nn.Conv2d(input_channels, hidden_channels, ksize,
            stride=2, padding=int((ksize - 1) / 2))
        self.conv2 = nn.Conv2d(hidden_channels, hidden_channels, ksize,
            stride=2, padding=int((ksize - 1) / 2))
        self.conv3 = nn.Conv2d(hidden_channels, hidden_channels, ksize,
            stride=2, padding=int((ksize - 1) / 2))
        self.finalmapsize = ksize
        self.convf = nn.Conv2d(hidden_channels, 1, self.finalmapsize,
            padding=int((ksize - 1) / 2))
        self.relu = nn.ReLU()

    def forward(self, x):
        output = self.relu(self.conv1(x))
        output = self.relu(self.conv2(output))
        output = self.relu(self.conv3(output))
        output = self.convf(output)
        return output


class MultiChannelCombinedScorerNew(nn.Module):

    def __init__(self, input_size=17, ksize=5, hidden_channels=10):
        super(MultiChannelCombinedScorerNew, self).__init__()
        self.channel1 = FociDetector(input_channels=1, input_size=
            input_size, ksize=ksize, hidden_channels=hidden_channels)
        self.channel2 = FociDetector(input_channels=1, input_size=
            input_size, ksize=ksize, hidden_channels=hidden_channels)

    def forward_vis(self, x):
        output1 = torch.sigmoid(F.interpolate(self.channel1(x[:, [0], :, :]
            ), size=(x.shape[2], x.shape[3])))
        output2 = torch.sigmoid(F.interpolate(self.channel2(x[:, [1], :, :]
            ), size=(x.shape[2], x.shape[3])))
        output3 = torch.sigmoid(x[:, [0], :, :])
        output4 = torch.sigmoid(x[:, [1], :, :])
        return output1, output2, output3, output4

    def forward(self, input_0):
        primals_2 = self.channel1.conv1.weight
        primals_3 = self.channel1.conv1.bias
        primals_4 = self.channel1.conv2.weight
        primals_5 = self.channel1.conv2.bias
        primals_6 = self.channel1.conv3.weight
        primals_7 = self.channel1.conv3.bias
        primals_8 = self.channel1.convf.weight
        primals_9 = self.channel1.convf.bias
        primals_10 = self.channel2.conv1.weight
        primals_11 = self.channel2.conv1.bias
        primals_12 = self.channel2.conv2.weight
        primals_13 = self.channel2.conv2.bias
        primals_14 = self.channel2.conv3.weight
        primals_15 = self.channel2.conv3.bias
        primals_16 = self.channel2.convf.weight
        primals_17 = self.channel2.convf.bias
        primals_1 = input_0
        output = call([primals_1, primals_2, primals_3, primals_4,
            primals_5, primals_6, primals_7, primals_8, primals_9,
            primals_10, primals_11, primals_12, primals_13, primals_14,
            primals_15, primals_16, primals_17])
        return output[0]


Measured latency_ms: 0.236213