Skip to content

Commit e374272

Browse files
committed
Fix time experiment with make clean && make libsmol && make main && ./main
1 parent 3dbb06f commit e374272

5 files changed

Lines changed: 74 additions & 14 deletions

File tree

demos/video/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
# export OpenCV_DIR="$(brew --prefix opencv)/share/opencv4"
44
# /opt/homebrew/opt/opencv/share/opencv4
5+
6+
add_subdirectory("chapel-webcam")
7+
8+
9+
10+
# This is messy
511
find_package(OpenCV 4 REQUIRED)
612

713
find_library(ACCELERATE Accelerate REQUIRED)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This is messy
2+
find_package(OpenCV 4 REQUIRED)
3+
4+
find_library(ACCELERATE Accelerate REQUIRED)
5+
find_library(METAL Metal REQUIRED)
6+
find_library(FOUNDATION Foundation REQUIRED)
7+
8+
include(${CMAKE_CURRENT_SOURCE_DIR}/lib/smol.cmake)
9+
10+
add_executable(ChapelWebcam
11+
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp
12+
)
13+
14+
target_include_directories(ChapelWebcam
15+
PRIVATE
16+
${CMAKE_CURRENT_SOURCE_DIR}/include
17+
${LIBTORCH_DIR}/include
18+
${LIBTORCH_DIR}/include/torch/csrc/api/include
19+
)
20+
21+
target_link_directories(ChapelWebcam PRIVATE ${LIBTORCH_DIR}/lib)
22+
23+
target_link_libraries(ChapelWebcam
24+
PRIVATE
25+
-ltorch
26+
-ltorch_cpu
27+
-lc10
28+
-ltorch_global_deps
29+
${OpenCV_LIBS}
30+
# ${TORCH_LIBRARIES}
31+
${ACCELERATE}
32+
${METAL}
33+
${FOUNDATION}
34+
)
35+
36+
target_include_directories(ChapelWebcam PUBLIC ${smol_INCLUDE_DIRS})
37+
target_link_libraries(ChapelWebcam PUBLIC ${smol_LINK_LIBS})
38+
39+
40+
set_target_properties(ChapelWebcam PROPERTIES
41+
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
42+
)
43+
44+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
45+
target_compile_options(ChapelWebcam PRIVATE -Ofast -flto -ffast-math)
46+
target_link_options(ChapelWebcam PRIVATE -flto)
47+
endif()

demos/video/chapel-webcam/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ LIB_GEN_CMD = \
1313
--dynamic \
1414
--library-dir lib \
1515
--library-makefile \
16+
--library-cmakelists \
1617
--no-munge-with-ids \
1718
-M ../../../lib \
1819
smol.chpl
1920
# --savec lib/savec \
20-
# --library-cmakelists \
2121
2222

2323
pre-build:

demos/video/chapel-webcam/lib/smol.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set(CHPL_THIRD_PARTY /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/third-party)
66

77
set(CHPL_HOME /opt/homebrew/Cellar/chapel/2.4.0_1/libexec)
88

9-
set(smol_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR} /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/internal ${CHPL_RUNTIME_INCL}/localeModels/flat ${CHPL_RUNTIME_INCL}/localeModels ${CHPL_RUNTIME_INCL}/comm/none ${CHPL_RUNTIME_INCL}/comm ${CHPL_RUNTIME_INCL}/tasks/qthreads ${CHPL_RUNTIME_INCL}/. ${CHPL_RUNTIME_INCL}/./qio ${CHPL_RUNTIME_INCL}/./atomics/cstdlib ${CHPL_RUNTIME_INCL}/./mem/jemalloc ${CHPL_THIRD_PARTY}/utf8-decoder ${CHPL_THIRD_PARTY}/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/include -Wno-error=unused-variable ${CHPL_THIRD_PARTY}/re2/install/darwin-arm64-native-llvm-none/include . /opt/homebrew/Cellar/gmp/6.3.0/include /opt/homebrew/Cellar/hwloc/2.12.0/include /opt/homebrew/Cellar/jemalloc/5.3.0/include /opt/homebrew/include)
9+
set(smol_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR} /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/internal /opt/homebrew/Cellar/chapel/2.4.0_1/libexec/modules/packages ${CHPL_RUNTIME_INCL}/localeModels/flat ${CHPL_RUNTIME_INCL}/localeModels ${CHPL_RUNTIME_INCL}/comm/none ${CHPL_RUNTIME_INCL}/comm ${CHPL_RUNTIME_INCL}/tasks/qthreads ${CHPL_RUNTIME_INCL}/. ${CHPL_RUNTIME_INCL}/./qio ${CHPL_RUNTIME_INCL}/./atomics/cstdlib ${CHPL_RUNTIME_INCL}/./mem/jemalloc ${CHPL_THIRD_PARTY}/utf8-decoder ${CHPL_THIRD_PARTY}/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/include -Wno-error=unused-variable ${CHPL_THIRD_PARTY}/re2/install/darwin-arm64-native-llvm-none/include . /opt/homebrew/Cellar/gmp/6.3.0/include /opt/homebrew/Cellar/hwloc/2.12.0/include /opt/homebrew/Cellar/jemalloc/5.3.0/include /opt/homebrew/include)
1010

1111
set(smol_LINK_LIBS -L${CMAKE_CURRENT_LIST_DIR} -lsmol -L${CHPL_RUNTIME_LIB}/darwin/llvm/arm64/cpu-native/loc-flat/comm-none/tasks-qthreads/tmr-generic/unwind-none/mem-jemalloc/atomics-cstdlib/hwloc-system/re2-bundled/fs-none/lib_pic-none/san-none -lchpl -L${CHPL_THIRD_PARTY}/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -Wl,-rpath,${CHPL_THIRD_PARTY}/qthread/install/darwin-arm64-native-llvm-none-flat-jemalloc-system/lib -lqthread -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -L${CHPL_THIRD_PARTY}/re2/install/darwin-arm64-native-llvm-none/lib -lre2 -Wl,-rpath,${CHPL_THIRD_PARTY}/re2/install/darwin-arm64-native-llvm-none/lib -lm -lpthread -L/opt/homebrew/Cellar/gmp/6.3.0/lib -lgmp -L/opt/homebrew/Cellar/hwloc/2.12.0/lib -Wl,-rpath,/opt/homebrew/Cellar/hwloc/2.12.0/lib -lhwloc -L/opt/homebrew/Cellar/jemalloc/5.3.0/lib -Wl,-rpath,/opt/homebrew/Cellar/jemalloc/5.3.0/lib -ljemalloc -L/opt/homebrew/lib -lsmol)
1212

demos/video/chapel-webcam/smol.chpl

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Utilities as utils;
22

3+
34
export proc square(x: int): int {
45
writeln(x, " * ", x, " = ", x * x);
56
return x * x;
@@ -15,29 +16,35 @@ export proc sumArray(a: [] int): int {
1516
export proc printArray(a: [] int): void {
1617
writeln(a);
1718
}
18-
export proc getNewFrame(ref frame: [] real(32),height: int, width: int,channels: int): [] real(32) {
19-
// const dom = {0..<height,0..<width,0..<channels};
20-
// const rgb: [dom] real(32) = reshape(frame,dom);
21-
// const ret = reshape(rgb,{0..<dom.size});
22-
// return ret;
23-
// return [x in frame] x * 1.2;
2419

25-
// const dom = {0..<height,0..<width,0..<channels};
26-
// const rgb: [dom] real(32) = reshape(frame,dom);
20+
use Time;
21+
use Math;
2722

28-
// const m = max reduce frame;
29-
// return [x in frame] m;
3023

24+
proc getTime() {
25+
const tm = timeSinceEpoch();
26+
const sec = tm.chpl_seconds : real(64);
27+
const us = tm.chpl_microseconds : real(64);
28+
const t = sec + (us/1000000.0);
29+
return t;
30+
}
31+
32+
const startTime = getTime();
33+
34+
export proc getNewFrame(ref frame: [] real(32),height: int, width: int,channels: int): [] real(32) {
35+
36+
const t = getTime() - startTime;
3137
const shape = (height,width,channels);
3238
forall i in 0..<frame.size {
3339
const idx = utils.indexAt(i,(...shape));
3440
const (h,w,c) = idx;
35-
// const color = frame[i];
41+
const (u,v) = (h:real(64)/height,w:real(64)/width);
42+
const color = frame[i];
3643
// if h < width {
3744
// frame[utils.linearIdx(shape,(h,w,c))] = frame[utils.linearIdx(shape,(h,w,c-1))];
3845
// }
3946
if h < width {
40-
frame[utils.linearIdx(shape,(h,w,0))] = 1.0;
47+
frame[utils.linearIdx(shape,(h,w,0))] *= Math.sin(2.0*t + 5.0 * u) : real(32);
4148
}
4249
}
4350
return frame;

0 commit comments

Comments
 (0)