Skip to content

Commit dacbfad

Browse files
committed
large tensor
1 parent becd2df commit dacbfad

File tree

13 files changed

+44
-894
lines changed

13 files changed

+44
-894
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ build
44

55
/target
66
**/*.rs.bk
7+
Makefile
8+
.idea

.idea/codeStyles/Project.xml

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

.idea/keigen.iml

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

.idea/misc.xml

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

.idea/modules.xml

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

.idea/vcs.xml

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

.idea/workspace.xml

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

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
cmake_minimum_required(VERSION 3.9)
22
project(keigen)
33

4+
#set(LLVM_DIR /usr/local/opt/llvm/share/cmake/modules)
45
set(CMAKE_CXX_STANDARD 11)
56
find_package(LLVM REQUIRED CONFIG)
6-
7+
#
78
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
89
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
910

@@ -16,7 +17,7 @@ include_directories(${LLVM_INCLUDE_DIRS})
1617
add_definitions(${LLVM_DEFINITIONS})
1718

1819
#find_package (Eigen3 3.3 REQUIRED NO_MODULE)
19-
include_directories(.)
20+
include_directories(Eigen)
2021

2122
add_executable(r_traits traits.cpp)
2223
add_executable(r_boost boost.cpp)
@@ -31,4 +32,4 @@ llvm_map_components_to_libnames(llvm_libs core)
3132
# Link against LLVM libraries
3233
target_link_libraries(r_kvm ${llvm_libs})
3334
#target_link_libraries(r_kvm Eigen3::Eigen)
34-
#target_link_libraries(r_kq Eigen3::Eigen)
35+
#target_link_libraries(r_kq Eigen3::Eigen)s

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Eigen/src/LU/InverseImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ struct Assignment<DstXprType, Inverse<XprType>, internal::assign_op<typename Dst
324324
* \note This matrix must be invertible, otherwise the result is undefined. If you need an
325325
* invertibility check, do the following:
326326
* \li for fixed sizes up to 4x4, use computeInverseAndDetWithCheck().
327-
* \li for the general case, use class FullPivLU.
327+
* \li for the general case, use class x.
328328
*
329329
* Example: \include MatrixBase_inverse.cpp
330330
* Output: \verbinclude MatrixBase_inverse.out

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# keigen
2-
![](http://eigen.tuxfamily.org/images/Eigen_Silly_Professor_135x135.png)
3-
42

3+
![](img/logo.png)
54
Some toys for high performance computation includes computation graph KVM compiler etc.

img/logo.png

58.1 KB
Loading

kq.cpp

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,37 @@
22
// Created by nuxeslin on 2018/11/7.
33
//
44
#include <iostream>
5-
#include <Eigen/Core>
5+
#include <Core>
66
#include <stdlib.h>
77

88
using namespace std;
99
using namespace Eigen;
1010

11-
template <int M, int N>
11+
template<int M, int N>
1212
void InitMat(float mat[M][N], int row_num, int col_num) {
1313
// for (int i = 0; i < row_num; i++) {
1414
// for (int j = 0; j < col_num; j++) {
1515
// mat[i * col_num + j] = 1;
1616
// }
1717
// }
1818
for (int k = 0; k < row_num * col_num; k++) {
19-
*((float*)mat + k) = 1;
19+
*((float *) mat + k) = 1;
2020
}
2121
}
2222

23-
template <size_t N>
23+
template<size_t N>
2424
struct MyAllocator {
2525
char buf[N];
2626
void *ptr;
2727
size_t sz;
28+
2829
MyAllocator() : ptr(buf), sz(N) {}
29-
template <typename T>
30-
T* aligned_malloc(size_t a = alignof(T)) {
30+
31+
template<typename T>
32+
T *aligned_malloc(size_t a = alignof(T)) {
3133
if (std::align(a, sizeof(T), ptr, sz)) {
32-
auto res = reinterpret_cast<T*>(ptr);
33-
ptr = (char*)res + sizeof(T);
34+
auto res = reinterpret_cast<T *>(ptr);
35+
ptr = (char *) res + sizeof(T);
3436
sz -= sizeof(T);
3537
return res;
3638
}
@@ -42,7 +44,7 @@ struct MyAllocator {
4244
struct KMatrix {
4345
int width;
4446
int height;
45-
float* data;
47+
float *data;
4648
};
4749

4850
// set memory alignment
@@ -59,40 +61,41 @@ struct Area {
5961
double x3;
6062
};
6163

62-
void Run() {
63-
int size = 3;
64-
Eigen::VectorXf v(size), u(size), w(size);
65-
u = v + w;
66-
std::cout << u << std::endl;
67-
}
68-
6964
// at runtime
7065
void KL_bad_allocate() {
7166
auto huge = static_cast<size_t>(-1);
7267
::operator new(huge);
7368
}
7469

7570
void KL_compute_op() {
76-
Eigen::Matrix2d mat;
77-
KL_bad_allocate();
71+
Eigen::MatrixXf mat(2, 2);
72+
mat << 2, 4,
73+
3, 9;
74+
mat.inverse();
75+
// KL_bad_allocate();
7876
// std::bad_alloc();
7977
}
8078

79+
void Run() {
80+
KL_compute_op();
81+
}
82+
83+
8184
void AlignedAllocate() {
8285
char n = 'x';
8386
float q = 2.0;
84-
printf("y1: 0x%lx\n", (size_t)&n);
87+
printf("y1: 0x%lx\n", (size_t) &n);
8588
// without customized alignment
8689
// alignment equal to min(sizeof(float), 16) = 4 bytes
8790
// so there will be 3 bytes padding subsequently
8891
// - (4 + 3 = 7) bytes
89-
printf("y2: 0x%lx\n", (size_t)&q);
92+
printf("y2: 0x%lx\n", (size_t) &q);
9093
// alignment at heap
9194
printf("at heap:\n");
9295
// auto pool = (Area*)malloc(sizeof(Area) * 3);
9396
Area *pool;
9497
// guarantee the address of `pool` multiple of 32(bytes), while `malloc` will not
95-
if (posix_memalign(reinterpret_cast<void**>(&pool), 32, 64 * 3)) {
98+
if (posix_memalign(reinterpret_cast<void **>(&pool), 32, 64 * 3)) {
9699
perror("error while allocate aligned memory\n");
97100
}
98101
// pool = (Area*)malloc(24 * 3);
@@ -108,11 +111,11 @@ void AlignedAllocate() {
108111
pool[1] = {'o', 4};
109112
// it works
110113
// pool[1000] = {'e', 7, 2};
111-
printf("r0: %ld\n", ((size_t)&pool[0]) % 32);
112-
printf("p1: 0x%lx\n", (size_t)&pool[1]);
114+
printf("r0: %ld\n", ((size_t) &pool[0]) % 32);
115+
printf("p1: 0x%lx\n", (size_t) &pool[1]);
113116
// + 48 bytes
114-
printf("p2: 0x%lx\n", (size_t)&pool[2]);
115-
printf("offset: %lu\n", ((char*)&pool[1] - (char*)&pool[0]));
117+
printf("p2: 0x%lx\n", (size_t) &pool[2]);
118+
printf("offset: %lu\n", ((char *) &pool[1] - (char *) &pool[0]));
116119
// printf("%c\n", pool[1].x1);
117120
}
118121

@@ -125,13 +128,13 @@ void Zmalloc() {
125128
// so we can access an element by *(buffer + i), let the pointer move up
126129
char buffer[6] = "kkkkk";
127130
// initialize to 0 when allocated at heap
128-
auto ptr = (float*)malloc(4);
131+
auto ptr = (float *) malloc(4);
129132
// non-successive at heap
130133
// arithmetic on a pointer to void is invalid
131-
auto other = (float*)malloc(4);
134+
auto other = (float *) malloc(4);
132135
// posix_memalign((void**)&ptr, 16, 4);
133-
cout << "ptr: " << (void*)ptr << endl;
134-
printf("other: 0x%lx\n", (size_t)other);
136+
cout << "ptr: " << (void *) ptr << endl;
137+
printf("other: 0x%lx\n", (size_t) other);
135138
// only pointers to compatible type can be subtracted
136139
printf("ptr offset: %lu\n", (other - ptr));
137140
printf("alignof T: %lu\n", alignof(char));
@@ -140,12 +143,12 @@ void Zmalloc() {
140143
cout << "ptr0: " << allocator.ptr << endl;
141144
auto ptr1 = allocator.aligned_malloc<char>();
142145
*ptr1 = 'x';
143-
cout << "ptr1: " << (void*)ptr1 << endl;
146+
cout << "ptr1: " << (void *) ptr1 << endl;
144147
// internal pointer of allocator will be adjusted when std::align has been invoked
145148
// aligned at runtime
146149
auto ptr2 = allocator.aligned_malloc<int>(8);
147150
*ptr2 = 7;
148-
cout << "ptr2: " << (void*)ptr2 << endl;
151+
cout << "ptr2: " << (void *) ptr2 << endl;
149152
// size is 48 bytes when alignment is 16 bytes, and 32 bytes when 8 bytes, 28 bytes when 4 bytes
150153
printf("size of area: %lu\n", sizeof(Area));
151154
Area ka = {'x', 5};
@@ -175,11 +178,6 @@ int main() {
175178
char my_key[] = "lollipop";
176179
memset(my_key, 'k', 6);
177180
printf("%s\n", my_key);
178-
InitMat<6, 6>(mat, 6, 6);
179-
::KMatrix cmat = {6, 5};
180-
cmat.data = (float*)malloc(cmat.width * cmat.height * sizeof(float));
181-
cmat.data[3] = 1;
182-
printf("%.1f\n", cmat.data[3]);
183181
Run();
184182
Zmalloc();
185183
// printf("size is %ld\n", sizeof(st));

0 commit comments

Comments
 (0)