Skip to content

Commit

Permalink
adds Sort, revamps TensorMath, adds masked* operations
Browse files Browse the repository at this point in the history
  • Loading branch information
soumith committed Mar 30, 2015
1 parent 4fdbf0c commit f004da6
Show file tree
Hide file tree
Showing 19 changed files with 2,467 additions and 909 deletions.
1 change: 1 addition & 0 deletions FFI.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ typedef struct THCState
{
struct THCRNGState* rngState;
struct THCBlasState* blasState;
struct cudaDeviceProp* deviceProperties;
} THCState;
typedef struct THCudaStorage
Expand Down
15 changes: 0 additions & 15 deletions Tensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@

/* everything is as the generic Storage.c, except few things (see below) */

static void THCudaTensor_maskedFill(THCState *state, THCudaTensor *tensor, THByteTensor *mask, float value)
{
THError("not yet implemented for CUDA");
}

static void THCudaTensor_maskedCopy(THCState *state, THCudaTensor *tensor, THByteTensor *mask, THCudaTensor* src)
{
THError("not yet implemented for CUDA");
}

void THCudaTensor_maskedSelect(THCState *state, THCudaTensor *tensor, THCudaTensor* src, THByteTensor *mask)
{
THError("not yet implemented for CUDA");
}

#define real float
#define Real Cuda

Expand Down
29 changes: 28 additions & 1 deletion TensorMath.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ end

local function lastdim(argn)
return function(arg)
return string.format("THCudaTensor_nDimension(%s)", arg.args[argn]:carg())
return string.format("THCudaTensor_nDimension(cutorch_getstate(L), %s)", arg.args[argn]:carg())
end
end

Expand Down Expand Up @@ -289,6 +289,33 @@ wrap("addcdiv",
{name=Tensor},
{name=Tensor}})

wrap("maskedFill",
cname("maskedFill"),
{{name=Tensor, returned=true, method={default='nil'}},
{name=Tensor},
{name=real}})

wrap("maskedCopy",
cname("maskedCopy"),
{{name=Tensor, returned=true, method={default='nil'}},
{name=Tensor},
{name=Tensor}})

wrap("maskedSelect",
cname("maskedSelect"),
{{name=Tensor, returned=true, default=true},
{name=Tensor},
{name=Tensor}})

wrap("sort",
cname("sort"),
{{name=Tensor, default=true, returned=true},
{name=Tensor, default=true, returned=true, noreadadd=true},
{name=Tensor},
{name="index", default=lastdim(3)},
{name="boolean", default=0}})


do
local Tensor = Tensor
local real = real
Expand Down
10 changes: 10 additions & 0 deletions init.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ static int cutorch_getDeviceCount(lua_State *L)
return 1;
}

static int cutorch_getMemoryUsage(lua_State *L) {
size_t freeBytes = 0;
size_t totalBytes = 0;
THCudaCheck(cudaMemGetInfo(&freeBytes, &totalBytes));
lua_pushnumber(L, freeBytes);
lua_pushnumber(L, totalBytes);
return 2;
}

static int cutorch_setDevice(lua_State *L)
{
THCState *state = cutorch_getstate(L);
Expand Down Expand Up @@ -158,6 +167,7 @@ static const struct luaL_Reg cutorch_stuff__ [] = {
{"deviceReset", cutorch_deviceReset},
{"getDeviceCount", cutorch_getDeviceCount},
{"getDeviceProperties", cutorch_getDeviceProperties},
{"getMemoryUsage", cutorch_getMemoryUsage},
{"setDevice", cutorch_setDevice},
{"seed", cutorch_seed},
{"seedAll", cutorch_seedAll},
Expand Down
6 changes: 5 additions & 1 deletion lib/THC/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SET(src
THCGeneral.c THCStorage.c THCStorageCopy.c THCTensor.c THCTensorCopy.c)

SET(src-cuda THC.cu)
SET(src-cuda THC.cu THCReduceApplyUtils.cu THCTensorSort.cu)

CUDA_ADD_LIBRARY(THC SHARED ${src} ${src-cuda})
CUDA_ADD_CUBLAS_TO_TARGET(THC)
Expand All @@ -23,4 +23,8 @@ INSTALL(FILES
THCTensorRandom.h
THCTensorMath.h
THCTensorConv.h
THCTensorSort.h
THCApply.cuh
THCReduce.cuh
THCReduceApplyUtils.cuh
DESTINATION "${Torch_INSTALL_INCLUDE_SUBDIR}/THC")
1 change: 1 addition & 0 deletions lib/THC/THC.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
#include "THCTensorRandom.h"
#include "THCTensorMath.h"
#include "THCTensorConv.h"
#include "THCTensorSort.h"

#endif
Loading

0 comments on commit f004da6

Please sign in to comment.