Skip to content

Commit 8492140

Browse files
authored
Remove state global locks (#85)
* Remove global locks and everything that uses them * Tidy up pi func * Remove scale_check function * New version
1 parent f3ac17b commit 8492140

File tree

14 files changed

+17
-380
lines changed

14 files changed

+17
-380
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SYSROOT_VERSION=0.1.5
2-
SYSROOT_CLI_IMAGE=faasm/cpp-sysroot:0.1.5
1+
SYSROOT_VERSION=0.1.6
2+
SYSROOT_CLI_IMAGE=faasm/cpp-sysroot:0.1.6
33
COMPOSE_PROJECT_NAME=cpp-dev

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
if: github.event.pull_request.draft == false
1313
runs-on: ubuntu-20.04
1414
container:
15-
image: faasm/cpp-sysroot:0.1.5
15+
image: faasm/cpp-sysroot:0.1.6
1616
defaults:
1717
run:
1818
working-directory: /code/cpp

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.5
1+
0.1.6

func/demo/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ demo_func(getpwuid getpwuid.cpp)
4343
demo_func(gettime gettime.cpp)
4444
demo_func(heap heap.cpp)
4545
demo_func(hello hello.cpp)
46-
demo_func(increment increment.cpp)
4746
demo_func(isatty isatty.cpp)
4847
demo_func(listdir listdir.cpp)
4948
demo_func(lock lock.c)
@@ -66,7 +65,6 @@ demo_func(print_state print_state.cpp)
6665
demo_func(ptr_ptr ptr_ptr.cpp)
6766
demo_func(random random.cpp)
6867
demo_func(random_float random_float.cpp)
69-
demo_func(scale_check scale_check.cpp)
7068
demo_func(shared_file shared_file.cpp)
7169
demo_func(simple simple.cpp)
7270
demo_func(sizes sizes.cpp)

func/demo/pi.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <faasm/counter.h>
21
#include <faasm/faasm.h>
32
#include <faasm/input.h>
43
#include <faasm/random.h>
@@ -12,8 +11,6 @@
1211

1312
int piStep()
1413
{
15-
auto sum = faasm::AtomicInt("pi");
16-
1714
int count = 0;
1815
for (int i = 0; i < CHUNK_SIZE; i++) {
1916
// Two random points
@@ -26,8 +23,8 @@ int piStep()
2623
}
2724
}
2825

29-
sum += count;
30-
26+
// Append count for this worker
27+
faasmAppendState("pi", BYTES(&count), sizeof(int));
3128
return 0;
3229
}
3330

@@ -40,15 +37,19 @@ int main(int argc, char* argv[])
4037
int nWorkers = std::stoi(inputData);
4138
int nTotal = CHUNK_SIZE * nWorkers;
4239

43-
// Initialise the sum
44-
auto sum = faasm::AtomicInt("pi");
45-
sum.reset();
46-
4740
// Dispatch chained calls
4841
faasmChainBatch(piStep, "", nWorkers);
4942

50-
// Get the final result
51-
int finalCount = sum.get();
43+
// Read in the counts
44+
size_t buffSize = nWorkers * sizeof(int);
45+
auto buffer = new int[nWorkers];
46+
faasmReadAppendedState("pi", (uint8_t*)buffer, buffSize, nWorkers);
47+
48+
// Sum the counts
49+
int finalCount = 0;
50+
for (int w = 0; w < nWorkers; w++) {
51+
finalCount += buffer[w];
52+
}
5253

5354
// Estimate pi
5455
float pi = 4 * ((float)finalCount / (nTotal));
@@ -59,5 +60,6 @@ int main(int argc, char* argv[])
5960
printf("%s", output.c_str());
6061
faasm::setStringOutput(output.c_str());
6162

63+
delete[] buffer;
6264
return 0;
6365
}

func/demo/scale_check.cpp

Lines changed: 0 additions & 49 deletions
This file was deleted.

libfaasm/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ set(PUBLIC_HEADERS
1010
faasm/host_interface.h
1111
faasm/array.h
1212
faasm/compare.h
13-
faasm/counter.h
1413
faasm/faasm.h
1514
faasm/files.h
1615
faasm/input.h
@@ -27,7 +26,6 @@ set(PUBLIC_HEADERS
2726
set(LIB_FILES
2827
compare.cpp
2928
core.cpp
30-
counter.cpp
3129
files.cpp
3230
input.cpp
3331
matrix.cpp

libfaasm/core.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,6 @@ void faasmPullState(const char* key, long stateLen)
108108
__faasm_pull_state(key, stateLen);
109109
}
110110

111-
void faasmLockStateGlobal(const char* key)
112-
{
113-
__faasm_lock_state_global(key);
114-
}
115-
116-
void faasmUnlockStateGlobal(const char* key)
117-
{
118-
__faasm_unlock_state_global(key);
119-
}
120-
121111
void faasmLockStateRead(const char* key)
122112
{
123113
__faasm_lock_state_read(key);

libfaasm/counter.cpp

Lines changed: 0 additions & 80 deletions
This file was deleted.

libfaasm/faasm.imports

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ __faasm_flag_state_dirty
1515
__faasm_flag_state_offset_dirty
1616
__faasm_read_state_offset
1717
__faasm_read_state_offset_ptr
18-
__faasm_lock_state_global
19-
__faasm_unlock_state_global
2018
__faasm_lock_state_read
2119
__faasm_unlock_state_read
2220
__faasm_lock_state_write

0 commit comments

Comments
 (0)