Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@BlGene
Copy link
Contributor

@BlGene BlGene commented Mar 8, 2017

This is an extension of caffe that enables the calling of Halide functions as layers.

To test it please.

  1. Install Halide
  2. build caffe using cmake with the BUILD_halide option
  3. run the short python script below

TODOs:

  • [build] fix make build

  • [build] add Halide to Travis + run layer tests
    The process of building layers is still quite elaborate and a lot of cmake code went into masking this complexity. That said I'm not a cmake expert, so I would greatly appreciate if others had a look at his too. The build server will have to updated to install Halide to tests to pass.

  • Make layer zoo?

Once useful Halide layers start cropping up it would be nice to have a designated place to put them, together with some information on usage.

Further work for this is on hold till after the ICCV deadline.


Some additional things worth considering:

  1. Halide Python Bindings
    Halide has python bindings which are a nicer user interface. Whats the cleanest way to provide access to these?

  2. Automatic Backward pass
    Automatic backward functions for Halide would make it much easier to use. There has been some chatter about implementing this, but I don't know the current state of this.

This is an extension of @longjon prior work.


Simple Test script

import time
import numpy as np
import caffe
from caffe import layers as L

INSTALL_DIR = "."
HEIGHT, WIDTH = 200, 200

def create_neural_net(batch_size=1):
    library = INSTALL_DIR + "/lib/halide/libdevfunc_wrapper.so"
    netspec = caffe.NetSpec()
    netspec.data = L.DummyData(shape=[dict(dim=[batch_size, 1, WIDTH, HEIGHT])], ntop=1)
    netspec.halide  = L.DevFuncLayer(netspec.data)

    with open('net_halide.proto','w') as f:
        f.write(str(netspec.to_proto()))
        f.write('external_layers : "{0}"'.format(library))
        f.flush()
        net = caffe.Net(f.name, caffe.TEST)
    return net

if __name__=='__main__':
    caffe.set_mode_gpu()

    m = 3
    tmp = np.zeros( (1,1,HEIGHT,WIDTH))
    h_c = int(HEIGHT/2)
    w_c = int(WIDTH/2)
    tmp[0,0,h_c,w_c] = 1

    net = create_neural_net()

    net.blobs['data'].data[...]  = tmp
    startTime = int(round(time.time() * 1000))
    net.forward()
    endTime = int(round(time.time() * 1000))
    print(endTime - startTime,'ms')
    print(net.blobs["halide"].data[0,0,h_c-m:h_c+m,w_c-m:w_c+m])

@shelhamer
Copy link
Member

Once useful Halide layers start cropping up it would be nice to have a designated place to put them, together with some information on usage.

This is true of Python layers too. Let's try to work out an arrangement for both.

@BlGene BlGene force-pushed the caffe-halide branch 4 times, most recently from 8f58408 to 1be1516 Compare March 22, 2017 23:01
BlGene and others added 12 commits March 22, 2017 23:32
	1. some blob name logic
	2. move to _argv interface of halide objects.
	3. lint.
Addesses the following isssues:
	1. Remove commented code
	2. Fix cmake build to remove path constants (requires 36473f32)
	3. Fix up forward defs in headers.
	4. Made README.md more detailed
	5. Lint
…ntime.

Also
1. Removed plip function replaced with testfunc.
2. Removed test subdirectory in halide dir.
3. spellchecked readme
4. fixup to syncedmem.hpp
5. updated cmake after removing plip func.
@BlGene
Copy link
Contributor Author

BlGene commented Mar 22, 2017

Note: github is sorting commits by time-stamp not order, so commits 5c8e354 and 1e02d62 should be reviewed first. If they are merged (or rejected) I can rebase.

They are in the PR #5437.

@BlGene BlGene force-pushed the caffe-halide branch 2 times, most recently from 18d3c16 to 8f7e68e Compare March 23, 2017 01:02
@BlGene BlGene force-pushed the caffe-halide branch 2 times, most recently from 0c72607 to c1ba227 Compare March 23, 2017 17:13
@BlGene BlGene force-pushed the caffe-halide branch 4 times, most recently from 0ccd523 to 3ef314c Compare March 24, 2017 14:25
Copy link
Contributor Author

@BlGene BlGene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notes to self.

blur_x(x, y, c, b) = (inp_c(x-1, y, c, b) + inp_c(x, y, c, b) + inp_c(x+1, y, c, b))/3;
blur_y(x, y, c, b) = (blur_x(x, y-1, c, b) + blur_x(x, y, c, b) + blur_x(x, y+1,c ,b))/3;

// The schedule - defines order, locality; implies storage
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed.

"than four axes";
buffer_t buf = {};
for (int i = 0; i < blob.num_axes(); ++i) {
// XXX reversing dimensions here -- should I?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All XXX should be removed from comments


if(BUILD_halide)

#add_subdirectory(test)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed.


#add_subdirectory(test)

# Target name modification
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument for keeping this is that I easily allows defining a separate CMake script in a subfolder, e.g. for tests.

message(STATUS "Halide build: found generator ${in_obj} at ${infilePath}")
SET(outfile "${PROJECT_BINARY_DIR}/halide/${in_obj}.o")
set( in_tgt "${in_obj}${target_name_mod}")
#message(STATUS halide_generator_run_${in_tgt} "creates" ${outfile} )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove.

@BlGene BlGene changed the title [experimental] Halide Layer Halide Layer Mar 24, 2017
@shelhamer shelhamer mentioned this pull request Apr 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants