Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions CSG/CU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
#include "cuda_runtime.h"
#include "CUDA_CHECK.h"

#ifdef WITH_SLOG
#include "SLOG.hh"
#endif

#include "CSGSolid.h"
#include "CSGPrim.h"
Expand All @@ -19,19 +17,15 @@

#include "CU.h"

#ifdef WITH_SLOG
const plog::Severity CU::LEVEL = SLOG::EnvLevel("CU","DEBUG");
#endif




template <typename T>
T* CU::AllocArray(unsigned num_items ) // static
{
#ifdef WITH_SLOG
LOG(LEVEL) << " num_items " << num_items ;
#endif
T* d_array = nullptr ;
CUDA_CHECK( cudaMalloc(reinterpret_cast<void**>( &d_array ), num_items*sizeof(T) ));
return d_array ;
Expand All @@ -49,9 +43,7 @@ Allocate on device and copy from host to device
template <typename T>
T* CU::UploadArray(const T* array, unsigned num_items ) // static
{
#ifdef WITH_SLOG
LOG(LEVEL) << " num_items " << num_items ;
#endif
T* d_array = nullptr ;
CUDA_CHECK( cudaMalloc(reinterpret_cast<void**>( &d_array ), num_items*sizeof(T) ));
CUDA_CHECK( cudaMemcpy(reinterpret_cast<void*>( d_array ), array, sizeof(T)*num_items, cudaMemcpyHostToDevice ));
Expand All @@ -70,9 +62,7 @@ Allocate on host and copy from device to host
template <typename T>
T* CU::DownloadArray(const T* d_array, unsigned num_items ) // static
{
#ifdef WITH_SLOG
LOG(LEVEL) << " num_items " << num_items ;
#endif
T* array = new T[num_items] ;
CUDA_CHECK( cudaMemcpy( array, d_array, sizeof(T)*num_items, cudaMemcpyDeviceToHost ));
return array ;
Expand Down Expand Up @@ -114,9 +104,7 @@ T* CU::UploadVec(const std::vector<T>& vec)
{
unsigned num_items = vec.size() ;
unsigned num_bytes = num_items*sizeof(T) ;
#ifdef WITH_SLOG
LOG(LEVEL) << " num_items " << num_items ;
#endif
T* d_array = nullptr ;
CUDA_CHECK( cudaMalloc(reinterpret_cast<void**>( &d_array ), num_bytes ));
CUDA_CHECK( cudaMemcpy(reinterpret_cast<void*>( d_array ), vec.data(), num_bytes, cudaMemcpyHostToDevice ));
Expand All @@ -131,9 +119,7 @@ template CSG_API unsigned* CU::UploadVec<unsigned>(const std::vector<unsigned>&
template <typename T>
void CU::DownloadVec(std::vector<T>& vec, const T* d_array, unsigned num_items) // static
{
#ifdef WITH_SLOG
LOG(LEVEL) << " num_items " << num_items ;
#endif
unsigned num_bytes = num_items*sizeof(T) ;
vec.clear();
vec.resize(num_items);
Expand All @@ -157,6 +143,3 @@ void CU::ConfigureLaunch1D( dim3& numBlocks, dim3& threadsPerBlock, unsigned num
numBlocks.y = 1 ;
numBlocks.z = 1 ;
}



7 changes: 1 addition & 6 deletions CSG/CU.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ CU.h : UploadArray/DownloadArray/UploadVec/DownloadVec
./CSG/CSGFoundry.cc

**/

#ifdef WITH_SLOG
#include "plog/Severity.h"
#endif

struct dim3 ;
#include <vector>
#include "CSG_API_EXPORT.hh"

struct CSG_API CU
{
#ifdef WITH_SLOG
static const plog::Severity LEVEL ;
#endif
static const plog::Severity LEVEL;

template <typename T>
static T* AllocArray(unsigned num_items ) ;
Expand Down
2 changes: 1 addition & 1 deletion CSGOptiX/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ foreach(cu_src IN LISTS OPTIX_SOURCES)
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/qudarap>)
target_compile_definitions(${cu_src} PUBLIC WITH_PRD WITH_SIMULATE WITH_SIMTRACE WITH_RENDER
OPTICKS_CSGOPTIX WITH_THRUST OPTICKS_CSG WITH_CONTIGUOUS WITH_S_BB CONFIG_Debug OPTICKS_SYSRAP WITH_CHILD
PLOG_LOCAL RNG_PHILOX DEBUG_TAG DEBUG_PIDX DEBUG_PIDXYZ WITH_STTF WITH_SLOG OPTICKS_OKCONF OPTICKS_QUDARAP NVCC)
PLOG_LOCAL RNG_PHILOX DEBUG_TAG DEBUG_PIDX DEBUG_PIDXYZ OPTICKS_OKCONF OPTICKS_QUDARAP NVCC)
target_link_libraries(${cu_src} PUBLIC OptiX::OptiX)

list(APPEND _generated_PTX_files "${cu_src}.ptx")
Expand Down
50 changes: 11 additions & 39 deletions CSGOptiX/CSGOptiX.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1190,21 +1190,13 @@ std::string CSGOptiX::AnnotationTime( double dt, const char* extra ) // static
std::string str = ss.str();
return str ;
}
std::string CSGOptiX::Annotation( double dt, const char* bot_line, const char* extra ) // static
{
std::stringstream ss ;
ss << AnnotationTime(dt, extra) ;
if(bot_line) ss << std::setw(30) << " " << bot_line ;
std::string str = ss.str();
return str ;
}

const char* CSGOptiX::getDefaultSnapPath() const
{
assert( foundry );
const char* cfbase = foundry->getOriginCFBase();
assert( cfbase );
const char* path = SPath::Resolve(cfbase, "CSGOptiX/snap.jpg" , FILEPATH );
const char* path = SPath::Resolve(cfbase, "CSGOptiX/snap.npy", FILEPATH);
return path ;
}

Expand Down Expand Up @@ -1305,11 +1297,11 @@ void CSGOptiX::render_save_(const char* stem_, bool inverted)
const char* stem = stem_ ? stem_ : getRenderStemDefault() ; // without ext

bool unique = true ;
const char* outpath = SEventConfig::OutPath(stem, -1, ".jpg", unique );
const char* outpath = SEventConfig::OutPath(stem, -1, ".npy", unique);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve snapshot image output format

Changing render_save_ to emit .npy (SEventConfig::OutPath(..., ".npy", ...)) turns renderer snapshots into raw arrays instead of image files, which breaks existing CSGOptiX workflows that consume .jpg frames (for example CSGOptiX/cxr_flight.sh expects *_00000.jpg and invokes ffmpeg_jpg_to_mp4.sh, and CSGOptiX/grab.sh syncs *.jpg). In practice, users pressing snap in interactive/render scripts will no longer produce the files those downstream tools are built around.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, the observation is technically correct: this PR changes renderer snapshots from .jpg image output to .npy frame dumps while some legacy CSGOptiX scripts still assume .jpg frames. That said, preserving .jpg output is not the direction of this PR; in-repo visualization/image publishing is being retired. I’ll treat the remaining JPG-oriented scripts/docs as follow-up cleanup rather than restoring the old SIMG/STTF image path.


LOG(LEVEL)
<< SEventConfig::DescOutPath(stem, -1, ".jpg", unique );
;
<< SEventConfig::DescOutPath(stem, -1, ".npy", unique);
;

std::string u_outdir ;
std::string u_stem ;
Expand All @@ -1320,37 +1312,25 @@ void CSGOptiX::render_save_(const char* stem_, bool inverted)

sglm->addlog("CSGOptiX::render_snap", u_stem.c_str() );


const char* topline = ssys::getenvvar("TOPLINE", sproc::ExecutableName() );
std::string _extra = SEventConfig::GetGPUMeta(); // scontext::brief giving GPU name
const char* extra = strdup(_extra.c_str()) ;

const char* botline_ = ssys::getenvvar("BOTLINE", nullptr );
std::string bottom_line = CSGOptiX::Annotation(kernel_dt, botline_, extra );
const char* botline = bottom_line.c_str() ;


LOG(LEVEL)
<< " stem " << stem
<< " outpath " << outpath
<< " outdir " << ( outdir ? outdir : "-" )
<< " kernel_dt " << kernel_dt
<< " topline [" << topline << "]"
<< " botline [" << botline << "]"
;

LOG(info) << outpath << " : " << AnnotationTime(kernel_dt, extra) ;

unsigned line_height = 24 ;
snap(outpath, botline, topline, line_height, inverted );

snap(outpath, inverted);

sglm->save( u_outdir.c_str(), u_stem.c_str() );
}


/**
CSGOptiX::snap : Download frame pixels and write to file as jpg.
CSGOptiX::snap : Download frame pixels and write to file as NPY.
------------------------------------------------------------------

WIP: contrast this with SGLFW::snap_local and consider if more consolidation is possible
Expand All @@ -1364,16 +1344,11 @@ CSGOptiX::snap

**/

void CSGOptiX::snap(const char* path_, const char* bottom_line, const char* top_line, unsigned line_height, bool inverted )
void CSGOptiX::snap(const char* path_, bool inverted)
{
const char* path = path_ ? SPath::Resolve(path_, FILEPATH ) : getDefaultSnapPath() ;
LOG(LEVEL) << " path " << path ;

const char* top_extra = pip->desc();
const char* topline = SStr::Concat(top_line, top_extra);

LOG(LEVEL) << " path_ [" << path_ << "]" ;
LOG(LEVEL) << " topline " << topline ;

LOG(LEVEL) << "[ frame.download " ;
if( inverted == false )
Expand All @@ -1386,10 +1361,6 @@ void CSGOptiX::snap(const char* path_, const char* bottom_line, const char* top_
}
LOG(LEVEL) << "] frame.download " ;

LOG(LEVEL) << "[ frame.annotate " ;
framebuf->annotate( bottom_line, topline, line_height );
LOG(LEVEL) << "] frame.annotate " ;

LOG(LEVEL) << "[ frame.snap " ;
framebuf->snap( path );
LOG(LEVEL) << "] frame.snap " ;
Expand All @@ -1414,13 +1385,14 @@ int CSGOptiX::render_flightpath() // for making mp4 movies
return 1 ;
}

void CSGOptiX::saveMeta(const char* jpg_path) const
void CSGOptiX::saveMeta(const char* path) const
{
const char* json_path = SStr::ReplaceEnd(jpg_path, ".jpg", ".json");
const char* json_path = SStr::ReplaceEnd(path, ".npy", ".json");
LOG(LEVEL) << "[ json_path " << json_path ;

nlohmann::json& js = meta->js ;
js["jpg"] = jpg_path ;
js["path"] = path;
js["npy"] = path;
js["emm"] = SGeoConfig::EnabledMergedMesh() ;

if(foundry->hasMeta())
Expand Down
7 changes: 2 additions & 5 deletions CSGOptiX/CSGOptiX.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,15 @@ struct CSGOPTIX_API CSGOptiX : public SSimulator
public:
const CSGFoundry* getFoundry() const ;
static std::string AnnotationTime( double dt, const char* extra=nullptr );
static std::string Annotation( double dt, const char* bot_line, const char* extra=nullptr );
const char* getDefaultSnapPath() const ;
//void snap(const char* path=nullptr, const char* bottom_line=nullptr, const char* top_line=nullptr, unsigned line_height=24, bool inverted=false ); // part of SRenderer protocol base
void snap(const char* path, const char* bottom_line, const char* top_line, unsigned line_height, bool inverted ); // part of SRenderer protocol base

void snap(const char* path, bool inverted); // part of SRenderer protocol base

#ifdef WITH_FRAME_PHOTON
void writeFramePhoton(const char* dir, const char* name);
#endif
int render_flightpath();

void saveMeta(const char* jpg_path) const ;
void saveMeta(const char* path) const;

static constexpr const char* CTX_LOGNAME = "CSGOptiX__Ctx.log" ;
void write_Ctx_log(const char* dir=nullptr) const ;
Expand Down
66 changes: 15 additions & 51 deletions CSGOptiX/Frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,14 @@

#include "SFrameConfig.hh"
#include "SComp.h"
#include "SStr.hh"
#include "SPath.hh"
#include "SLOG.hh"
#include "NP.hh"
#include "Frame.h"

#define SIMG_IMPLEMENTATION 1
#include "SIMG.h"


const plog::Severity Frame::LEVEL = SLOG::EnvLevel("Frame", "DEBUG" );

unsigned Frame::getNumPixels() const
{
return num_pixels ;
}

/**
Frame::Frame
--------------
Expand Down Expand Up @@ -58,8 +49,6 @@ Frame::Frame(int width_, int height_, int depth_, uchar4* d_pixel_, float4* d_is
height(height_),
depth(depth_),
channels(4),
jpg_quality(SStr::GetEValue<int>("QUALITY", 50)),
img(new SIMG(width, height, channels, nullptr )),
num_pixels(width*height),
d_pixel(d_pixel_ == nullptr ? DeviceAlloc<uchar4>(num_pixels, mask & SCOMP_PIXEL ) : d_pixel_ ),
d_isect(d_isect_ == nullptr ? DeviceAlloc<float4>(num_pixels, mask & SCOMP_ISECT ) : d_isect_ ),
Expand Down Expand Up @@ -107,10 +96,8 @@ void Frame::download_(bool flip_vertical)
if(d_fphoton) QU::Download<quad4>(photon, d_fphoton, num_pixels );
#endif

if(d_pixel)
{
img->setData( getPixelData(), flip_vertical );
}
if (d_pixel && flip_vertical)
flipPixelVertical();
}

void Frame::download()
Expand All @@ -122,46 +109,24 @@ void Frame::download_inverted()
download_(false);
}



unsigned char* Frame::getPixelData() const { return d_pixel ? (unsigned char*)pixel.data() : nullptr ; }
float* Frame::getIntersectData() const { return d_isect ? (float*)isect.data() : nullptr ; }
#ifdef WITH_FRAME_PHOTON
float* Frame::getFPhotonData() const { return d_fphoton ? (float*)fphoton.data() : nullptr ; }
#endif

void Frame::annotate( const char* bottom_line, const char* top_line, int line_height )
void Frame::flipPixelVertical()
{
img->annotate( bottom_line, top_line, line_height );
for (int y = 0; y < height / 2; y++)
for (int x = 0; x < width; x++)
{
std::swap(pixel[y * width + x], pixel[(height - 1 - y) * width + x]);
}
}

void Frame::write(const char* outdir_, int quality) const
void Frame::writePixels(const char* path) const
{
const char* outdir = SPath::Resolve(outdir_, DIRPATH);
writePNG(outdir, "f_pixels.png");
writeJPG(outdir, "f_pixels.jpg", quality);
writeIsect(outdir, "f_isect.npy" ); // formerly posi.npy
#ifdef WITH_FRAME_PHOTON
writeFPhoton(outdir, "f_photon.npy" );
#endif
}

void Frame::writePNG(const char* dir, const char* name) const
{
img->writePNG(dir, name);
}
void Frame::writePNG(const char* path) const
{
img->writePNG(path);
}

void Frame::writeJPG(const char* dir, const char* name, int quality) const
{
img->writeJPG(dir, name, quality > 0 ? quality : jpg_quality );
}
void Frame::writeJPG(const char* path, int quality) const
{
img->writeJPG(path, quality > 0 ? quality : jpg_quality );
if (d_pixel)
NP::Write(path, (unsigned char*)pixel.data(), height, width, channels);
}


Expand All @@ -181,12 +146,11 @@ void Frame::writeFPhoton( const char* dir, const char* name) const

void Frame::snap( const char* path )
{
LOG(LEVEL) << "[" ;

LOG(LEVEL) << "[ writeJPG " ;
writeJPG( path );
LOG(LEVEL) << "] writeJPG " ;
LOG(LEVEL) << "[";

LOG(LEVEL) << "[ writePixels ";
writePixels(path);
LOG(LEVEL) << "] writePixels ";

LOG(LEVEL) << "[ writeIntersectData " ;
const char* fold = SPath::Dirname(path);
Expand Down
Loading
Loading