Giter Site home page Giter Site logo

amirunpri2018 / pytorch-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sniklaus/pytorch-extension

0.0 1.0 0.0 25 KB

an example of a CUDA extension for PyTorch using CuPy which computes the Hadamard product of two tensors

License: GNU General Public License v3.0

Python 100.00%

pytorch-extension's Introduction

pytorch-extension

This is an example of a CUDA extension for PyTorch which uses CuPy to compute the Hadamard product of two tensors.

For a more advanced PyTorch extension that uses CuPy as well, please see: https://github.com/szagoruyko/pyinn

setup

Make sure to install CuPy, which can be done using pip install cupy or alternatively using one of the provided binary packages as outlined in the CuPy repository.

usage

There is no separate build process necessary, simply run python test.py to test it. A minimal example of how the sample extension can be used is also shown below.

import torch

import hadamard

class Network(torch.nn.Module):
	def __init__(self):
		super(Network, self).__init__()
	# end

	def forward(self, input1, input2):
		return hadamard.Hadamard()(input1, input2)
	# end
# end

net = Network().cuda()

input1 = torch.rand(64, 3, 128, 128).cuda()
input2 = torch.rand(64, 3, 128, 128).cuda()

input1 = input1.requires_grad_()
input2 = input2.requires_grad_()

output = net(input1, input2)
expected = torch.mul(input1, input2)

print(torch.sum(output.data - expected.data), '<-- should be 0.0')

license

Please refer to the appropriate file within this repository.

pytorch-extension's People

Contributors

sniklaus avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.