import torch
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.triton_helpers import math as tl_math
import math
assert_size_stride = torch._C._dynamo.guards.assert_size_stride
empty_strided_cuda = torch._C._dynamo.guards._empty_strided_cuda


@triton.jit
def triton_per_fused_add_log_mean_mul_neg_rsub_sigmoid_sub_sum_0(in_out_ptr0,
    in_ptr0, out_ptr0, xnumel, rnumel, XBLOCK: tl.constexpr):
    RBLOCK: tl.constexpr = 4
    xoffset = tl.program_id(0) * XBLOCK
    xoffset + tl.arange(0, XBLOCK)[:, None]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    rindex = tl.arange(0, RBLOCK)[None, :]
    tl.full([XBLOCK, RBLOCK], True, tl.int1)
    r0 = rindex
    tmp0 = tl.load(in_ptr0 + r0, None)
    tmp1 = tl.sigmoid(tmp0)
    tmp2 = -tmp1
    tmp3 = tl_math.log(tmp1)
    tmp4 = tmp2 * tmp3
    tmp5 = 1.0
    tmp6 = tmp5 - tmp1
    tmp7 = tl_math.log(tmp6)
    tmp8 = tmp6 * tmp7
    tmp9 = tmp4 - tmp8
    tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])
    tmp12 = tl.sum(tmp10, 1)[:, None]
    tmp13 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])
    tmp15 = tl.sum(tmp13, 1)[:, None]
    tmp16 = 4.0
    tmp17 = tmp12 / tmp16
    tmp18 = 0.5
    tmp19 = tmp15 * tmp18
    tmp20 = tmp17 + tmp19
    tl.store(out_ptr0 + tl.broadcast_to(r0, [XBLOCK, RBLOCK]), tmp1, None)
    tl.debug_barrier()
    tl.store(in_out_ptr0 + tl.full([XBLOCK, 1], 0, tl.int32), tmp20, None)


def call(args):
    primals_1, = args
    args.clear()
    assert_size_stride(primals_1, (1, 4), (4, 1))
    with torch.cuda._DeviceGuard(0):
        torch.cuda.set_device(0)
        buf0 = empty_strided_cuda((1, 4), (4, 1), torch.float32)
        buf1 = empty_strided_cuda((), (), torch.float32)
        buf3 = buf1
        del buf1
        get_raw_stream(0)
        triton_per_fused_add_log_mean_mul_neg_rsub_sigmoid_sub_sum_0[grid(1)](
            buf3, primals_1, buf0, 1, 4, XBLOCK=1, num_warps=2, num_stages=1)
        del primals_1
    return buf0, buf3, buf0


class AbstractTorchModule(torch.nn.Module):

    def __init__(self):
        torch.nn.Module.__init__(self)

    def save(self, path):
        None
        torch.save(self.state_dict(), path)

    def load(self, path):
        None
        self.load_state_dict(torch.load(path, map_location=self.device))

    def set_device(self, device):
        self.device = device
        self


class GNNExplainerProbeNew(AbstractTorchModule):

    def __init__(self, num_edges, num_layers, init_strategy='normal',
        const_val=1.0):
        super(GNNExplainerProbeNew, self).__init__()
        mask = torch.empty((num_layers, num_edges))
        if init_strategy == 'normal':
            std = torch.nn.init.calculate_gain('relu') * math.sqrt(2.0 / (2 *
                math.sqrt(num_edges)))
            with torch.no_grad():
                mask.normal_(1.0, std)
        elif init_strategy == 'const':
            torch.nn.init.constant_(mask, const_val)
        self.mask = torch.nn.Parameter(mask)

    def forward(self):
        primals_1 = self.mask
        output = call([primals_1])
        return output[0], output[1]


Measured latency_ms: 0.015894