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:
authorClement Farabet <clement.farabet@gmail.com>2011-07-29 01:39:39 +0400
committerClement Farabet <clement.farabet@gmail.com>2011-07-29 01:39:39 +0400
commit86b6cb4fc2c29e1232a1c70a38ae82d23260f615 (patch)
tree732af38ad53deffa889cc16d79d204d6045e7485
parentd7ca10c90eccbd1ab47fee193fe5db1603daf16f (diff)
Removed omp locks.
-rw-r--r--SpatialLinear.lua2
-rw-r--r--generic/SpatialLinear.c26
-rw-r--r--test/test-omp.lua8
3 files changed, 8 insertions, 28 deletions
diff --git a/SpatialLinear.lua b/SpatialLinear.lua
index 56231d1..1cf850e 100644
--- a/SpatialLinear.lua
+++ b/SpatialLinear.lua
@@ -1,4 +1,4 @@
-local SpatialLinear, parent = torch.class('nn.SpatialLinear', 'nn.OmpModule')
+local SpatialLinear, parent = torch.class('nn.SpatialLinear', 'nn.Module')
function SpatialLinear:__init(fanin, fanout)
parent.__init(self)
diff --git a/generic/SpatialLinear.c b/generic/SpatialLinear.c
index b9f60e2..56b4a3d 100644
--- a/generic/SpatialLinear.c
+++ b/generic/SpatialLinear.c
@@ -9,7 +9,6 @@ static int nn_(SpatialLinear_forward)(lua_State *L)
THTensor *bias = luaT_getfieldcheckudata(L, 1, "bias", torch_(Tensor_id));
THTensor *weight = luaT_getfieldcheckudata(L, 1, "weight", torch_(Tensor_id));
THTensor *output = luaT_getfieldcheckudata(L, 1, "output", torch_(Tensor_id));
- int nThread = luaT_getfieldcheckint(L, 1, "nThread");
// dims
int iwidth = input->size[2];
@@ -19,20 +18,15 @@ static int nn_(SpatialLinear_forward)(lua_State *L)
int oheight = iheight;
int ochannels = output->size[0];
+ // planes
+ THTensor *outputPlane = THTensor_(new)();
+ THTensor *inputPlane = THTensor_(new)();
+
// process each plane
int ok,ik;
- omp_set_num_threads(nThread);
- omp_lock_t lock; omp_init_lock(&lock);
- #pragma omp parallel for private(ok,ik)
for (ok=0; ok<ochannels; ok++) {
-
- // select planes
- omp_set_lock(&lock);
- THTensor *outputPlane = THTensor_(new)();
- THTensor *inputPlane = THTensor_(new)();
+ // fill output
THTensor_(select)(outputPlane, output, 0, ok);
- omp_unset_lock(&lock);
-
THTensor_(fill)(outputPlane, THTensor_(get1d)(bias,ok));
for (ik=0; ik<ichannels; ik++) {
@@ -40,16 +34,11 @@ static int nn_(SpatialLinear_forward)(lua_State *L)
THTensor_(select)(inputPlane, input, 0, ik);
THTensor_(cadd)(outputPlane, THTensor_(get2d)(weight,ok,ik), inputPlane);
}
-
- // cleanup
- omp_set_lock(&lock);
- THTensor_(free)(inputPlane);
- THTensor_(free)(outputPlane);
- omp_unset_lock(&lock);
}
// cleanup
- omp_destroy_lock(&lock);
+ THTensor_(free)(inputPlane);
+ THTensor_(free)(outputPlane);
return 1;
}
@@ -65,7 +54,6 @@ static int nn_(SpatialLinear_backward)(lua_State *L)
THTensor *gradWeight = luaT_getfieldcheckudata(L, 1, "gradWeight", torch_(Tensor_id));
THTensor *gradBias = luaT_getfieldcheckudata(L, 1, "gradBias", torch_(Tensor_id));
int weightDecay = luaT_getfieldcheckint(L, 1, "weightDecay");
- int nThread = luaT_getfieldcheckint(L, 1, "nThread");
// dims
int iwidth = input->size[2];
diff --git a/test/test-omp.lua b/test/test-omp.lua
index 0145211..0de7707 100644
--- a/test/test-omp.lua
+++ b/test/test-omp.lua
@@ -88,14 +88,6 @@ function nnx.test_omp(nThread)
-- backward('SpatialMaxPooling_backward')
end
- function test_SpatialLinear()
- ts = {}
- times['SpatialLinear_forward'] = ts
- n = nn.SpatialLinear(maps,maps2)
- vec = lab.randn(maps,height,width)
- forward('SpatialLinear_forward')
- end
-
-- run all tests
lunit.main()