Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/clementfarabet/lua---nnx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Scoffier <github@metm.org>2011-09-23 08:54:23 +0400
committerMarco Scoffier <github@metm.org>2011-09-23 08:54:23 +0400
commited8881eadcd626307adbc7d2a8fa98fd8d7fd98f (patch)
tree76b22fb1cbe8350fbb23d3259e0c159cd00c169a
parente43dff52d4d7cee90028725943fc88b48be48f7c (diff)
working cuda -> lbfgs
-rw-r--r--generic/lbfgs.c16
-rw-r--r--lbfgs.c4
-rw-r--r--nnx-1.0-1.rockspec37
3 files changed, 41 insertions, 16 deletions
diff --git a/generic/lbfgs.c b/generic/lbfgs.c
index ffe7bd0..7e39f7e 100644
--- a/generic/lbfgs.c
+++ b/generic/lbfgs.c
@@ -11,8 +11,7 @@ int THTensor_(copy_evaluate_start)(THTensor *parameters,
const int nParameter)
{
THDoubleStorage *xs = THDoubleStorage_newWithData((double *)x,nParameter);
- THStorage *ps =
- THStorage_(newWithData)(THTensor_(data)(parameters),nParameter);
+ THStorage *ps = THTensor_(storage)(parameters);
/* copy given x (xs) -> parameters (ps) */
@@ -21,8 +20,6 @@ int THTensor_(copy_evaluate_start)(THTensor *parameters,
/* only want to free the struct part of the storage not the data */
xs->data = NULL;
THDoubleStorage_free(xs);
- ps->data = NULL;
- THStorage_(free)(ps);
return 0;
}
@@ -31,8 +28,7 @@ int THTensor_(copy_evaluate_end)(lbfgsfloatval_t *g,
const int nParameter)
{
THDoubleStorage *gs = THDoubleStorage_newWithData((double *)g,nParameter);
- THStorage *gps =
- THStorage_(newWithData)(THTensor_(data)(gradParameters), nParameter);
+ THStorage *gps = THTensor_(storage)(gradParameters);
/* copy gradParameters (gps) -> g (gs) */
#ifdef TH_REAL_IS_FLOAT
@@ -47,8 +43,6 @@ int THTensor_(copy_evaluate_end)(lbfgsfloatval_t *g,
/* only want to free the struct part of the storage not the data */
gs->data = NULL;
THDoubleStorage_free(gs);
- gps->data = NULL;
- THStorage_(free)(gps);
return 0;
}
@@ -59,8 +53,7 @@ int THTensor_(copy_init)(lbfgsfloatval_t *x,
const int nParameter)
{
THDoubleStorage *xs = THDoubleStorage_newWithData((double *)x,nParameter);
- THStorage *ps =
- THStorage_(newWithData)(THTensor_(data)(parameters),nParameter);
+ THStorage *ps = THTensor_(storage)(parameters);
/* copy given parameters (ps) -> x (xs) */
#ifdef TH_REAL_IS_FLOAT
@@ -75,9 +68,6 @@ int THTensor_(copy_init)(lbfgsfloatval_t *x,
/* only want to free the struct part of the storage not the data */
xs->data = NULL;
THDoubleStorage_free(xs);
- ps->data = NULL;
- THStorage_(free)(ps);
- printf("in copy_init : freed storage\n");
/* done */
return 0;
diff --git a/lbfgs.c b/lbfgs.c
index b9e1137..11f871e 100644
--- a/lbfgs.c
+++ b/lbfgs.c
@@ -66,7 +66,7 @@
#endif
#ifdef WITH_CUDA
-#include "THC.h"
+#include <THC/THC.h>
#endif
#include "TH.h"
@@ -1549,7 +1549,7 @@ int lbfgs_init(lua_State *L) {
THFloatTensor_copy_init(x,(THFloatTensor *)parameters,nParameter);
#ifdef WITH_CUDA
else if ( current_torch_type = torch_CudaTensor_id )
- THCudaTensor_copy_init(x,(THDoubleTensor *)parameters,nParameter);
+ THCudaTensor_copy_init(x,(THCudaTensor *)parameters,nParameter);
#endif
/* initialize the parameters for the L-BFGS optimization */
diff --git a/nnx-1.0-1.rockspec b/nnx-1.0-1.rockspec
index 1b90f21..2650547 100644
--- a/nnx-1.0-1.rockspec
+++ b/nnx-1.0-1.rockspec
@@ -49,10 +49,45 @@ build = {
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
- include_directories (${TORCH_INCLUDE_DIR} ${PROJECT_SOURCE_DIR})
+ include_directories (${TORCH_INCLUDE_DIR} ${PROJECT_SOURCE_DIR})
+
+ SET(WITH_CUDA OFF CACHE BOOL "Compile qlua and associated packages")
+
+ IF(EXISTS "${TORCH_BIN_DIR}/../include/THC/THC.h")
+ FIND_PACKAGE(CUDA 4.0)
+
+ IF (CUDA_FOUND)
+ # bug on Apple
+ IF(APPLE)
+ LINK_DIRECTORIES("/usr/local/cuda/lib/")
+ ENDIF(APPLE)
+
+ find_library (TORCH_THC THC ${TORCH_BIN_DIR}/../lib NO_DEFAULT_PATH)
+
+
+ set (TORCH_LIBRARIES ${TORCH_TH} ${TORCH_THC} ${TORCH_luaT} ${TORCH_lua})
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWITH_CUDA")
+
+ cuda_add_library (lbfgs SHARED lbfgs.c)
+ target_link_libraries (lbfgs ${TORCH_LIBRARIES})
+ CUDA_ADD_CUBLAS_TO_TARGET(lbfgs)
+
+ ELSE (CUDA_FOUND)
+
+ MESSAGE(STATUS "Disabling CUDA (CUDA 4.0 required, and not found)")
+ MESSAGE(STATUS "If CUDA 4.0 is installed, then specify CUDA_TOOLKIT_ROOT_DIR")
+
+ set (TORCH_LIBRARIES ${TORCH_TH} ${TORCH_luaT} ${TORCH_lua})
+
add_library (lbfgs SHARED lbfgs.c)
target_link_libraries (lbfgs ${TORCH_LIBRARIES})
+
+ ENDIF (CUDA_FOUND)
+ ENDIF(EXISTS "${TORCH_BIN_DIR}/../include/THC/THC.h")
+
install_targets (/lib lbfgs)
+
+
include_directories (${TORCH_INCLUDE_DIR} ${PROJECT_SOURCE_DIR})
add_library (nnx SHARED init.c)