Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ ifeq ($(USE_DIST_KVSTORE), 1)
LDFLAGS += $(PS_LDFLAGS_A)
endif

include $(MXNET_PLUGINS)

.PHONY: clean all test lint doc clean_all rcpplint rcppexport roxygen

all: lib/libmxnet.a lib/libmxnet.so $(BIN)
Expand All @@ -100,6 +98,7 @@ OBJ = $(patsubst %.cc, build/%.o, $(SRC))
CUSRC = $(wildcard src/*/*.cu)
CUOBJ = $(patsubst %.cu, build/%_gpu.o, $(CUSRC))

# extra operators
ifneq ($(EXTRA_OPERATORS),)
EXTRA_SRC = $(wildcard $(EXTRA_OPERATORS)/*.cc $(EXTRA_OPERATORS)/*/*.cc)
EXTRA_OBJ = $(patsubst $(EXTRA_OPERATORS)/%.cc, $(EXTRA_OPERATORS)/build/%.o, $(EXTRA_SRC))
Expand All @@ -113,21 +112,11 @@ else
endif

# plugin
ifeq ($(USE_TORCH), 1)
CFLAGS += -I$(TORCH_PATH)/install/include -I$(TORCH_PATH)/install/include/TH -I$(TORCH_PATH)/install/include/THC -DMXNET_USE_TORCH=1
LDFLAGS += -L$(TORCH_PATH)/install/lib -lluajit -lluaT -lTH -lTHC -L$(TORCH_PATH)/install/lib/lua/5.1 -lpaths -ltorch -lnn
ifeq ($(USE_CUDA), 1)
LDFLAGS += -lcutorch -lcunn
endif

TORCH_SRC = $(wildcard plugin/torch/*.cc)
PLUGIN_OBJ += $(patsubst %.cc, build/%.o, $(TORCH_SRC))
TORCH_CUSRC = $(wildcard plugin/torch/*.cu)
PLUGIN_CUOBJ += $(patsubst %.cu, build/%_gpu.o, $(TORCH_CUSRC))
else
CFLAGS += -DMXNET_USE_TORCH=0
endif
PLUGIN_OBJ =
PLUGIN_CUOBJ =
include $(MXNET_PLUGINS)

# all dep
LIB_DEP += $(DMLC_CORE)/libdmlc.a
ALL_DEP = $(OBJ) $(EXTRA_OBJ) $(PLUGIN_OBJ) $(LIB_DEP)
ifeq ($(USE_CUDA), 1)
Expand Down Expand Up @@ -158,10 +147,11 @@ build/plugin/%.o: plugin/%.cc
$(CXX) -std=c++0x $(CFLAGS) -MM -MT build/plugin/$*.o $< >build/plugin/$*.d
$(CXX) -std=c++0x -c $(CFLAGS) -c $< -o $@

# A nvcc bug cause this to generate "generic/xxx.h" dependencies from torch headers.
# $(NVCC) $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" -M -MT build/plugin/$*_gpu.o $< >build/plugin/$*_gpu.d
# A nvcc bug cause it to generate "generic/xxx.h" dependencies from torch headers.
# Use CXX to generate dependency instead.
build/plugin/%_gpu.o: plugin/%.cu
@mkdir -p $(@D)
$(CXX) -std=c++0x $(CFLAGS) -MM -MT build/plugin/$*_gpu.o $< >build/plugin/$*_gpu.d
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

nvcc's dependency generation doesn't work with torch headers. I used CXX to generate dependency for .cu files instead. It seems to work just fine.

$(NVCC) -c -o $@ $(NVCCFLAGS) -Xcompiler "$(CFLAGS)" $<

$(EXTRA_OPERATORS)/build/%.o: $(EXTRA_OPERATORS)/%.cc
Expand Down
4 changes: 2 additions & 2 deletions make/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ EXTRA_OPERATORS =
#----------------------------

# whether to use torch integration. This requires installing torch.
USE_TORCH = 0
TORCH_PATH = $(HOME)/torch
# TORCH_PATH = $(HOME)/torch
# MXNET_PLUGINS += plugin/torch/torch.mk

# whether to use sframe integration. This requires build sframe
# git@github.com:dato-code/SFrame.git
Expand Down
4 changes: 2 additions & 2 deletions make/osx.mk
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,5 @@ EXTRA_OPERATORS =
#----------------------------

# whether to use torch integration. This requires installing torch.
USE_TORCH = 0
TORCH_PATH = $(HOME)/torch
# TORCH_PATH = $(HOME)/torch
# MXNET_PLUGINS += plugin/torch/torch.mk
10 changes: 10 additions & 0 deletions plugin/torch/torch.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CFLAGS += -I$(TORCH_PATH)/install/include -DMXNET_USE_TORCH=1
LDFLAGS += -L$(TORCH_PATH)/install/lib -lluajit -lluaT -lTH -lTHC -L$(TORCH_PATH)/install/lib/lua/5.1 -lpaths -ltorch -lnn
ifeq ($(USE_CUDA), 1)
LDFLAGS += -lcutorch -lcunn
endif

TORCH_SRC = $(wildcard plugin/torch/*.cc)
PLUGIN_OBJ += $(patsubst %.cc, build/%.o, $(TORCH_SRC))
TORCH_CUSRC = $(wildcard plugin/torch/*.cu)
PLUGIN_CUOBJ += $(patsubst %.cu, build/%_gpu.o, $(TORCH_CUSRC))
11 changes: 6 additions & 5 deletions plugin/torch/torch_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
#ifndef PLUGIN_TORCH_TORCH_BASE_H_
#define PLUGIN_TORCH_TORCH_BASE_H_
#include <mxnet/base.h>
#include <vector>

extern "C" {
#include <lua.h>
#include <luaT.h>
#include <lualib.h>
#include <THStorage.h>
#include <THTensor.h>
#include <TH/THStorage.h>
#include <TH/THTensor.h>
}

#if MXNET_USE_CUDA
extern "C" {
#include <THCStorage.h>
#include <THCTensor.h>
#include <THC/THCStorage.h>
#include <THC/THCTensor.h>
}
#endif // MXNET_USE_CUDA

#include <vector>

namespace mxnet {

class TorchState {
Expand Down