Skip to content

Commit d255adf

Browse files
committed
fixup
1 parent d3175c8 commit d255adf

File tree

7 files changed

+222
-12
lines changed

7 files changed

+222
-12
lines changed

CMakeLists.txt

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ project(cpp_etudes)
66
#enable_language(C)
77
#enable_language(ASM)
88

9-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -static-libstdc++ -msse4.1 -msse4.2 -mavx2 -mpopcnt -O3 -std=c++17")
10-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -static-libstdc++ -msse4.1 -msse4.2 -mavx2 -g -O0 -std=c++17")
9+
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -static-libstdc++ -msse4.1 -msse4.2 -mavx2 -mpopcnt -O3 -std=c++17")
10+
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -static-libstdc++ -msse4.1 -msse4.2 -mavx2 -g -O0 -std=c++17")
11+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -static-libstdc++ -O3 -std=c++17")
12+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -static-libstdc++ -g -O0 -std=c++17")
1113
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
12-
14+
message(STATUS "abc")
1315
include(cmakes/arch.cmake)
1416
include(cmakes/target.cmake)
1517
#include(cmakes/tools.cmake)
@@ -143,6 +145,20 @@ set(ABSL_BUILD_TESTING OFF)
143145
add_subdirectory(third-party/abseil-cpp-91b7cd600a34cbd)
144146
set(BUILD_TESTING ON)
145147

148+
include (CheckCXXSourceCompiles)
149+
check_cxx_source_compiles("
150+
#include <iostream>
151+
int main() {
152+
#if !_GLIBCXX_USE_CXX11_ABI
153+
#error _GLIBCXX_USE_CXX11_ABI must be non-zero
154+
#endif
155+
return 0;
156+
}
157+
" HAVE_GLIBCXX_USE_CXX11_ABI)
158+
if (NOT HAVE_GLIBCXX_USE_CXX11_ABI)
159+
MESSAGE(FATAL_ERROR "_GLIBCXX_USE_CXX11_ABI should not be 0")
160+
endif()
161+
146162
list(APPEND link_libs gtest
147163
pthread atomic
148164
glog::glog
@@ -170,3 +186,14 @@ message(STATUS "link_libs=${link_libs}")
170186
add_subdirectory(unittest)
171187
add_subdirectory(benchmark)
172188
add_subdirectory(src/main)
189+
190+
SET(IN_DOCKER_ENV OFF)
191+
FIND_FILE(DOCKER_ENV NAMES ".dockerenv" PATHS "/" NO_CACHE)
192+
if (NOT (DOCKER_ENV STREQUAL "DOCKER_ENV-NOTFOUND"))
193+
SET(IN_DOCKER_ENV ON)
194+
endif()
195+
196+
197+
if (IN_DOCKER_ENV)
198+
MESSAGE(STATUS "IN_DOCKER_ENV=${IN_DOCKER_ENV}")
199+
endif()

cmakes/1.png

138 KB
Loading

paste.pl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
use strict;
44
use warnings;
5+
use List::Util qw/max/;
6+
use Data::Dumper;
57
my $n = shift or die "Missing argument 'n'";
8+
my $sep = shift or die "Missing argument 'sep'";
9+
my $fill = shift or die "Missing argument 'fill'";
10+
611
my @ifiles=map {open my $h, "<$_" or die "Open file '$_' error=$!";$h} @ARGV;
712

813
my @contents = map{my $h=$_;[map{chomp $_;$_} <$h>]} @ifiles;
9-
my @total_lines = map{scalar(@$_)} @contents;
14+
@contents = map {[@{$_}[0..$n-1]] } map{[@$_, ($fill) x $n]} @contents;
15+
16+
#print Dumper(\@contents);
1017

1118
for my $i (0..$n-1) {
12-
print join "\t", map {$contents[$_][$i%$total_lines[$_]]} 0..$#contents;
19+
print join "$sep", map {$contents[$_][$i]} 0..$#contents;
1320
print "\n";
1421
}

sr_index2.pl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ ($)
2323
elsif ($t=~/^(\d+)m(\d+)s$/) {
2424
return (($1+0)*60+$2)*1000;
2525
}
26+
elsif($t=~/^(\d+)m$/) {
27+
return ($1+0)*60*1000;
28+
}
2629
elsif ($t=~/^-(\d+(?:\.\d+)?)(ns|us|ms)$/){
2730
return -($1+0.0)/$unit{$2};
2831
}
@@ -53,7 +56,7 @@ ($)
5356
if (!defined($u)) {
5457
$u="B";
5558
}
56-
return ($1+0.0)*$unit{$u};
59+
return ($1+0.0)*$unit{$u}/1024/1024/1024;
5760
} else {
5861
die "undefined number format! '$b'";
5962
return undef;
@@ -84,7 +87,7 @@ ($)
8487
next;
8588
}
8689

87-
if (/\b(MemoryLimit|PeakMemoryUsage|InstanceNum):\s+(\S+)/) {
90+
if (/\b(MemoryLimit|PeakMemoryUsage|__MAX_OF_PeakMemoryUsage|InstancePeakMemoryUsage|__MAX_OF_InstancePeakMemoryUsage|InstanceNum):\s+(.*)/) {
8891
$plan->{$fragment}{$1}=$2;
8992
$plan->{$fragment}{id}=$fragment;
9093
next;
@@ -115,7 +118,7 @@ ($)
115118
next;
116119
}
117120

118-
if (/\b(PushTotalTime|PullTotalTime|CompressTime|SetFinishingTime|BuildHashTableTime|RuntimeFilterBuildTime|CopyRightTableChunkTime|OtherJoinConjunctEvaluateTime|OutputBuildColumnTimer|OutputProbeColumnTimer|OutputTupleColumnTimer|ProbeConjunctEvaluateTime|__MAX_OF_ProbeConjunctEvaluateTime|__MIN_OF_ProbeConjunctEvaluateTime|SearchHashTableTimer|WhereConjunctEvaluateTime|OperatorTotalTime|SetFinishedTime|JoinRuntimeFilterTime|CloseTime)\b:\s+(\S+)/) {
121+
if (/\b(PushTotalTime|SortingTime|__MAX_OF_SortingTime|MergingTime|__MAX_OF_MergingTime|PullTotalTime|CompressTime|SetFinishingTime|BuildHashTableTime|RuntimeFilterBuildTime|CopyRightTableChunkTime|OtherJoinConjunctEvaluateTime|OutputBuildColumnTimer|OutputProbeColumnTimer|OutputTupleColumnTimer|ProbeConjunctEvaluateTime|__MAX_OF_ProbeConjunctEvaluateTime|__MIN_OF_ProbeConjunctEvaluateTime|SearchHashTableTimer|WhereConjunctEvaluateTime|OperatorTotalTime|SetFinishedTime|JoinRuntimeFilterTime|CloseTime)\b:\s+(\S+)/) {
119122
my $operator_id = join "_", ($fragment, $pipeline, $operator);
120123
$plan->{$fragment}{pipelines}{$pipeline}{operators}{$operator}{$1}=norm_time($2);
121124
$plan->{$fragment}{pipelines}{$pipeline}{operators}{$operator}{id}=$operator_id;
@@ -128,7 +131,7 @@ ($)
128131
$plan->{$fragment}{pipelines}{$pipeline}{operators}{$operator}{id}=$operator_id;
129132
next;
130133
}
131-
if (/\b(BytesPassThrough|BytesSent|UpcompressedBytes):\s+(.*)/) {
134+
if (/\b(BytesPassThrough|BytesSent|InputRequiredMemory|__MAX_OF_InputRequiredMemory|MergeUnsortedPeakMemoryUsage|__MAX_OF_MergeUnsortedPeakMemoryUsage|MergeSortedPeakMemoryUsage|__MAX_OF_MergeSortedPeakMemoryUsage|SortPartialPeakMemoryUsage|__MAX_OF_SortPartialPeakMemoryUsage|UpcompressedBytes|OperatorPeakMemoryUsage|__MAX_OF_OperatorPeakMemoryUsage):\s+(.*)/) {
132135
my $operator_id = join "_", ($fragment, $pipeline, $operator);
133136
$plan->{$fragment}{pipelines}{$pipeline}{operators}{$operator}{$1}=$2;
134137
$plan->{$fragment}{pipelines}{$pipeline}{operators}{$operator}{id}=$operator_id;
@@ -154,5 +157,5 @@ ($)
154157
my @fragments = grep {exists $_->{$index}} @$fragments;
155158
my @pipelines = grep {exists $_->{$index}} @$pipelines;
156159
my @ops= grep {exists $_->{$index}} @$ops;
157-
print join "\n", map {sprintf "%s\t%s\t%s", "".$_->{$index}, $index, $_->{id}} sort{$a->{$index} <=> $b->{$index}} (@fragments, @pipelines, @ops);
160+
print join "\n", map {sprintf "%s\t%s\t%s", "".$_->{$index}, $index, $_->{id}} sort{$a->{$index} cmp $b->{$index}} (@fragments, @pipelines, @ops);
158161
print "\n";

unittest/misc_test.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,21 @@ TEST_F(MiscTest, testReadValues) {
14611461
int e =0;
14621462
ASSERT_FALSE(read_values("foobar.1", a, b, c, s, d, e));
14631463
}
1464+
void* func(void*){
1465+
std::cout<<"ok"<<std::endl;
1466+
}
1467+
TEST_F(MiscTest, testPthread) {
1468+
pthread_t pid;
1469+
pthread_attr_t pattr;
1470+
pthread_attr_init(&pattr);
1471+
pthread_attr_setstack(&pattr, (void*)static_cast<intptr_t>(1), 100);
1472+
auto res = pthread_create(&pid, &pattr, func, NULL);
1473+
if (res!=0) {
1474+
std::cout<<"pthread_create: ERROR";
1475+
}
1476+
pthread_join(pid,NULL);
1477+
1478+
}
14641479

14651480
int main(int argc, char** argv) {
14661481
::testing::InitGoogleTest(&argc, argv);

unittest/test_llvm.cc

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
//
77
// Created by grakra on 2022/11/12.
88
//
9+
#include <glog/logging.h>
910
#include <gtest/gtest.h>
11+
#include <llvm-c/BitWriter.h>
1012
#include <llvm-c/Core.h>
13+
#include <llvm-c/LLJIT.h>
14+
#include <llvm-c/OrcEE.h>
15+
#include <llvm-c/Orc.h>
1116
#include <llvm-c/TargetMachine.h>
17+
#include <llvm/ExecutionEngine/Orc/LLJIT.h>
1218

1319
#include <memory>
1420
namespace test {
@@ -74,6 +80,56 @@ TEST_F(LLVMTest, testTupleReference) {
7480
}
7581
std::cout << "end" << std::endl;
7682
}
83+
84+
static LLVMOrcObjectLayerRef llvm_create_object_layer(void* Ctx, LLVMOrcExecutionSessionRef ES, const char* Triple) {
85+
LLVMOrcObjectLayerRef objlayer = LLVMOrcCreateRTDyldObjectLinkingLayerWithSectionMemoryManager(ES);
86+
87+
#if defined(HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER) && HAVE_DECL_LLVMCREATEGDBREGISTRATIONLISTENER
88+
if (jit_debugging_support) {
89+
LLVMJITEventListenerRef l = LLVMCreateGDBRegistrationListener();
90+
91+
LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(objlayer, l);
92+
}
93+
#endif
94+
95+
#if defined(HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER) && HAVE_DECL_LLVMCREATEPERFJITEVENTLISTENER
96+
if (jit_profiling_support) {
97+
LLVMJITEventListenerRef l = LLVMCreatePerfJITEventListener();
98+
99+
LLVMOrcRTDyldObjectLinkingLayerRegisterJITEventListener(objlayer, l);
100+
}
101+
#endif
102+
103+
return objlayer;
104+
}
105+
106+
static void llvm_log_jit_error(void* ctx, LLVMErrorRef error) {
107+
std::cerr << "Error: " << LLVMGetErrorMessage(error) << std::endl;
108+
}
109+
110+
static void materializationUnitFn() {}
111+
static LLVMErrorRef
112+
definitionGeneratorFn(LLVMOrcDefinitionGeneratorRef G, void *Ctx,
113+
LLVMOrcLookupStateRef *LS, LLVMOrcLookupKind K,
114+
LLVMOrcJITDylibRef JD, LLVMOrcJITDylibLookupFlags F,
115+
LLVMOrcCLookupSet Names, size_t NamesCount) {
116+
for (size_t I = 0; I < NamesCount; I++) {
117+
LLVMOrcCLookupSetElement Element = Names[I];
118+
LLVMOrcJITTargetAddress Addr =
119+
(LLVMOrcJITTargetAddress)(&materializationUnitFn);
120+
LLVMJITSymbolFlags Flags = {LLVMJITSymbolGenericFlagsWeak, 0};
121+
LLVMJITEvaluatedSymbol Sym = {Addr, Flags};
122+
LLVMOrcRetainSymbolStringPoolEntry(Element.Name);
123+
LLVMJITCSymbolMapPair Pair = {Element.Name, Sym};
124+
LLVMJITCSymbolMapPair Pairs[] = {Pair};
125+
LLVMOrcMaterializationUnitRef MU = LLVMOrcAbsoluteSymbols(Pairs, 1);
126+
LLVMErrorRef Err = LLVMOrcJITDylibDefine(JD, MU);
127+
if (Err)
128+
return Err;
129+
}
130+
return LLVMErrorSuccess;
131+
}
132+
77133
TEST_F(LLVMTest, testBasic2) {
78134
auto llvmCtx = LLVMContextCreate();
79135
ASSERT_TRUE(LLVMInitializeNativeTarget() == 0);
@@ -92,9 +148,68 @@ TEST_F(LLVMTest, testBasic2) {
92148
LLVMSetDataLayout(module, dataLayout);
93149
auto builder = LLVMCreateBuilder();
94150
std::vector<LLVMTypeRef> funcParams(2, LLVMInt32Type());
95-
auto funcType = LLVMFunctionType(LLVMInt32Type(),funcParams.data(), funcParams.size(), false);
96-
LLVMAddFunction(module, "foobar", funcType);
151+
auto funcType = LLVMFunctionType(LLVMInt32Type(), funcParams.data(), funcParams.size(), false);
152+
auto func = LLVMAddFunction(module, "foobar", funcType);
153+
LLVMSetLinkage(func, LLVMExternalLinkage);
154+
LLVMSetVisibility(func, LLVMDefaultVisibility);
155+
auto block0 = LLVMAppendBasicBlock(func, "entry");
156+
auto param0 = LLVMGetParam(func, 0);
157+
auto param1 = LLVMGetParam(func, 1);
158+
LLVMPositionBuilderAtEnd(builder, block0);
159+
auto tmp = LLVMBuildAlloca(builder, LLVMInt32Type(), "alloc");
160+
auto addResult = LLVMBuildAdd(builder, param0, param1, "add");
161+
LLVMBuildStore(builder, addResult, tmp);
162+
auto c = LLVMBuildLoad2(builder, LLVMInt32Type(), tmp, "");
163+
auto d = LLVMConstInt(LLVMInt32Type(), 2, 0);
164+
auto e = LLVMBuildMul(builder, c, d, "");
165+
LLVMBuildRet(builder, e);
166+
LLVMDisposeBuilder(builder);
167+
//auto buffer = LLVMWriteBitcodeToMemoryBuffer(module);
168+
//const auto* start = LLVMGetBufferStart(buffer);
169+
//const auto size = LLVMGetBufferSize(buffer);
170+
//std::string_view s(start, size);
171+
//std::cout<<s<<std::endl;
172+
std::cout << LLVMPrintModuleToString(module) << std::endl;
173+
auto orcTsCtx = LLVMOrcCreateNewThreadSafeContext();
174+
175+
176+
LLVMOrcLLJITRef lljit;
177+
auto orcJitBuilder = LLVMOrcCreateLLJITBuilder();
178+
auto orcJitTargetMachineBuilder = LLVMOrcJITTargetMachineBuilderCreateFromTargetMachine(targetMachine);
179+
LLVMOrcLLJITBuilderSetJITTargetMachineBuilder(orcJitBuilder, orcJitTargetMachineBuilder);
180+
LLVMOrcLLJITBuilderSetObjectLinkingLayerCreator(orcJitBuilder, llvm_create_object_layer, NULL);
181+
auto err = LLVMOrcCreateLLJIT(&lljit, orcJitBuilder);
182+
if (err) {
183+
LOG(ERROR) << "error: " << LLVMGetErrorMessage(err);
184+
}
185+
186+
LLVMOrcExecutionSessionSetErrorReporter(LLVMOrcLLJITGetExecutionSession(lljit), llvm_log_jit_error, NULL);
97187

188+
LLVMOrcDefinitionGeneratorRef main_gen, ref_gen;
189+
err = LLVMOrcCreateDynamicLibrarySearchGeneratorForProcess(&main_gen, LLVMOrcLLJITGetGlobalPrefix(lljit), 0, NULL);
190+
if (err) {
191+
std::cout << "error" << LLVMGetErrorMessage(err) << std::endl;
192+
}
193+
LLVMOrcJITDylibAddGenerator(LLVMOrcLLJITGetMainJITDylib(lljit), main_gen);
194+
195+
ref_gen = LLVMOrcCreateCustomCAPIDefinitionGenerator(definitionGeneratorFn, NULL);
196+
LLVMOrcJITDylibAddGenerator(LLVMOrcLLJITGetMainJITDylib(lljit), ref_gen);
197+
198+
auto orcTsModule = LLVMOrcCreateNewThreadSafeModule(module, orcTsCtx);
199+
LLVMOrcJITDylibRef jd = LLVMOrcLLJITGetMainJITDylib(lljit);
200+
auto rt = LLVMOrcJITDylibCreateResourceTracker(jd);
201+
202+
err = LLVMOrcLLJITAddLLVMIRModuleWithRT(lljit, rt, orcTsModule);
203+
if (err) {
204+
LOG(ERROR) << "error: " << LLVMGetErrorMessage(err);
205+
}
206+
LLVMOrcExecutorAddress addr;
207+
err = LLVMOrcLLJITLookup(lljit, &addr, "foobar");
208+
if (err) {
209+
LOG(ERROR) << "error: " << LLVMGetErrorMessage(err);
210+
}
211+
auto f = reinterpret_cast<int (*)(int, int)>(reinterpret_cast<uintptr_t>(addr));
212+
std::cout << f(10, 100) << std::endl;
98213
}
99214
} // namespace test
100215
int main(int argc, char** argv) {

unittest/util_test.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <random>
1212
#include <util/bits_op.hh>
13+
#include <absl/container/flat_hash_map.h>
1314
namespace com {
1415
namespace grakra {
1516
namespace util {
@@ -104,7 +105,49 @@ TEST_F(TestUtil, testTerityExprReferenceAssignment) {
104105
std::cout << &b << std::endl;
105106
std::cout << &c << std::endl;
106107
}
108+
#include<list>
109+
TEST_F(TestUtil, testFlatHashMap) {
110+
absl::flat_hash_map<int, int> abc;
111+
std::random_device rd;
112+
std::mt19937 gen(rd());
113+
std::uniform_int_distribution<int8_t> r;
114+
std::uniform_int_distribution<size_t> rsize(1, 1000);
115+
for (int i = 0; i < 100000; ++i) {
116+
const auto size = rsize(gen);
117+
for (int k = 0; k < size; ++k) {
118+
abc[r(gen)] = r(gen);
119+
}
120+
for (const auto& [a, b] : abc) {
121+
std::cout << "k=" << a << ", v=" << b << std::endl;
122+
}
123+
}
124+
}
107125

126+
TEST_F(TestUtil, testVectorResize){
127+
std::vector<int> data;
128+
for(int i=0;i < 100; i++){
129+
data.resize(i*100);
130+
std::cout<<"size="<<i*100 <<", cap="<<data.capacity()<<std::endl;
131+
}
132+
}
133+
134+
TEST_F(TestUtil, TestUnsignedIntegerOverflow){
135+
uint32_t a = 4294967295;
136+
int32_t c = a;
137+
int64_t b = c;
138+
std::cout<<b<<std::endl;
139+
}
140+
141+
TEST_F(TestUtil,TestListTransform){
142+
std::list<int> l0{1,2,3,4,5};
143+
std::list<int> l1;
144+
l1.resize(10);
145+
std::transform(l0.begin(), l0.end(), l1.begin(), [](int x){return x*2;});
146+
std::cout<<"size="<<l1.size()<<std::endl;
147+
for (auto it = l1.begin(); it!=l1.end(); ++it) {
148+
std::cout<<*it<<std::endl;
149+
}
150+
}
108151
} // namespace util
109152
} // namespace grakra
110153
} // namespace com

0 commit comments

Comments
 (0)