Implement basis for thread management.
This commit is contained in:
parent
594b6ef722
commit
0b4cc27331
7 changed files with 38 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
|||
# CMake entry point
|
||||
cmake_minimum_required (VERSION 3.27.1)
|
||||
cmake_minimum_required (VERSION 3.30.5)
|
||||
project(CX C)
|
||||
cmake_policy(SET CMP0072 NEW)
|
||||
|
||||
|
@ -17,6 +17,7 @@ set(ALL_LIBS
|
|||
glfw
|
||||
GLEW
|
||||
m
|
||||
pthread
|
||||
)
|
||||
|
||||
set(CMAKE_C_FLAGS "-O0 -ggdb -Wall")
|
||||
|
|
17
include/cx.h
17
include/cx.h
|
@ -9,6 +9,7 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
|
||||
// Include GLEW
|
||||
#include <GL/glew.h>
|
||||
|
@ -24,13 +25,27 @@
|
|||
#include <shader.h>
|
||||
#include <neural.h>
|
||||
|
||||
// Declare common data structures.
|
||||
|
||||
typedef struct _cx_thrgr {
|
||||
pthread_t *group_manager;
|
||||
pthread_t *workers;
|
||||
} CX_ThreadGroup;
|
||||
|
||||
typedef struct _cx_ctx {
|
||||
GLFWwindow *window;
|
||||
Neural_Network *nn;
|
||||
CX_ThreadGroup **threads;
|
||||
} CX_Context;
|
||||
|
||||
// Declare functions
|
||||
|
||||
CX_Context *cx_context_new(void);
|
||||
|
||||
int cx_glinit(GLFWwindow **);
|
||||
int cx_nninit(Neural_Network **);
|
||||
|
||||
int cx_run(GLFWwindow *, Neural_Network *);
|
||||
int cx_run(CX_Context *);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
12
src/cx.c
12
src/cx.c
|
@ -156,7 +156,7 @@ cx_nnrun(Neural_Network *nn) {
|
|||
}
|
||||
|
||||
int
|
||||
cx_run(GLFWwindow *window, Neural_Network *nn) {
|
||||
cx_run(CX_Context *cx_ctx) {
|
||||
ModelRegistry *mr;
|
||||
GLuint VertexArrayID;
|
||||
GLuint programID;
|
||||
|
@ -168,19 +168,19 @@ cx_run(GLFWwindow *window, Neural_Network *nn) {
|
|||
// Establish a model registry
|
||||
mr = modelRegistry_new();
|
||||
// Fill the model registry with mesh models
|
||||
neural_getMesh(nn, mr);
|
||||
neural_getMesh(cx_ctx->nn, mr);
|
||||
|
||||
// Remainder from cursor experiments, might be useful later
|
||||
double xpos, ypos;
|
||||
glfwGetCursorPos(window, &xpos, &ypos);
|
||||
glfwGetCursorPos(cx_ctx->window, &xpos, &ypos);
|
||||
|
||||
|
||||
do {
|
||||
cx_glrender(window, programID, mr);
|
||||
cx_glrender(cx_ctx->window, programID, mr);
|
||||
usleep(1000000/60);
|
||||
// Check if the ESC key was pressed or the window was closed
|
||||
} while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS
|
||||
&& !glfwWindowShouldClose(window));
|
||||
} while(glfwGetKey(cx_ctx->window, GLFW_KEY_ESCAPE) != GLFW_PRESS
|
||||
&& !glfwWindowShouldClose(cx_ctx->window));
|
||||
|
||||
// Close OpenGL window and terminate GLFW
|
||||
glfwTerminate();
|
||||
|
|
16
src/main.c
16
src/main.c
|
@ -1,27 +1,23 @@
|
|||
// Include standard headers
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
// Include project headers
|
||||
#include <cx.h>
|
||||
|
||||
|
||||
int
|
||||
main(void) {
|
||||
CX_Context *cx_ctx;
|
||||
cx_ctx = calloc(1, sizeof(CX_Context));
|
||||
GLFWwindow *window;
|
||||
Neural_Network *nn;
|
||||
|
||||
int retval;
|
||||
|
||||
if (cx_glinit(&window)) {
|
||||
if (cx_glinit(&(cx_ctx->window))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (cx_nninit(&nn)) {
|
||||
if (cx_nninit(&(cx_ctx->nn))) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
retval = cx_run(window, nn);
|
||||
retval = cx_run(cx_ctx);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
Model *
|
||||
model_new(size_t size) {
|
||||
Model *self = calloc(1, sizeof(Model));
|
||||
self->object = calloc((size ? size : 1) *4 , sizeof(GLfloat));
|
||||
self->colors = calloc((size ? size : 1) *3 , sizeof(GLfloat));
|
||||
self->object = calloc((size ? size : 1) * 4 , sizeof(GLfloat));
|
||||
self->colors = calloc((size ? size : 1) * 3 , sizeof(GLfloat));
|
||||
self->bufsize = size;
|
||||
self->transformations = calloc(8 , sizeof(Tensor *));
|
||||
self->transformations = calloc(8, sizeof(Tensor *));
|
||||
self->transformation_size = 8;
|
||||
self->transformation_count = 0;
|
||||
return self;
|
||||
|
|
|
@ -28,6 +28,7 @@ neural_new(size_t input_size, size_t output_size, size_t layer_count) {
|
|||
// Failed to allocate.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// The difference between layer sizes, hidden layers step between the two
|
||||
// sizes in linear fashion.
|
||||
ssize_t layer_diff;
|
||||
|
|
|
@ -34,6 +34,10 @@ tensor_fromVertexBuffer(float *buffer, size_t bufsize) {
|
|||
return mat;
|
||||
}
|
||||
|
||||
Tensor *
|
||||
tensor_fromNeuralData(Neural_Data *nd) {
|
||||
}
|
||||
|
||||
Tensor *
|
||||
tensor_multip(Tensor *mat2, Tensor *mat1) {
|
||||
Tensor *result;
|
||||
|
|
Loading…
Reference in a new issue