Skip to content

Instantly share code, notes, and snippets.

@samskalicky
samskalicky / op_info.cc
Created August 19, 2020 08:08
MXNet Ops
// put in src/operator and build MXNet
#include "operator_common.h"
extern "C" int listOps() {
// get op registry
::dmlc::Registry<::nnvm::Op>* reg = ::dmlc::Registry<::nnvm::Op>::Get();
// get list of registered op names
std::vector<std::string> ops = reg->ListAllNames();
@samskalicky
samskalicky / pass_lib.cc
Last active May 1, 2020 07:08
Example graph pass
#include <math.h>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <functional>
#include "lib_api.h"
class Node;
struct NodeEntry {
Node* node;
@samskalicky
samskalicky / Makefile
Last active January 25, 2020 07:09
static singletons in shared libraries
all:
g++ -o main test.cpp -ldl -std=c++11
g++ -o libmylib.so -shared -fPIC -std=c++11 lib.cpp
cp libmylib.so libmylib2.so
clean:
rm -rf *.so main *~
@samskalicky
samskalicky / ndiag.py
Created September 5, 2018 02:39
N-dimensional diagonal tensor calculation
# convert from N-D coordinates to 1-D index
def ravel(coord,stride):
idx = 0
# loop and multiply each coordinate by the stride
for i in range(len(coord)):
idx += coord[i] * stride[i]
return idx
# convert from a 1-D index to N-D coordinates
def unravel(idx,stride):
@samskalicky
samskalicky / Makefile
Created August 6, 2018 23:43
Example cuDNN pooling operator for both forward and backward passes
all:
nvcc -arch=sm_35 -std=c++11 -O2 -Icudnn/include -L cudnn/lib64 -L /usr/local/lib test.cu -o test -lcudnn -I. -D$(FLAGS)