Add new mju_threadpool API function, and delete old threading API.
PiperOrigin-RevId: 922838541 Change-Id: Id9f7e0fb298ffde61fcc49a802dc78971858ce51
This commit is contained in:
committed by
Copybara-Service
parent
a22fc2423a
commit
b935d4153c
@@ -20,7 +20,6 @@
|
||||
#include <mujoco/mjplugin.h>
|
||||
#include <mujoco/mjrender.h>
|
||||
#include <mujoco/mjspec.h>
|
||||
#include <mujoco/mjthread.h>
|
||||
#include <mujoco/mjtype.h>
|
||||
#include <mujoco/mjui.h>
|
||||
#include <mujoco/mjvisualize.h>
|
||||
@@ -123,9 +122,6 @@ MJ_ASSERT_SIZE(mjtEvent, 4);
|
||||
MJ_ASSERT_SIZE(mjtItem, 4);
|
||||
MJ_ASSERT_SIZE(mjtSection, 4);
|
||||
|
||||
// mjthread.h
|
||||
MJ_ASSERT_SIZE(mjtTaskStatus, 4);
|
||||
|
||||
// mjplugin.h
|
||||
MJ_ASSERT_SIZE(mjtPluginCapabilityBit, 4);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include <mujoco/mjtype.h>
|
||||
#include <mujoco/mjmodel.h>
|
||||
#include <mujoco/mjthread.h>
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -112,9 +112,12 @@ struct mjData_ {
|
||||
// arena pointer
|
||||
size_t parena; // first available byte in arena
|
||||
|
||||
// threading
|
||||
uintptr_t threadpool; // thread pool pointer
|
||||
mjtBool threadlock; // disable stack freeing during threaded execution
|
||||
|
||||
// memory utilization statistics
|
||||
mjtSize maxuse_stack; // maximum stack allocation in bytes (mutable)
|
||||
mjtSize maxuse_threadstack[mjMAXTHREAD]; // maximum stack allocation per thread in bytes
|
||||
mjtSize maxuse_arena; // maximum arena allocation in bytes
|
||||
int maxuse_con; // maximum number of contacts
|
||||
int maxuse_efc; // maximum number of scalar constraints
|
||||
@@ -417,9 +420,6 @@ struct mjData_ {
|
||||
mjtNum* efc_force; // constraint force in constraint space (nefc x 1)
|
||||
mjtNum* ifrc_constraint; // constraint force (nidof x 1)
|
||||
|
||||
// thread pool pointer
|
||||
uintptr_t threadpool;
|
||||
|
||||
// compilation signature
|
||||
uint64_t signature; // also held by the mjSpec that compiled the model
|
||||
};
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 2023 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef MUJOCO_INCLUDE_MJTHREAD_H_
|
||||
#define MUJOCO_INCLUDE_MJTHREAD_H_
|
||||
|
||||
#define mjMAXTHREAD 128 // maximum number of threads in a thread pool
|
||||
|
||||
typedef enum mjtTaskStatus_ { // status values for mjTask
|
||||
mjTASK_NEW = 0, // newly created
|
||||
mjTASK_QUEUED, // enqueued in a thread pool
|
||||
mjTASK_COMPLETED // completed execution
|
||||
} mjtTaskStatus;
|
||||
|
||||
// function pointer type for mjTask
|
||||
typedef void* (*mjfTask)(void*);
|
||||
|
||||
// An opaque type representing a thread pool.
|
||||
struct mjThreadPool_ {
|
||||
int nworker; // number of workers in the pool
|
||||
};
|
||||
typedef struct mjThreadPool_ mjThreadPool;
|
||||
|
||||
struct mjTask_ { // a task that can be executed by a thread pool.
|
||||
mjfTask func; // pointer to the function that implements the task
|
||||
void* args; // arguments to func
|
||||
volatile int status; // status of the task
|
||||
};
|
||||
typedef struct mjTask_ mjTask;
|
||||
|
||||
#endif // MUJOCO_INCLUDE_MJTHREAD_H_
|
||||
@@ -1014,6 +1014,7 @@
|
||||
X( size_t, pstack ) \
|
||||
X( size_t, pbase ) \
|
||||
X( size_t, parena ) \
|
||||
X( uintptr_t, threadpool ) \
|
||||
X( size_t, maxuse_stack ) \
|
||||
X( size_t, maxuse_arena ) \
|
||||
X( int, maxuse_con ) \
|
||||
@@ -1036,13 +1037,11 @@
|
||||
X( mjtBool, flg_energyvel ) \
|
||||
X( mjtBool, flg_subtreevel ) \
|
||||
X( mjtBool, flg_rnepost ) \
|
||||
X( mjtNum, time ) \
|
||||
X( uintptr_t, threadpool )
|
||||
X( mjtNum, time )
|
||||
|
||||
|
||||
// vector fields of mjData
|
||||
#define MJDATA_VECTOR \
|
||||
X( size_t, maxuse_threadstack, mjMAXTHREAD, 1 ) \
|
||||
X( mjSolverStat, solver, mjNISLAND, mjNSOLVER ) \
|
||||
X( int, solver_niter, mjNISLAND, 1 ) \
|
||||
X( int, solver_nnz, mjNISLAND, 1 ) \
|
||||
|
||||
+2
-18
@@ -31,7 +31,6 @@
|
||||
#include <mujoco/mjrender.h>
|
||||
#include <mujoco/mjsan.h>
|
||||
#include <mujoco/mjspec.h>
|
||||
#include <mujoco/mjthread.h>
|
||||
#include <mujoco/mjtype.h>
|
||||
#include <mujoco/mjui.h>
|
||||
#include <mujoco/mjvisualize.h>
|
||||
@@ -1593,23 +1592,8 @@ MJAPI mjSpec* mju_decodeResource(mjResource* resource, const char* content_type,
|
||||
|
||||
//---------------------------------- Threads -------------------------------------------------------
|
||||
|
||||
// Create a thread pool with the specified number of threads running.
|
||||
MJAPI mjThreadPool* mju_threadPoolCreate(size_t number_of_threads);
|
||||
|
||||
// Adds a thread pool to mjData and configures it for multi-threaded use.
|
||||
MJAPI void mju_bindThreadPool(mjData* d, void* thread_pool);
|
||||
|
||||
// Enqueue a task in a thread pool.
|
||||
MJAPI void mju_threadPoolEnqueue(mjThreadPool* thread_pool, mjTask* task);
|
||||
|
||||
// Destroy a thread pool.
|
||||
MJAPI void mju_threadPoolDestroy(mjThreadPool* thread_pool);
|
||||
|
||||
// Initialize an mjTask.
|
||||
MJAPI void mju_defaultTask(mjTask* task);
|
||||
|
||||
// Wait for a task to complete.
|
||||
MJAPI void mju_taskJoin(mjTask* task);
|
||||
// Create a thread pool with nthread worker threads.
|
||||
MJAPI void mju_threadpool(mjData* d, int nthread);
|
||||
|
||||
|
||||
//---------------------------------- Attachment ----------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user