Skip to content

Commit

Permalink
Update Lecture7
Browse files Browse the repository at this point in the history
  • Loading branch information
bluekds committed Oct 14, 2021
1 parent 3c5d6f1 commit e9fcf70
Show file tree
Hide file tree
Showing 7 changed files with 926 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CUDA_Programming.sln
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lecture6", "Lecture6", "{3D
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ThreadCounting_AtomicOp", "VS2019\Intermediate_Class\Lecture6\ThreadCounting_AtomicOp\ThreadCounting_AtomicOp.vcxproj", "{E36C456D-0161-426E-B305-E119C40B480F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lecture7", "Lecture7", "{8C2E78EF-0AF9-4AD6-B1E3-2A3BB7DB2798}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Stream", "VS2019\Intermediate_Class\Lecture7\Stream\Stream.vcxproj", "{AFD873F0-6742-40CC-A371-FFB188BC1AC1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lecture8", "Lecture8", "{40E3E314-3859-4C01-BCD7-331540F33D08}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand Down Expand Up @@ -161,6 +167,14 @@ Global
{E36C456D-0161-426E-B305-E119C40B480F}.Release|x64.Build.0 = Release|x64
{E36C456D-0161-426E-B305-E119C40B480F}.Release|x86.ActiveCfg = Release|Win32
{E36C456D-0161-426E-B305-E119C40B480F}.Release|x86.Build.0 = Release|Win32
{AFD873F0-6742-40CC-A371-FFB188BC1AC1}.Debug|x64.ActiveCfg = Debug|x64
{AFD873F0-6742-40CC-A371-FFB188BC1AC1}.Debug|x64.Build.0 = Debug|x64
{AFD873F0-6742-40CC-A371-FFB188BC1AC1}.Debug|x86.ActiveCfg = Debug|Win32
{AFD873F0-6742-40CC-A371-FFB188BC1AC1}.Debug|x86.Build.0 = Debug|Win32
{AFD873F0-6742-40CC-A371-FFB188BC1AC1}.Release|x64.ActiveCfg = Release|x64
{AFD873F0-6742-40CC-A371-FFB188BC1AC1}.Release|x64.Build.0 = Release|x64
{AFD873F0-6742-40CC-A371-FFB188BC1AC1}.Release|x86.ActiveCfg = Release|Win32
{AFD873F0-6742-40CC-A371-FFB188BC1AC1}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -190,6 +204,9 @@ Global
{8D608736-D0A2-4D23-BED7-641B87D5F4C1} = {EF9A42B1-29F7-4349-827D-08B3B5D95ECA}
{3DEBB45B-FF8B-4776-BFF5-D68A48058E79} = {B3430C43-00B8-443C-A7C2-DCF639AEADD1}
{E36C456D-0161-426E-B305-E119C40B480F} = {3DEBB45B-FF8B-4776-BFF5-D68A48058E79}
{8C2E78EF-0AF9-4AD6-B1E3-2A3BB7DB2798} = {B3430C43-00B8-443C-A7C2-DCF639AEADD1}
{AFD873F0-6742-40CC-A371-FFB188BC1AC1} = {8C2E78EF-0AF9-4AD6-B1E3-2A3BB7DB2798}
{40E3E314-3859-4C01-BCD7-331540F33D08} = {B3430C43-00B8-443C-A7C2-DCF639AEADD1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {52DE253B-6715-4A93-BA27-7131973681F9}
Expand Down
197 changes: 197 additions & 0 deletions Intermediate_Class/Lecture7/Stream/DS_definitions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

#define OS_WINDOWS 0
#define OS_LINUX 1

#ifdef _WIN32
#define _TARGET_OS OS_WINDOWS
#else
#ifndef nullptr
#define nullptr NULL
#endif
#define _TARGET_OS OS_LINUX
#endif

/************************************************************************/
/* OS dependet function */
/************************************************************************/
#if _TARGET_OS == OS_WINDOWS
// #define _SPRINT sprintf_s
#define _STRTOK strtok_s

#define EXIT_WIHT_KEYPRESS {std::cout << "Press any key to exit..."; getchar(); exit(0);}

#define SPLIT_PATH(_path,_result) \
_splitpath_s(_path, _result.drive, 255, _result.dir, 255, _result.filename, 255, _result.ext, 255)


#elif _TARGET_OS == OS_LINUX
#include <libgen.h>
#include <inttypes.h>

#define _STRTOK strtok_r

#define EXIT_WIHT_KEYPRESS {std::cout << "Program was terminated!"; exit(0);}

#define sprintf_s sprintf
#define scanf_s scanf
#define fprintf_s fprintf

#define __int64 int64_t

#define fopen_s(fp, name, mode) (*fp = fopen(name, mode))

#endif

/************************************************************************/
/* Defines */
/************************************************************************/

// *********** data size
#define _1K_ 1024
#define _1M_ (_1K_*_1K_)
#define _1G_ (_1M_*_1K_)

#define CHAR_STRING_SIZE 255

/************************************************************************/
/* Type definitions */
/************************************************************************/
typedef unsigned int UINT ;

/************************************************************************/
/* Macro functions */
/************************************************************************/
#define DS_MEM_DELETE(a) \
if (a != NULL) { \
delete a ; \
a = NULL ; \
}

#define DS_MEM_DELETE_ARRAY(a) \
if (a != NULL) { \
delete [] a ; \
a = NULL ; \
}

#define RANGE_MIN 0
#define RANGE_MAX 1

#define MATCHED_STRING 0

#ifndef VTK_RANGE_MIN
#define VTK_RANGE_MIN 0
#define VTK_RANGE_MAX 1
#endif

// Print
#define PRINT_LINE_INFO printf("%s, line %d", __FILE__, __LINE__)
#define PRINT_ERROR_MSG(_msg) {PRINT_LINE_INFO; printf(" at "); printf(_msg);}

// Single loops
#define LOOP_I(a) for(int i=0; i<a; i++)
#define LOOP_J(a) for(int j=0; j<a; j++)
#define LOOP_K(a) for(int k=0; k<a; k++)
#define LOOP_INDEX(index, end) for (int index = 0 ; index < end ; index++)
#define LOOP_INDEX_START_END(index, start, end) for (int index = start ; index < end ; index++)

// Multiple loops
#define LOOP_J_I(b, a) LOOP_J(b) LOOP_I(a)
#define LOOP_K_J_I(c,b,a) for(int k=0; k<c; k++) LOOP_J_I(b,a)

//
#ifndef SWAP
template<class T>
void SWAP(T &a, T &b){
T tmp = a;
a = b;
b = tmp;
}
#endif

//
#ifndef MIN
#define MIN(a,b) (a > b ? b : a)
#endif

#ifndef MAX
#define MAX(a,b) (a > b ? a : b)
#endif

// Index converter

#define INDEX2X(_ID,_W) (_ID%_W)
#define INDEX2Y(_ID,_W) (_ID/_W)
#define INDEX2ID(_ID,_X,_Y,_W) {_X=INDEX2X(_ID,_W);_Y=INDEX2Y(_ID_,_W);}
#define ID2INDEX(_W,_X,_Y) (_Y*_W+_X)
#define PTR2ID(_type, _target, _base) ((_type*)_target - (_type*)_base)

// Memory allocation and release
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) {if(p!=NULL) delete p; p=NULL;}
#endif

#ifndef SAFE_DELETE_ARR
#define SAFE_DELETE_ARR(p) {if(p!=NULL) delete [] p; p=NULL;}
#endif

#define SAFE_NEW(p, type, size) {\
try {p = new type[size];} \
catch(std::bad_alloc& exc) \
{ printf("[%s, line %d] fail to memory allocation - %.2f MB requested\n", __FILE__, __LINE__, (float)(sizeof(type)*size)/_1M_); \
EXIT_WIHT_KEYPRESS }\
}

template<class T>
void memsetZero(T** p, long long size = 0) {
if (*p != NULL)
memset(*p, 0, sizeof(T)*size);
}

template<class T>
void allocNinitMem(T** p, long long size, double *memUsage = NULL) {
*p = new T[size];
//SAFE_NEW(*p, T, size);
memset(*p, 0, sizeof(T)*size);

if (memUsage != NULL) {
*memUsage += sizeof(T)*size;
}
}

#define SAFE_MEMCPY(_dst, _src, _type, _size){ \
if(_dst == nullptr || _src == nullptr ) \
printf("[%s, line %d] fail to memcpy (dst = %x, src = %x)\n", __FILE__, __LINE__, _dst, _src); \
exit(-1); \
memcpy(_dst, _src, sizeof(_type)*_size);\
}

// VTK related
#ifndef SAFE_DELETE_VTK
#define SAFE_DELETE_VTK(p) {if(p!=NULL) p->Delete(); p=NULL;}
#endif

#ifndef VTK_IS_NOERROR
//#include "DS_common_def.h"
#define VTK_IS_NOERROR(p) (p->GetErrorCode()==vtkErrorCode::NoError ? true : false)
#endif

/************************************************************************/
/* Data structures */
/************************************************************************/
typedef struct {
std::string input;
std::string output;
} nameMatch;

typedef struct {
char drive[255];
char dir[255];
char filename[255];
char ext[255];
} filePathSplit;
Loading

0 comments on commit e9fcf70

Please sign in to comment.