y_nnn: WORK IN PROGRESS... have to save

This commit is contained in:
2025-11-16 00:01:16 +01:00
parent 63d5f63030
commit ea26f5f3bc
9 changed files with 2747 additions and 16 deletions
@@ -2,6 +2,7 @@
#ifndef Y_NETWORK_NEURAL_NETWORK__MANAGER__H_C
#define Y_NETWORK_NEURAL_NETWORK__MANAGER__H_C
#include <pthread.h>
#include <string.h>
#include "learn_to_drive.h"
@@ -51,7 +51,9 @@ struct arg_bash{
int fd_old_bash_pid;
int fd_new_bash_pid;
int fd_current_bash_pid;
pthread_t *thread_launch;
pthread_mutex_t *mut_bash_var;
pthread_cond_t *cond_bash_var;
int go_on;
@@ -19,9 +19,12 @@ void free_arg_run_qlearn_bprint(struct arg_run_qlearn_bprint *arg){
free(arg);
}
void* run_sleep_wait_bash_and_print(void *arg);
void y_nnn_manager_handle_input(char * buf, int len_buf, void *arg){
struct arg_run_qlearn_bprint *run_arg=(struct arg_run_bash_print*)arg;
struct arg_run_qlearn_bprint *run_arg=(struct arg_run_qlearn_bprint*)arg;
struct arg_bash *bash_arg=run_arg->bash_arg;
struct RL_agent *rlAgent = run_arg->rlAgent;
if(arg && (len_buf>0)){
@@ -32,6 +35,27 @@ void y_nnn_manager_handle_input(char * buf, int len_buf, void *arg){
launch_sleep_wait_bash(bash_arg);
}else if(strncmp(buf,"killbash",8)==0){
kill_all_bash(bash_arg);
}else if(strncmp(buf,"stoplearn",9)==0){
pthread_mutex_lock(rlAgent->status->mut_ending);
rlAgent->status->ending=1;
pthread_mutex_unlock(rlAgent->status->mut_ending);
kill_all_bash(bash_arg);
}else if(strncmp(buf,"startprintnewbash",17)==0){
run_newbash(bash_arg);
pthread_t thread_run;
pthread_create(&thread_run, NULL, runBashPrint, arg);
//Sleep(2);
}else if(strncmp(buf,"startprintwaitbash",18)==0){
pthread_t thread_run;
pthread_create(&thread_run, NULL, run_sleep_wait_bash_and_print, arg);
}else if(strncmp(buf,"stopprintbash",13)==0){
pthread_mutex_lock(bash_arg->mut_bash_var);
bash_arg->go_on=0;
pthread_mutex_unlock(bash_arg->mut_bash_var);
}else{
printf("debug: %s is not handle\n",buf);
}
@@ -40,10 +64,29 @@ void y_nnn_manager_handle_input(char * buf, int len_buf, void *arg){
}
void* run_sleep_wait_bash_and_print(void *arg){
struct arg_run_qlearn_bprint *arg_run=(struct arg_run_qlearn_bprint*)arg;
//struct RL_agent *rlAgent = arg_run->rlAgent;
struct arg_bash *bash_arg = arg_run->bash_arg;
wait_sleep_newbash(bash_arg);
return runBashPrint(arg);
}
void wait_valid_pid_bash(struct arg_bash *bash_arg){
pthread_mutex_lock(bash_arg->mut_bash_var);
while(
(bash_arg->fd_new_bash_pid == -1) &&
(bash_arg->fd_current_bash_pid == -1)
){
printf("debug: wait new bash!\n");
pthread_cond_wait(bash_arg->cond_bash_var, bash_arg->mut_bash_var);
}
pthread_mutex_unlock(bash_arg->mut_bash_var);
}
void* runBashPrint(void *arg){
struct arg_run_bash_print *arg_run=(struct arg_run_bash_print*)arg;
struct arg_run_qlearn_bprint *arg_run=(struct arg_run_qlearn_bprint*)arg;
struct RL_agent *rlAgent = arg_run->rlAgent;
struct arg_bash *bash_arg = arg_run->bash_arg;
@@ -53,6 +96,10 @@ void* runBashPrint(void *arg){
size_t count_print = 0;
char buf[SIZE_LOCAL_BUF];
int len_buf;
wait_valid_pid_bash(bash_arg);
printf("debug: start runBashPrint in episode: %ld\n",qlStatus->index_episode);
while((new_bash_exist(bash_arg)) && check_go_on_print_params(pprint) && !is_ending(qlStatus)){
if(/*(qlStatus->nb_episodes %125 == 0) &&*/ pprint->printed){
//pthread_mutex_lock(&(pprint->mut_printed));
@@ -64,7 +111,7 @@ void* runBashPrint(void *arg){
len_buf=sprintf(buf,"%s ",pprint->string_space);
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf)
////printf("ep: %ld\n",qlStatus->index_episode);
////printf("ep: %ld ",qlStatus->index_episode);
len_buf=sprintf(buf,"ep: %ld\n",qlStatus->index_episode);
BASH_WRITE_IF_EXIST(bash_arg, buf, len_buf)
neurons_TYPE_FLOAT * net_main = rlAgent->networks->main_net;
@@ -104,5 +151,11 @@ void* runBashPrint(void *arg){
clear_screen();
}
}
printf("debug: end runBashPrint\n");
return NULL;
}
// 0 if filename it exists
int file_exists(char *filename){
return access(filename, F_OK);
}
@@ -109,6 +109,7 @@ struct arg_bash *create_arg_bash(){
pthread_cond_init(b_arg->cond_bash_var,NULL);
b_arg->go_on=1;
b_arg->thread_launch=NULL;
return b_arg;
}
@@ -130,11 +131,16 @@ void free_arg_bash(struct arg_bash *arg){
kill(arg->current_bash_pid, SIGKILL);
}
if(arg->thread_launch){
pthread_join(*(arg->thread_launch), NULL);
free(arg->thread_launch);
}
free(arg);
}
int new_bash_exist(struct arg_bash *bash_arg){
return ((bash_arg->fd_new_bash_pid>0) || (bash_arg->fd_current_bash_pid));
return ((bash_arg->fd_new_bash_pid>0) || (bash_arg->fd_current_bash_pid>0));
}
/* run new bash terminal graphic, can be called directly or in a thread */
@@ -153,14 +159,23 @@ if(arg->new_bash_pid == arg->old_bash_pid){
}else{
wait(NULL);
usleep(20000);
pthread_mutex_lock(arg->mut_bash_var);
arg->new_bash_pid=pidof("bash",NULL);
if(arg->new_bash_pid > arg->old_bash_pid){
arg->new_bash_pid = pidof("bash",NULL);
arg->fd_new_bash_pid = open_duplicate_bash(arg->new_bash_pid);
while(arg->new_bash_pid == arg->old_bash_pid)
{
printf("debug: create new terminal: %d vs %d\n",arg->new_bash_pid,arg->old_bash_pid);
getchar();
arg->new_bash_pid = pidof("bash",NULL);
arg->fd_new_bash_pid = open_duplicate_bash(arg->new_bash_pid);
printf("runnewbash: ready\n");
//usleep(2000);
}
pthread_mutex_unlock(arg->mut_bash_var);
pthread_cond_signal(arg->cond_bash_var);
printf("debug: send signal run_newbash\n");
}
}
+1 -1
View File
@@ -127,7 +127,7 @@ DEPLIBS=$(NETNEURNETDIR) $(YTESTDIR) $(YSOCKET_DIR) $(DEEPQLEARNDIR)
INCLUDE=$(INCLUDE_NNN) $(INCLUDE_SOCKET) $(INCLUDE_DEEPQLEARN)
CFLAGS=-Wall -lOpenCL -lm -lpthread -Werror -fpic $(INCLUDE) #-lcurses
CFLAGS=-Wall -lOpenCL -lm -lpthread -Werror -fpic $(INCLUDE) #-lcurses -lexplain
#LDFLAGS=-L$(YTESTDIR) -lytest -lOpenCL -lm -lpthread #-lcurses
File diff suppressed because it is too large Load Diff